[Enterprise] GraphqlController errors
jeperkins4 opened this issue · 3 comments
After upgrading to Enterprise GraphQL, we now receive the following error in multiple places within our Rails monolithic application:
NoMethodError - undefined method `size' for #<ActionController::Parameters {} permitted: true>
@variables_fingerprint ||= "#{provided_variables.size}/#{Fingerprint.generate(provided_variables.to_json)}"
^^^^^:
app/controllers/graphql_controller.rb:37:in `execute'
Hey, sorry for the trouble and thanks for reporting this! ActionController::Parameters
almost works for GraphQL variables, but there are a few cases where it doesn't have the methods that GraphQL-Ruby needs. (Another example is #4941.) To work around this, call .to_unsafe_h
on the variables before passing them to .execute
, for example:
MySchema.execute(..., variables: params[:variables]&.to_unsafe_h)
Usually, that's not a good way of handling Rails params. But with GraphQL, you can be sure that GraphQL-Ruby will be doing validation during execution. .to_unsafe_h
is what rails g graphql:install
does:
graphql-ruby/lib/generators/graphql/templates/graphql_controller.erb
Lines 38 to 39 in f82ed87
How about giving that a try?
That worked! Thank you so much!
Glad to hear it -- let me know if I can help with anything else!