require-selections
Enforce selecting specific fields when they are available on the GraphQL type.
✅ The "extends": "plugin:@graphql-eslint/operations-recommended" property in a configuration file
enables this rule.
💡 This rule provides suggestions
- Category:
Operations - Rule name:
@graphql-eslint/require-selections - Requires GraphQL Schema:
trueℹ️ - Requires GraphQL Operations:
trueℹ️
Enforce selecting specific fields when they are available on the GraphQL type.
Usage Examples
Incorrect
Correct
Config Schema
The schema defines the following properties:
fieldName
The object must be one of the following types:
asStringasArray
Default: "id"
requireAllFields (boolean)
Whether all fields of fieldName option must be included.
Sub Schemas
The schema defines the following additional types:
asString (string)
asArray (array)
When Not To Use It
Relay Compiler automatically adds an id field to any type that has an id field, even if it
hasn’t been explicitly requested. Requesting a field that is not used directly in the code can
conflict with another Relay rule: relay/unused-fields.