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
Getting 422 http status code error message on all query calls from Apollo client to gqlgen graphql server. Apollo client works fine when I query Apollo Graphql server. Error Message
Objects are not valid as a React child (found: Error: Response not successful: Received status code 422). If you meant to render a collection of children, use an array instead.
What did you expect?
Query calls be executed as expected return the result with any error message
Minimal graphql.schema and models to reproduce
type Test {
name; String
}
query {
Testnow: Test
}
Resolver:
Just return Test Model. Very simple
versions
gqlgen version?
0.12.2
go version?
1.15
dep or go modules?
go modules
The text was updated successfully, but these errors were encountered:
I don't think there's an issue. When there's an error before query execution (e.g. when the query is validated against a schema), gqlgen returns a 422 Unprocessable Entity status. If the query is valid but an error is returned from a resolver, gqlgen will respond with a 200 OK status. This seems to be the adopted behaviour in other projects like express-graphql (the reference server for GraphQL over HTTP I believe) and apollo-server as well. Please check out this and this for more context and reasoning.
Error handling in Apollo Client (v3.0) treats HTTP responses with valid JSON but a status >= 300 as a generic network/server error (ref). This is a safe fallback which aligns with the proposed spec for how GraphQL over HTTP should work:
"For any non-2XX response, the client should not rely on the body to be in GraphQL format since the source of the response may not be the GraphQL server but instead some intermediary such as API gateways, firewalls, etc."
It would be nice though if Apollo Client first attempts to parse the HTTP response body as GraphQL errors and only if that fails fallback and handle it as a generic network error.
TL;DR: It's perfectly fine for a GraphQL server to respond with a 4xx code when there's a syntax/validation error that occurs before query execution. It's also (probably) expected that Apollo Client treats statuses >= 300 as generic network/server errors, although it would be nice if it first attempts to parse them as GraphQL errors.
What happened?
Getting 422 http status code error message on all query calls from Apollo client to gqlgen graphql server. Apollo client works fine when I query Apollo Graphql server.
Error Message
Objects are not valid as a React child (found: Error: Response not successful: Received status code 422). If you meant to render a collection of children, use an array instead.
What did you expect?
Query calls be executed as expected return the result with any error message
Minimal graphql.schema and models to reproduce
type Test {
name; String
}
query {
Testnow: Test
}
Resolver:
Just return Test Model. Very simple
versions
gqlgen version
?0.12.2
go version
?1.15
go modules
The text was updated successfully, but these errors were encountered: