-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Wrong error code thrown for GraphQL validation failures in arguments using query variables #3498
Comments
The hacky workaround would be to fix it inside if (
error.extensions &&
(error.message.startsWith(`Variable "`) ||
error.extensions.code === "GRAPHQL_VALIDATION_FAILED")
) {
error.extensions.code = "GRAPHQL_VALIDATION_FAILED";
return error;
} |
Unfortunately, Apollo failing to validate the query variables results in a I wish we could rely on something else than the message to check for the error type, as I personally believe that the former should be passed down to the client while the latter should be wrapped as an internal system error. |
Also related to #3304. |
I came across the same issue. |
Ah, we are running into this same issue after upgrading both The big issue here is that there is no reliable way to differentiate graphql validation errors from actual internal errors that are unexpected. GraphQL validation errors are essentially user-error... unactionable, whereas other types of internal errors are unexpected and potentially actionable. Agree that TypeErrors thrown during document validation should be categorized as such. |
Are there any news on this issue? |
You're right: INTERNAL_SERVER_ERROR shouldn't be something that should show up due to normal user input. I don't think GRAPHQL_VALIDATION_FAILED is correct here. "Validation" is a specific stage in GraphQL processing that compares an operation document to a schema. It's a stage that's completely cacheable for a given document/schema pair and does not depend on other inputs like variables. I think we should catch errors thrown by execution and if they are this particular type, give them an appropriate non-internal error code. |
This particular error can be trivially triggered by clients, so it doesn't make sense to use `INTERNAL_SERVER_ERROR` for it. It seems like a good fit for `BAD_USER_INPUT`, which previously was only used if you explicitly throw a `UserInputError` in your app. Fixes #3498.
Fixing this in #5091. I've chosen |
I've released a prerelease with this fix, version |
This is released in Apollo Server 2.23.0. |
Same thing happens when you feed ExampleVersion: query ($var: String!) {
hello(name: $var)
} Variables: {} /* or */ { "var": null } Response: {
"error": {
"errors": [
{
"message": "Variable \"$var\" of non-null type \"String!\" must not be null.",
"locations": [
{
"line": 1,
"column": 8
}
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [ /* ... */ ]
}
}
}
]
}
} Expected This is derived from OP's example since my own example has unnecessary implementation details that would only bloat this post. |
@iBlueDust Thanks for the report and reproduction. I filed #5353 which would be a great first issue for anyone interested in contributing. |
Package Name/Version
Name:
apollo-server
Version:
2.x.x
. All versions from2.9.7
through2.0.0
have this bug.Expected Behavior
Queries that fail due to errors in scalar parsing should return the error code
GRAPHQL_VALIDATION_FAILED
.Actual Behavior
If an argument passed as a non-null query variable fails to validate, the server response has the code
INTERNAL_SERVER_ERROR
. This issue occurs with both built-in scalars and custom scalar types.Reproduction
Sandbox Link
https://codesandbox.io/s/apollo-error-code-bug-ho6vr
Instructions
In the query field of the sandbox, enter
And in the query variables section, enter
The query above returns this response:
Type errors in arguments sent without using query variables, on the other hand, give a more accurate error code. Compare the above to the result for this query:
It gives the response
which contains a much more useful error code for the client.
A similar problem was noted in several previous issues (#3361 #1410 #2204), but those issues were all linked to mutations, instead of queries.
The text was updated successfully, but these errors were encountered: