Skip to content
Latchkey

GraphQL Code Generator "Field ... must have a selection of subfields" in CI

In GraphQL, a field whose type is an object, interface, or union must select subfields. When an operation leaves such a field as a leaf, the validator fails with "must have a selection of subfields", and codegen stops.

What this error means

graphql-codegen fails with "Field \"<field>\" of type \"<Type>\" must have a selection of subfields. Did you mean \"<field> { ... }\"?".

graphql-codegen
Field "owner" of type "User" must have a selection of subfields. Did you mean "owner { ... }"?

Common causes

An object-typed field selected as a leaf

The operation requests an object field (like owner) without a { ... } selection set, which is invalid GraphQL.

A field changed from scalar to object

The schema changed a field type to an object; existing operations that treated it as scalar now need a selection set.

How to fix it

Add a selection set to the field

  1. Find the field named in the error.
  2. Add { ... } selecting the subfields you need.
  3. Re-run codegen to confirm the operation validates.
queries/repo.graphql
query Repo {
  repository(id: $id) {
    owner {
      id
      name
    }
  }
}

Update operations after a schema type change

When a field becomes an object type, sweep operations for now-invalid leaf selections and add subfields.

How to prevent it

  • Lint operations against the schema in CI to catch leaf selections.
  • Update operations together with schema type changes.
  • Run codegen locally before pushing.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →