GRAPHQL_VALIDATION_FAILED 🔌 API

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

Seen on: JavaScript REST API

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

  1. Explore the schema (GraphiQL / Apollo Sandbox) and copy the exact field name
  2. Use inline fragments for unions/interfaces
  3. Re-run schema download and code generation
  4. Check errors[].extensions.code for the precise validation rule

Detailed fix by platform

JavaScript

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

  1. Message — Which field and type are named?
  2. Schema — Does the field exist on that type in the current schema?
  3. Types — Union/interface → fragment needed?
  4. 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.