Skip to Content
This is documentation for v4 of the plugin. For v3 click here.
ESLGraphQL-ESLint
Rulesknown-fragment-names

known-fragment-names

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

  • Category: Operations
  • Rule name: @graphql-eslint/known-fragment-names
  • Requires GraphQL Schema: true ℹ️
  • Requires GraphQL Operations: true ℹ️

A GraphQL document is only valid if all ...Fragment fragment spreads refer to fragments defined in the same document.

This rule is a wrapper around a graphql-js validation function.

Usage Examples

Incorrect

# eslint @graphql-eslint/known-fragment-names: 'error' query { user { id ...UserFields # fragment not defined in the document } }

Correct

# eslint @graphql-eslint/known-fragment-names: 'error' fragment UserFields on User { firstName lastName } query { user { id ...UserFields } }

Correct (UserFields fragment located in a separate file)

# eslint @graphql-eslint/known-fragment-names: 'error' # user.gql query { user { id ...UserFields } } # user-fields.gql fragment UserFields on User { id }

Resources

Last updated on