require-selections

Since 0.9.0 · In the rulesets: Strict at error, All at error

This rule checks that selections of objects with an identifier select it.

Rule details

Clients such as Apollo Client and Relay cache and update objects by their identifier; an object fetched without it cannot be normalized. The identifier may be selected directly, in inline fragments or in the fragments of the document.

The rule checks operations against the schema files named by the schema property of the configuration, or against the type system of their own document. It reports nothing without a schema.

The rule applies to operations and fragments. An # apigenie-lint-disable require-selections comment on a node turns it off for the node and everything nested in it; at the top of the file, separated from the first definition by a blank line, the comment turns it off for the whole file.

Configuration

The configuration block can be a string, the name of the identifier field, or an object with the fieldName property. The name is id by default.

version: "1.0"
commands:
  lint:
    graphql:
      rules:
        require-selections: [error, uuid]

Examples

Good.

query Me { me { id name } }

Bad. The linter reports Field 'me' should select 'id', which identifies its type 'User'.

query Me { me { name } }

Turn it off or change its severity

In apigenie.yaml, off turns the rule off and warning or error sets its severity; a rule with options takes the severity and the options as a pair, [warning, options]. lint.graphql has the details.

commands:
  lint:
    graphql:
      rules:
        require-selections: off
Last updated on View as Markdown
Was this helpful?