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

Compatibility for run_graphql_field with lookahead extra #4925

Closed
marten opened this issue Apr 19, 2024 · 1 comment · Fixed by #4930
Closed

Compatibility for run_graphql_field with lookahead extra #4925

marten opened this issue Apr 19, 2024 · 1 comment · Fixed by #4930

Comments

@marten
Copy link
Contributor

marten commented Apr 19, 2024

Is your feature request related to a problem? Please describe.

I am converting our test suites to mostly use run_graphql_field where we only test a specific field. In some of our types, we're using the lookahead extra to optimize our database queries. When attempting to use the test helper on such a field, graphql-ruby raises an error:

     GraphQL::Schema::Field::FieldImplementationFailed:
       Failed to call `:some_field` on #<Types::SomeType:0x000000011da57918 @object=#<Some id: 1>, @context=#<Query::Context ...>> because the Ruby method params were incompatible with the GraphQL arguments:

       - `lookahead:` is required by Ruby, but not by GraphQL. Consider `lookahead: nil` instead, or making this argument required in GraphQL.

Describe the solution you'd like

A default lookahead being passed in that claims nothing is selected would probably be the best developer experience. Some way of overriding it would make testing the optimizations in the field's method possible, but testing using a full query starting from the QueryType would be acceptable in these cases I think, since it's no longer testing a field in isolation (which seems to be the spirit of the run_graphql_field helper).

Describe alternatives you've considered

For now I'll leave these to execute complete queries against the schema class.

@rmosolgo
Copy link
Owner

Hey, thanks for reporting this. I updated run_graphql_field in #4930 to inject minimal objects by default, but accept any object using a keyword argument (run_graphql_field(...., lookahead: ...). It's not easy to make a lookahead without a real query, but for small unit-testing, you could create mock and inject it that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants