Linter rulesGraphQLno-unused-fragments

no-unused-fragments

Since 0.9.0

This rule checks that every fragment is spread by an operation, directly or through other fragments, as the GraphQL specification requires.

Rule Details

The rule reports the issues of the validation rule of the same name, with the messages of graphql-js. A document that breaks it is rejected by GraphQL servers and tools, so the rule should stay enabled with the error severity.

Configuration

This rule has no options.

version: "1.0"
commands:
  lint:
    graphql:
      rules:
        no-unused-fragments: warning

The rule can be disabled for a node and everything nested in it with an # apigenie-lint-disable no-unused-fragments comment on the node, or for a whole file with the comment at the top of the file, separated from the first definition by a blank line. It applies to operations and fragments.

Examples

Good.

query Q { user { ...A } }
fragment A on User { id }

Bad. The linter reports Fragment "A" is never used..

query Q { user { id } }
fragment A on User { id }

Compatibility

The rule reports references to types and fragments that are not in the document only when the configuration sets self_contained: true, since schemas and operations are often split across files.

Further reading