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> { ... }\"?".
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
- Find the field named in the error.
- Add
{ ... }selecting the subfields you need. - Re-run codegen to confirm the operation validates.
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.