Skip to content

requireSelections

PropertyValue
Config namerequireSelections
Default severityerror
ContextDocument-Schema
In recommendedNo

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

Given this schema:

type User {
id: ID!
name: String!
}
type Post {
id: ID!
title: String!
author: User!
}
# ❌ Bad — missing id field in nested selection
query GetPost {
post {
id
title
author {
name
}
}
}
# ✅ Good — id selected at every level
query GetPost {
post {
id
title
author {
id
name
}
}
}
OptionTypeDefaultDescription
fieldsstring[]["id"]Field names to require in every object selection set
# Default: require 'id'
extensions:
graphql-analyzer:
lint:
rules:
requireSelections: error
# Require both id and __typename
extensions:
graphql-analyzer:
lint:
rules:
requireSelections:
severity: error
options:
fields: ["id", "__typename"]