apollo-feature-requests
apollo-feature-requests copied to clipboard
Validate the queries and mutations against cache merge policies
Problem
When my team migrated to AC3 we encountered plenty of warnings related to cache. They were pointing out types without a merge policy. It helped us to configure better type policies, but there is a danger related to it.
If a type has unique id field, all queries for that type must fetch it or AC crashes when we have 2 queries like
{
viewer {
id
...fields
}
}
and
{
viewer {
...fields
}
}
The same happens when we defined some other keyFields
, they must be fetched in all the queries or we risk a runtime error.
It would be cool to capture such potential problems not in the runtime but without even running the application. It could be done by comparing configured type policies with all the queries we have in the application. It could also point out missing merge policies and prompt configuration change.
Solution
Allow to define type policies as a static file like typePolicies.json
so it can be reused between AC and eslint plugin going through graphql queries and mutations in the project. We could have a helper function transforming such JSON file and produce the current structure of the type policies.
Alternative Solution
We could keep the type policies definition runtime, specifically, we can keep functions and configurations together. Then have a helper function to load the type policies and do some checks on all of the queries and mutations inside the application.
Seems like there's more want for something like this: https://github.com/apollographql/apollo-feature-requests/issues/251