require-selections
✅ 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
ℹ️
Usage Examples
Incorrect
# eslint @graphql-eslint/require-selections: 'error'
# In your schema
type User {
id: ID!
name: String!
}
# Query
query {
user {
name
}
}
Correct
# eslint @graphql-eslint/require-selections: 'error'
# In your schema
type User {
id: ID!
name: String!
}
# Query
query {
user {
id
name
}
}
# Selecting `id` with an alias is also valid
query {
user {
id: name
}
}
Config Schema
The schema defines the following properties:
fieldName
The object must be one of the following types:
asString
asArray
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
.
Resources
Last updated on