-
Notifications
You must be signed in to change notification settings - Fork 163
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
HttpStatus Code on GRAPHQL_VALIDATION error #967
Comments
The latest 7.2.0 follows the draft GraphQL over HTTP spec, which returns
Both the response content type and status code response are configurable. See the app.UseGraphQL("/graphql", options =>
{
options.DefaultResponseContentType = MediaTypeHeaderValueMs.Parse("application/json");
options.ValidationErrorsReturnBadRequest = false;
}); Note that if the HTTP |
@gao-artur You provided irrelevant parts of the spec. The problem is not about intermediary servers or content type. The problem is the data itself. @Shane32 pointed in the right direction. Since v7 server returns 4xx if data entry is empty, i.e. execution was not started at all, that means some validation error or any other arbitrary server-side error occurred BEFORE actual execution of GraphQL query. |
@sungam3r You may wish to read this section again https://github.com/graphql/graphql-over-http/blob/main/spec/GraphQLOverHTTP.md#applicationjson @gao-artur is correct that 400 is "strongly discouraged" for well-formed GraphQL responses with the "application/json" content type.
We are catering to the |
OK, too many combinations to remember. |
Thanks, this explains the observed behavior and provided configuration indeed solves my issue. But I think this should be the default behavior for |
We can look at adding this feature. (Specifically, that the response status code is dependent not only on the response but the selected content type.) It would likely have to be in the next major version since it probably requires a redesign of some of the protected methods of the middleware. I think ultimately we want to determine the response content type earlier in the middleware logic to allow for adjusting behavior throughout the pipeline, for example to support subscriptions over SSE. |
Done for v8. By default it will follow GraphQL over HTTP spec and return 200 for |
Not sure if it's a bug or a misunderstanding of the spec. I'm migrating from 5.1.1 to 7.2.0 and found that in some cases, the HttpStatus Code changed from 200 to 400. For example, when the required field is missing from the query, I'm getting now BadRequest (400)
The spec for
application/json
says:And also:
The text was updated successfully, but these errors were encountered: