You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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:
n-1
errors and return the last errornone 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::ExecutionError
sPS: 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.
The text was updated successfully, but these errors were encountered: