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-jsvalidation 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