ardatan / ardatan/graphql-mesh
Redis critical failure when using GraphQL field aliases (bug)
- Dominant language
- TypeScript
- Stars
- 3.5k
- Forks
- 363
- Avg merge
- 6h 10m
- Merged PRs (30d)
- 19
Description
**Describe the bug**
When enabling mesh sdk caching using redis, or caching on any underlying service the mesh queries. If we alias a field then the Mesh SDK query itself fails with a null error for the particular aliased field.
```
GraphQL Mesh SDK Failed (1 errors): Cannot return null for non-nullable field component_configs_selector_field.selector_fields
```
The alias looks like this
```graphql
selector {
fields: selector_fields(order_by: { order_by: asc }) {
type
title
}
}
```
After investigating it only seems to happen on Redis. The file and inmemory cache both seem to be working as expected with aliased fields returning no problem.
I confirmed it was an alias field issue by going into a Redis GUI and changing the cached response from something like
```json
"selector":{
"fields":[]
}
```
To the original unaliased name and that fixed the error (running into an error on the next aliased field though since we rely on aliases heavily.
```json
"selector":{
"selector_fields":[]
}
```
**To Reproduce**
Alias a GraphQL field and use a redis cache (in our case running on a docker pod inside kubernetes).
**Expected behavior**
Redis caching should work as expected when hooked up via the Mesh SDK Cache config, or when redis caching is enabled on the underlying service itself (i.e our underlyding federated ApolloServer pod)
**Environment:**
- OS:
- "@apollo/federation": "^0.14.1",
"@apollo/gateway": "^0.14.1",
- "@graphql-mesh/cache-file": "^0.5.10",
"@graphql-mesh/cache-inmemory-lru": "^0.5.5",
"@graphql-mesh/cache-redis": "^0.5.10",
"@graphql-mesh/cli": "^0.2.15",
"@graphql-mesh/config": "^0.4.1",
"@graphql-mesh/graphql": "^0.2.15",
"@graphql-mesh/runtime": "^0.2.15",
"@graphql-mesh/transform-cache": "^0.9.0",
- NodeJS: 13.14.0
**Additional context**
Pretty sure it's an issue directly related to aliases, it is working fine on all other tested caching solutions. Even though the cached response is exactly the same, for example I pulled this from the file cache
```json
{
"selector":{
"fields: [{... data ...}]
}
]
```
**I'm available to help fix the bug and support as required as this is a high priority issue for our company releasing GraphQL Mesh to production soon. I will just need to be pointed in the right direction, or if you are able to fix the issue no worries. Let me know if/how I can help.**
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the @graphql-mesh/cache-redis and @graphql-mesh/transform-cache packages, then reproduce the aliased selector query with Redis enabled. Compare the result with @graphql-mesh/cache-file and @graphql-mesh/cache-inmemory-lru using the same query. Done means aliased fields return correctly through Redis caching without the null-field error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, redis, typescript
- Domain
- backend-api-design, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100