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 multiple execution errors for Fields defined to return a list … #2433

Merged
merged 3 commits into from
Aug 21, 2019

Conversation

stanishev
Copy link
Contributor

Fields defined to return a List of some type should be able to return an Array of GraphQL::ExecutionErrors instead.

@@ -296,18 +296,6 @@
describe "more than one ExecutionError" do
let(:query_string) { %|{ multipleErrorsOnNonNullableField} |}
it "the errors are inserted into the errors key and the data is nil even for a NonNullable field " do

# I Think the path here is _wrong_, since this is not an array field:
Copy link
Contributor Author

@stanishev stanishev Aug 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment makes sense to me because I submitted the PR that introduced this test. The comment is correct (and thank you sincerely for pointing this out).

I've taken the liberty to remove the comment because I see that you have already corrected the spec and I think that at this point the comment is no longer necessary. To someone else reading this without the context we have, I think it may just be confusing without adding much.


describe "more than one ExecutionError on a field defined to return a list" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more test, similar to the earlier one, but this time the return type is a list type and so the path includes the list indices as well.

@@ -197,7 +197,7 @@ def continue_resolve_field(raw_value, field_type, field_ctx)
raw_value.path = field_ctx.path
query.context.errors.push(raw_value)
when Array
if !field_type.list?
if field_type.non_null?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the correct logic for including (or not) the array of errors here.

This covers all scenarios:

  • fields defined with null: true will not have these errors included here since as the comment below mentions they were already handled somewhere else.
  • fields defined with null: false will have the list of errors included, regardless of whether they are defined to return a single type or a list of some type.

@stanishev
Copy link
Contributor Author

stanishev commented Aug 19, 2019

Currently the spec I added fails for the ruby 2.4.3 build in TravisCI. The actual results do not include the indices in the path. I am unable to replicate this failure locally. Does anyone have leads on what may be happening here?

Copy link
Owner

@rmosolgo rmosolgo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for taking this on! The change is looking great. It looks like a similar change will be required in interpreter/runtime.rb, which will be the default runtime in a future GraphQL-Ruby version (it has better performance and flexibility than execute.rb).

value.each do |v|
v.path ||= path
v.ast_node ||= ast_node
value.each_with_index do |error, index|
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding the index to the path for list types.

@rmosolgo
Copy link
Owner

Awesome, thanks so much for taking care of this 🎉 !

@rmosolgo rmosolgo modified the milestones: 1.10.0, 1.9.11 Aug 21, 2019
@rmosolgo rmosolgo merged commit edfc441 into rmosolgo:master Aug 21, 2019
@stanishev stanishev deleted the returning-array-of-errors branch August 22, 2019 19:27
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 this pull request may close these issues.

2 participants