Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Having 422 HTTP status code when you send Query requests from Apollo client #1310

Closed
rkunhi opened this issue Aug 26, 2020 · 1 comment
Closed

Comments

@rkunhi
Copy link

rkunhi commented Aug 26, 2020

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
  • dep or go modules?
    go modules
@dstotijn
Copy link

dstotijn commented Sep 22, 2020

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."

(ref)

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.

@frederikhors frederikhors converted this issue into discussion #1822 Jan 19, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants