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

Enable resolvers to return an array of GraphQL::ExecutionErrors #1230

Closed
stanishev opened this issue Jan 19, 2018 · 1 comment
Closed

Enable resolvers to return an array of GraphQL::ExecutionErrors #1230

stanishev opened this issue Jan 19, 2018 · 1 comment

Comments

@stanishev
Copy link
Contributor

stanishev commented Jan 19, 2018

When a field resolver returns a single GraphQL::ExecutionError, the field is resolved as nil and the error is added to the response's errors key.
graphql-ruby ensures that only that one error is added to the errors key, even if the field is marked as non_null.

There is no mechanism to achieve the same behavior for multiple errors for non_null fields.

The add_error method allows adding multiple errors to the errors key, but resolvers are still required to return a value if the field is marked as non_null.

This leaves us with only the following options for a non_null field:

  • returning nil and having an additional error added in the errors key by graphql-ruby (the error indicates that a nil value is not permitted for a non_null field)
  • or to use add_error and return a bogus non nil value of the correct return type.
  • or use add_error for the first n-1 errors and return the last error

none of which are very nice.

Would like to suggest that GraphQL::Execution::Execute.resolve_value returns a PropagateNull type when the result from a resolve method is an array of GraphQL::ExecutionErrors

PS: Can't be sure but looking through the code in resolve_value it seems that this was perhaps intended to begin with...

also this PR doesn't handle the case where the return type is an Array where only some of the elements are GraphQL::ExecutionErrors.. Quite frankly I am not sure how that should be handled. Hopefully rmosolgo can weight in.

@stanishev stanishev changed the title Enable resolvers for fields marked as non_null to return an array of GraphQL::ExecutionErrors Enable resolvers to return an array of GraphQL::ExecutionErrors Jan 19, 2018
@stanishev
Copy link
Contributor Author

PR was merged. 💥

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

No branches or pull requests

1 participant