On this page

require-description

Enforce descriptions in type definitions and operations.

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

  • Category: Schema
  • Rule name: @graphql-eslint/require-description
  • Requires GraphQL Schema: false ℹ️
  • Requires GraphQL Operations: false ℹ️

Enforce descriptions in type definitions and operations.

Usage Examples

Incorrect

# eslint @graphql-eslint/require-description: ['error', { types: true, FieldDefinition: true }]

type someTypeName {
  name: String
}

Correct

# eslint @graphql-eslint/require-description: ['error', { types: true, FieldDefinition: true }]

"""
Some type description
"""
type someTypeName {
  """
  Name description
  """
  name: String
}

Correct

# eslint @graphql-eslint/require-description: ['error', { OperationDefinition: true }]

# Create a new user
mutation createUser {
  # ...
}

Correct

# eslint @graphql-eslint/require-description: ['error', { rootField: true }]

type Mutation {
  "Create a new user"
  createUser: User
}

type User {
  name: String
}

Correct

# eslint @graphql-eslint/require-description: ['error', { ignoredSelectors: ['[type=ObjectTypeDefinition][name.value=PageInfo]', '[type=ObjectTypeDefinition][name.value=/(Connection|Edge)$/]'] }]

type FriendConnection {
  edges: [FriendEdge]
  pageInfo: PageInfo!
}
type FriendEdge {
  cursor: String!
  node: Friend!
}
type PageInfo {
  hasPreviousPage: Boolean!
  hasNextPage: Boolean!
  startCursor: String
  endCursor: String
}

Config Schema

The schema defines the following properties:

types (boolean, enum)

Includes:

  • ObjectTypeDefinition
  • InterfaceTypeDefinition
  • EnumTypeDefinition
  • ScalarTypeDefinition
  • InputObjectTypeDefinition
  • UnionTypeDefinition

This element must be one of the following enum values:

  • true

rootField (boolean, enum)

Definitions within Query, Mutation, and Subscription root types.

This element must be one of the following enum values:

  • true

ignoredSelectors (array)

Ignore specific selectors

[!TIP]

These fields are defined by ESLint selectors. Paste or drop code into the editor in ASTExplorer and inspect the generated AST to compose your selector.

The object is an array with all elements of the type string.

Additional restrictions:

  • Minimum items: 1
  • Unique items: true

DirectiveDefinition (boolean)

[!NOTE]

Read more about this kind on spec.graphql.org.

EnumTypeDefinition (boolean)

[!NOTE]

Read more about this kind on spec.graphql.org.

EnumValueDefinition (boolean)

[!NOTE]

Read more about this kind on spec.graphql.org.

FieldDefinition (boolean)

[!NOTE]

Read more about this kind on spec.graphql.org.

InputObjectTypeDefinition (boolean)

[!NOTE]

Read more about this kind on spec.graphql.org.

InputValueDefinition (boolean)

[!NOTE]

Read more about this kind on spec.graphql.org.

InterfaceTypeDefinition (boolean)

[!NOTE]

Read more about this kind on spec.graphql.org.

ObjectTypeDefinition (boolean)

[!NOTE]

Read more about this kind on spec.graphql.org.

OperationDefinition (boolean)

[!NOTE]

Read more about this kind on spec.graphql.org.

[!WARNING]

You must use only comment syntax # and not description syntax """ or ".

ScalarTypeDefinition (boolean)

[!NOTE]

Read more about this kind on spec.graphql.org.

UnionTypeDefinition (boolean)

[!NOTE]

Read more about this kind on spec.graphql.org.

Resources