Skip to Content
This is documentation for v4 of the plugin. For v3 click here.
ESLGraphQL-ESLint
Rulesrequire-description

require-description

✅ 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

Last updated on