Linter rulesGraphQLvariables-sorted

variables-sorted

Since 0.9.0

This rule checks that the variable definitions of each operation are in alphabetical order.

Rule Details

Sorted definitions are easier to find and produce smaller diffs. Names are compared ignoring case; the first name out of order of each list is reported.

Configuration

This rule has no options.

version: "1.0"
commands:
  lint:
    graphql:
      rules:
        variables-sorted: warning

The rule can be disabled for a node and everything nested in it with an # apigenie-lint-disable variables-sorted 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 Users($first: Int, $kind: Kind) { users(first: $first, kind: $kind) { id } }

Bad. The linter reports Variable 'first' should come before 'kind'.

query Users($kind: Kind, $first: Int) { users(first: $first, kind: $kind) { id } }

When Not to Use It

Disable this rule when the order of definitions is meaningful, e.g. the most important fields first.