-
Notifications
You must be signed in to change notification settings - Fork 271
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
add errors for response validation #5787
Conversation
When formatting responses, the router is validating the data returned by subgraphs and replacing it with null values as appropriate. MEssages were put in the response extensions outlining the paths at which the nulls were propagated up the response (due to non nullable types) but it was not generating error messages for invalid values
This comment has been minimized.
This comment has been minimized.
CI performance tests
|
I think error messages could be improved to add more info about the kind of data that was received |
8b2deb0
to
b2bddc3
Compare
The only thing required now is to make the error message match the gateway. |
I'm updating the error messages following https://github.com/apollographql/federation/blob/main/gateway-js/src/resultShaping.ts#L305-L430 |
6733583 follows the gateway's error messages. I'd like to modify them to not show the value we got in the error message, nor mention the subgraph. The rationale here being that we don't want to expose in the errors some sensitive data that might have been returned by error. |
36231f5 updates the error message to expose less information but still give enough for debugging |
in the interest of avoiding breaking changes, I'd rather not fail hard on the typename validation, but still add the error message |
I removed the __typename validation in 965cfd2 and added a comment for more context |
@@ -388,7 +405,8 @@ impl Query { | |||
input, | |||
output, | |||
path, | |||
field_type, | |||
parent_type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My change: this call is recursing from Int!
to Int
, it's not entering a new field, so the parent type remains the same.
Before this change you could get an error message like Invalid value found for field Int!.field
, which doesn't make sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this is not a huge issue because parent_type
is only used for that error message, but I worry that this would break assumptions when we change the code later. Could we move it back to field_type
, but use parent_type.inner_named_type()
in the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code should assume that the parent type is the type that the selection is executed on, while the field type is the type that the selection returns. inner_named_type()
is also incorrect as it would mention Int.someNumber
in the error, when Int
is the return type, not the type that has the field someNumber
.
Before this change parent_type
would sometimes contain the parent type, but sometimes not contain the parent type at all. It could be two entirely different things that must be used differently. So I don't think it could possibly be correct before
I added a small fix as well to get that test to pass & to fix the |
@goto-bus-stop when you say it needs to exercise all cases, do you mean that we could generate false positive errors or that there are invalid values that we may not be detecting yet? |
I'd like to see tests exercising more wrong combinations of types, instead of just one for each type. I think I'm mostly looking for test assurance that we are not missing error cases. Some combinations don't feel all that useful to test but the spec provides some freedom to servers, so I think it's good to nail down what our choices are even for the obvious stuff. For example, if a field returns a boolean The case that I was thinking of specifically is if a subgraph responds with a float for an
So it leaves a lot of free choice for us. I think we already do the right thing because serde_json's |
honestly I'd be more ok with missing some error cases right now and revisit in a later PR, than wait a few more months without any validation errors |
I found several minor issues by adding tests:
I'm surprised serde_json doesn't handle My proposed initial steps for the coercion issues:
|
Backing out my |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be good to, I reverted my unnecessary changes so the only things I added are more tests encoding the current behaviour, and a fix to the error message.
*output = Value::Null; | ||
Ok(()) | ||
} | ||
} | ||
None => { | ||
parameters.validation_errors.push( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a missing if !input.is_null()
or something here. If I understand correctly, the executable::Type::Named(type_name)
matcher arm that this is under actually means "nullable named type" (vs executable::Type::NonNullNamed
), which means it is valid for input
to be null. This change is leading to the addition of an incorrect Expected a valid enum value for type {}
error to responses any time that a subgraph returns null
for a nullable enum field.
This reverts commit 39c6c03.
Co-authored-by: Andrew McGivery <[email protected]> Co-authored-by: Renée Kooi <[email protected]>
This PR was reverted during the 1.58.0 release candidacy life-cycle due to regressions which are best described in #6314. While it was present in |
Fix #5372
Closes #6143
When formatting responses, the router is validating the data returned by subgraphs and replacing it with null values as appropriate. MEssages were put in the response extensions outlining the paths at which the nulls were propagated up the response (due to non nullable types) but it was not generating error messages for invalid values
Checklist
Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.
Exceptions
Note any exceptions here
Notes
Footnotes
It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. ↩
Configuration is an important part of many changes. Where applicable please try to document configuration examples. ↩
Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions. ↩