-
Notifications
You must be signed in to change notification settings - Fork 1.4k
QueryComplexity analyzer may have IO side-effect #5261
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
Comments
Hey, thanks for opening this issue to discuss this further. In my eyes, there are a few things to consider:
|
Is this not completely avoidable doing something like...? class Query < GraphQL::Schema::Object
field :mentions, Mention.connection_type do
argument :ticket_id, ID
end
def mentions(ticket_id:)
Ticket.find_by(id: ticket_id)&.mentions
end
end Call me old fashioned but there's some bliss in simplicity. |
Yes, you could also do it in the resolver. But using All of that could also be implemented in the application layer itself, but sometimes ... it isn't 😅 |
Describe the bug
Discussed in #4800 (comment)
The
GraphQL::Analysis::QueryComplexity
may have IO side-effects (eg making a DB query via active record), while it would be expected to be fully static (as mentioned in the doc "None of GraphQL-Ruby’s validators make IO calls").This happens because the field complexity calculation for connections (in https://github.com/rmosolgo/graphql-ruby/blob/v2.4.10/lib/graphql/schema/field.rb#L504) calls the argument_cache to read the arguments (to read static arguments like
:first
), which fully resolves the arguments. This is a problem for example when an argument usesloads:
to get an ActiveRecord object from id. This makes using thevalidate_timeout
feature for analysis unsafe.Versions
graphql
version: 2.4.10Script to reproduce
(took inspiration from the script in #5036 (comment))
Expected behavior
No DB call should be made, analyzer should be fully static. Arguments that are needed for the complexity calculation should be read statically.
Actual behavior
We can see a DB call made through ActiveRecord
And can see the argument resolved in the
arguments_cache
The text was updated successfully, but these errors were encountered: