🎉 Welcome to the new GraphQL-ESLint website. Try new playground page →
Rules
Require Id When Available

require-id-when-available

✅ The "extends": "plugin:@graphql-eslint/operations-recommended" property in a configuration file enables this rule.

💡 This rule provides suggestions (opens in a new tab)

  • Category: Operations
  • Rule name: @graphql-eslint/require-id-when-available
  • Requires GraphQL Schema: true ℹī¸
  • Requires GraphQL Operations: true ℹī¸

Enforce selecting specific fields when they are available on the GraphQL type.

Usage Examples

Incorrect

# eslint @graphql-eslint/require-id-when-available: 'error'
 
# In your schema
type User {
  id: ID!
  name: String!
}
 
# Query
query {
  user {
    name
  }
}

Correct

# eslint @graphql-eslint/require-id-when-available: '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"


Sub Schemas

The schema defines the following additional types:

asString (string)

asArray (array)

Resources