Skip to content
Latchkey

GraphQL "Cannot query field X on type Y" at runtime in CI

The GraphQL server validated the incoming operation against its schema and the field you selected is not defined on that type. The request is rejected with a 400 and a GRAPHQL_VALIDATION_FAILED error before any resolver runs.

What this error means

An integration test or client call against the running server returns errors with "Cannot query field \"x\" on type \"Y\".", and the HTTP response carries a 400 status with extensions.code GRAPHQL_VALIDATION_FAILED.

Apollo Server
{
  "errors": [{
    "message": "Cannot query field \"fullName\" on type \"User\".",
    "locations": [{ "line": 3, "column": 5 }],
    "extensions": { "code": "GRAPHQL_VALIDATION_FAILED" }
  }]
}

Common causes

The query is ahead of the deployed schema

The operation selects a field the running server's schema does not expose, often because the client query was updated but the server build in CI is older.

A typo or wrong type in the selection

The field name is misspelled, or it is selected on the wrong type (for example a field that lives on a nested object, not the parent).

How to fix it

Align the query with the running schema

  1. Print the schema the server actually serves in CI (SDL or introspection).
  2. Confirm the field exists on that exact type and fix the selection if not.
  3. Rebuild the server so its schema matches the operation under test.
Terminal
# dump the SDL the server serves, then grep for the field
npm run print-schema > schema.graphql
grep -n "fullName" schema.graphql

Validate operations against the schema in CI

Run a static check so an operation that selects a missing field fails early instead of at request time.

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

How to prevent it

  • Generate the schema artifact and validate operations against it in CI.
  • Deploy schema and client queries from the same commit.
  • Treat GRAPHQL_VALIDATION_FAILED in tests as a hard failure, not a warning.

Frequently asked questions

What causes ""Cannot query field on type""?
The operation selects a field the running server's schema does not expose, often because the client query was updated but the server build in CI is older.
How do I fix "Cannot query field on type"?
Align the query with the running schema

Related guides

References

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