-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add a GraphQL.reload()
API
#26
Comments
|
@chrischen the idea is to have an API that does not require problematic manual cache edits. Before the React hooks update, |
It seems apollo has partial automatic cache updates (if an ID matches up in the response). If you won't go this way, what's the way to update the cache manually or do I have to do a reset() to refetch? |
Apollo makes a lot of assumptions, and their automatic cache updates require manual intervention in a lot of situations. For example, imagine you run a After a mutation the best thing to do is reset the cache so all the mounted components refetch their data. |
You can also always call client.resetStore() in apollo, but they give you some ways to do optimizations that require manual intervention, but it's not required. You can supply a refetchQueries list when mutating to selectively refetch, if you're not willing to do manual cache changes. I think the reload() method should be able to take an optional list of queries to selectively reload queries. |
Keep in mind that The |
But how can I use this to specify stale queries as a result of a specific mutation?
|
That's the beauty of the API; you don't have to. Cache is automatically reloaded everywhere. A component that triggers a mutation should not have to be aware of a bunch of queries used elsewhere in unrelated components. |
if you don't want an operation to load on reset (perhaps for mutation loaded on demand) you can opt-out.
Do you mean that mutation operations get loaded on reset by default?
Thanks!
Chris
…________________________________
From: Jayden Seric <notifications@github.com>
Sent: Tuesday, February 26, 2019 12:19 PM
To: jaydenseric/graphql-react
Cc: chrischen; Mention
Subject: Re: [jaydenseric/graphql-react] Add a `GraphQL.reload()` API (#26)
Keep in mind that useGraphQL has a loadOnReset option which defaults to true; if you don't want an operation to load on reset (perhaps for mutation loaded on demand) you can opt-out.
The GraphQL.reload() method will have an exceptCacheKey option.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#26 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AAGsPo8sR59hesGiTblBcpy_QN66dcSzks5vRLXDgaJpZM4bIphp>.
|
@chrischen please read the |
What do you think of the onMutation hook from https://github.com/arackaf/micro-graphql-react You define entity types in the query to watch for changes on:
|
A
GraphQL.reload()
API would trigger aGraphQL
reload
event, but not actually delete any cache likeGraphQL.reset()
does. It would have the same ability to preserve the cache for a particular operation via anexceptCacheKey
option.The
useGraphQL()
React hook optionresetOnLoad
will need rethinking. Although we could just add anotherreloadOnLoad
option, it doesn't make sense that a user could set both options totrue
at once.Use cases:
GraphQL.reset()
:exceptCacheKey
option is used to ensure that the mutation payload is preserved so that the logout success status and message stays visible to the user.GraphQL.reload()
:The text was updated successfully, but these errors were encountered: