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.
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
- Inspect
error.result.errors(or the raw response body) for the real GraphQL message. - Fix the named validation problem in the query or variables.
- Confirm the request sends
Content-Type: application/jsonwith a non-empty query.
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.
npx graphql-validate --schema schema.graphql 'src/**/*.graphql'How to prevent it
- Surface
networkError.result.errorsin 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.