Linter rulesGraphQLmatch-document-filename

match-document-filename

Since 0.9.0

This rule checks that the file name of a document with one operation or fragment is the name of the definition.

Rule Details

Files named after their operation are easy to find. Documents with several definitions are not checked (see lone-executable-definition).

Configuration

The configuration block is an object with the properties:

  • style: the case of the file name, camelCase, camelCaseStrict, PascalCase, PascalCaseStrict, snake_case, CONST_CASE (or UPPER_CASE), kebab-case or Header-Case; the strict forms reject two capitals in a row (userID); the name as written by default
  • fileExtension: the extension the file must have, e.g. .gql; any by default
version: "1.0"
commands:
  lint:
    graphql:
      rules:
        match-document-filename: [error, { style: kebab-case, fileExtension: .graphql }]

The rule can be disabled for a node and everything nested in it with an # apigenie-lint-disable match-document-filename 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.

# GetUser.graphql
query GetUser { me { id } }

Bad. The linter reports The file name 'user.graphql' should match the query 'GetUser', e.g. 'GetUser.graphql'.

# user.graphql
query GetUser { me { id } }