-
-
Notifications
You must be signed in to change notification settings - Fork 454
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
RFC: Allow for selectively skipping local resolver with a hook option #2650
Comments
I don't know if this will also work for queries (as the docs only talk about mutations and I haven't tried it), but it may be possible to pass an "extra" argument to your query, and use this in the resolver to conditionally perform your merge? |
This would be really useful, I'm having the same experience as you. |
Generally I would say this option already exists, let's say for a local resolver you are using the const myResolver = relayPagination();
cacheExchange({
resolvers: {
Query: {
list: (parent, args, cache, info) => {
// or any other condition 😅
if (info.variables.skipPagination) {
return cache.resolve('Query', 'list', args)
}
return myResolver(parent, args, cache, info);
}
}
}
}) |
Thanks @JoviDeCroock, that's very helpful. |
Just tried this - |
Sounds good, much appreciated. Yeah I'm not sure where it happens but it's definitely being passed in to useQuery and not making it into the For context I'm on Graphcache 4.4.3, although it seems that neither of the snippets you linked have changed since then, so might not be a relevant detail. |
Just tried in a sanbox, works great https://codesandbox.io/s/jovial-cloud-usm1t4?file=/src/components/Todos.js |
Okay I got it working, it turned out to be filtering it out because I had |
Resolved by #3191 / #3306 which have been released in |
Summary
Graphcache is great and the local resolvers feature works great for merging data together when doing cursor pagination. However, if I wanted to use the same query in multiple places and in some components I did NOT want to merge data when paginating, my hands are tied because if you apply a local resolver to a query, then it applies to ALL calls to that query. I tried setting
requestPolicy
tonetwork-only
but that does not seem to have an effect on whether local resolvers are used.Proposed Solution
Perhaps a simple switch to skip the local resolver straight from the hooks. Maybe a skipLocalResolvers option or something similar?
Requirements
I am not familiar with the internals of urql, so really I'm just looking to have an option to decide whether a query will use the local resolvers I've written to resolve things or not, however that might best be implemented.
Thank you for the amazing work! Love using urql :)
The text was updated successfully, but these errors were encountered: