Skip to content
Latchkey

Apollo "Response not successful: Received status code 400" in CI

Apollo Client throws this when the GraphQL endpoint returns HTTP 400. The server refused the request before execution, almost always because the operation failed validation or the request body was malformed.

What this error means

A client call or SSR test rejects with "ServerError: Response not successful: Received status code 400". The error often wraps a result with a GRAPHQL_VALIDATION_FAILED or BAD_REQUEST message.

Apollo Client
ApolloError: Response not successful: Received status code 400
    at new ApolloError (.../core/ApolloError.js)
  result: { errors: [ { message: 'Cannot query field "x" on type "Query".' } ] }

Common causes

The operation failed server-side validation

Apollo Server returns 400 for validation failures (unknown field, missing required variable, malformed query), and the client surfaces it as status 400.

A malformed or empty request body

A missing Content-Type, an empty query string, or non-JSON body makes the server reject the POST with 400 before parsing the operation.

How to fix it

Read the wrapped server errors

  1. Inspect error.result.errors (or the raw response body) for the real GraphQL message.
  2. Fix the named validation problem in the query or variables.
  3. Confirm the request sends Content-Type: application/json with a non-empty query.
JavaScript
client.query({ query, variables }).catch((e) => {
  console.error(e.networkError?.result?.errors ?? e.message);
});

Validate operations before the request

Run a schema-aware validation in CI so invalid operations never reach the network and turn into opaque 400s.

Terminal
npx graphql-validate --schema schema.graphql 'src/**/*.graphql'

How to prevent it

  • Surface networkError.result.errors in tests rather than just the 400 message.
  • Validate operations against the schema in CI.
  • Always send a JSON Content-Type and a non-empty query string.

Frequently asked questions

What causes ""Received status code 400""?
Apollo Server returns 400 for validation failures (unknown field, missing required variable, malformed query), and the client surfaces it as status 400.
How do I fix "Received status code 400"?
Read the wrapped server errors

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card