GraphQL: Cannot query field "x" on type "Y"
The query asks for a field that doesn’t exist in the server’s schema (or isn’t available on that type).
Meaning
GraphQL validates every query against the schema before running it. Typos, renamed/removed fields, querying a field on the wrong type (use fragments for unions/interfaces) or an outdated generated client all produce this validation error — usually with HTTP 200 or 400 and an errors array.
Common causes
- Typo or wrong case in the field name
- Field renamed/removed in a newer schema version
- Field belongs to a concrete type inside a union/interface — needs
... on Type { field } - Client codegen/types generated from an old schema
- Querying the wrong endpoint/environment
⚡ Quick fix
- Explore the schema (GraphiQL / Apollo Sandbox) and copy the exact field name
- Use inline fragments for unions/interfaces
- Re-run schema download and code generation
- Check
errors[].extensions.codefor the precise validation rule
Detailed fix by platform
JavaScript
- Fragment on a union type:graphql
query Search($q: String!) { search(q: $q) { __typename ... on User { name avatarUrl } ... on Project { title stars } } }
Code examples
Always check the errors array
javascript
const { data, errors } = await (await fetch('/graphql', {
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query, variables }),
})).json();
if (errors?.length) throw new Error(errors.map(e => e.message).join('; '));GraphQL can return HTTP 200 together with errors — status alone is not enough.
How to diagnose
- Message — Which field and type are named?
- Schema — Does the field exist on that type in the current schema?
- Types — Union/interface → fragment needed?
- Client — Generated types up to date?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026