-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Create own context for mutation response resolvers #1308
Comments
Happy to entertain suggestions on how to do this, however I think the expectation is that since mutations definitionally are side-effectful on global state that doing things like clearing caches is totally within the expectations of the kind of work you would do in a mutation resolver |
This is an issue I am running into aswell, I thought I was misreading the documentation when exploring this but it actuality seems to not be possible to update the context during a query / mutation. |
You can change things inside context but not a context itself. In general, I think such issues should be solved by 3rd-party middlewares proposed in #1516 |
Imagine a mutation top edit a users username, which has a signature something like this:
In said mutation resolver, I now have to load the user for whatever reason. (in my real use case for checking permissions) I'm using DataLoader to do so to avoid repeated database calls:
In my query resolvers I also use the same loader to resolve a user object:
The issue I'm running into is that the query resolver for the single user returns the cached data from the dataloader without the new changes because the context is shared between the mutation resolver and the returned query resolvers:
Now, in this specific case I can work around this by manually clearing the DataLoader cache with
context.loaders.user.clear(id)
. I'm wondering though, maybe it'd make sense to create the context anew for the resolvers of a mutations return value vs. for the mutation resolver itself?The text was updated successfully, but these errors were encountered: