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

Clear loader cache in Mutation#after_resolve #141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Clear loader cache in Mutation#after_resolve
The `resolve` method of a Mutation can make changes to the DB that
invalidate any cached Loader results. So, the cache should be cleared
after the resolve method has completed, and before any nested fields on
the Mutation query are resolved.

In our codebase, this causes authorization errors if the Mutation
removes a member from a list/connection, and the client requests that
same list field as part of the mutation response. Since the Loader
cached the pre-mutation result, the wrong data is returned to the
client.
  • Loading branch information
Palash Agarwal committed Jun 15, 2021
commit dc76c05452316c602cb7f119ddac7a3cf1144fde
5 changes: 5 additions & 0 deletions lib/graphql/batch/mutation_field_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ def resolve(object:, arguments:, **_rest)
GraphQL::Batch::Executor.current.clear
end
end

def after_resolve(value:, **_rest)
GraphQL::Batch::Executor.current.clear
value
end
end
end