eslint-plugin-graphql
eslint-plugin-graphql copied to clipboard
Apollo cache WriteError prevention
One issue I've seen come up multiple times is Apollo's caching mechanism throwing when a given __typename has at some point been queried with id (which Apollo uses to normalize the cache), but subsequent queries (maybe upon specific types of client-side routing/navigation) omit the id for the same type.
This causes Apollo to throw an exception, treating the query as a failure even though data came back successfully. For example:
query GetMovies {
movies {
id
name
}
}
Then, clicking something or navigating somewhere leads to this query:
query GetMovieNames {
movies {
name
}
}
This would throw an error not because the data couldn't be retrieved but because the cache doesn't know how to handle it.
eslint-plugin-graphql has a unique opportunity to catch these types of issues pretty easily. Thoughts on adding a validation rule to prevent this?
The outcome would be if you have any documents that include the id field for a given __typename, you could warn/error if any other documents have omitted the id field.