A GraphQL operation that queries User.emailAddress when the schema defines User.email fails at request time with a schema validation error — the server returns an errors array, the client receives no data, and the page renders whatever skeleton state you wrote for the loading case. Reference integrity between operation and schema is exactly what GraphQL Codegen was built to enforce, and AI tools writing queries without running codegen introduce this drift on nearly every new query.
Info because GraphQL validation errors surface cleanly in logs and codegen eliminates the class of bug entirely.
Wire GraphQL Codegen into install and build so every query is type-checked against the schema. Add the script to package.json:
{
"scripts": {
"codegen": "graphql-codegen --config codegen.yml",
"postinstall": "npm run codegen",
"build": "npm run codegen && next build"
}
}
Import the generated gql tag in src/queries.ts so tsc --noEmit flags every field-name mismatch before deploy.
ID: ai-slop-hallucinations.data-references.graphql-operations-match-schema
Severity: info
What to look for: When GraphQL is detected (any .graphql schema file, any gql\...`template tag usage, any of@apollo/client, urql, graphql-request, @graphql-codegen/*, genqlin dependencies), read the GraphQL schema file (or codegen-generated types). Build a set of valid query/mutation/subscription names and their field types. Then walk source files forgql`query X { ... }`` and similar template tags. Parse each operation and count all referenced fields, then verify each referenced field exists in the schema. Report counts: operations inspected, operations matching schema, operations with unresolved fields. SKIP this check if no schema file or codegen output is found.
Pass criteria: 100% of GraphQL operations reference fields that exist in the schema. Report: "X operations inspected, Y matching schema, 0 unresolved."
Fail criteria: At least 1 GraphQL operation references a field that does not exist in the schema.
Skip (N/A) when: No GraphQL detected (no .graphql files, no gql\...`` usage, no GraphQL libraries in dependencies) OR no schema file/codegen output is present.
Detail on fail: "1 GraphQL operation has unresolved field: query GetUser in src/queries.ts references User.emailAddress, but schema defines User.email"
Remediation: Use GraphQL Codegen to generate TypeScript types from your schema and operations — TypeScript catches field-name mismatches at build time. Wire codegen into package.json:
{
"scripts": {
"codegen": "graphql-codegen --config codegen.yml",
"postinstall": "npm run codegen",
"build": "npm run codegen && next build"
}
}
Then update src/queries.ts to import the generated types:
// src/queries.ts
import { gql } from '@/__generated__/gql'
// Field name typos are caught by tsc --noEmit
const GetUser = gql(`query GetUser { user { id email } }`)
Re-run graphql-codegen after every schema change.