Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apollo cache WriteError prevention #278

Open
mshwery opened this issue Jul 3, 2020 · 0 comments
Open

Apollo cache WriteError prevention #278

mshwery opened this issue Jul 3, 2020 · 0 comments

Comments

@mshwery
Copy link

mshwery commented Jul 3, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant