requireSelections
| Property | Value |
|---|---|
| Config name | requireSelections |
| Default severity | error |
| Context | Document-Schema |
| In recommended | No |
What it checks
Section titled “What it checks”Enforces that selection sets on object types include specific fields (by default, id). This is essential for client-side cache normalization in tools like Apollo Client and urql, which rely on a consistent identifier field to merge and deduplicate objects.
This rule requires the specified fields to be selected on all object types, helping you catch missing selections project-wide. Use requireAllFields: true in options to limit checks to types that actually have the field (similar to the old require-id-field behavior).
Examples
Section titled “Examples”Given this schema:
type User { id: ID! name: String!}
type Post { id: ID! title: String! author: User!}# ❌ Bad — missing id field in nested selectionquery GetPost { post { id title author { name } }}# ✅ Good — id selected at every levelquery GetPost { post { id title author { id name } }}Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
fields | string[] | ["id"] | Field names to require in every object selection set |
Configuration
Section titled “Configuration”# Default: require 'id'extensions: graphql-analyzer: lint: rules: requireSelections: error
# Require both id and __typenameextensions: graphql-analyzer: lint: rules: requireSelections: severity: error options: fields: ["id", "__typename"]