# selection-set-depth

Source: https://apigenie.pl/docs/linter/graphql/rules/selection-set-depth

A rule of the GraphQL linter, which reads GraphQL schemas and operations. Since 0.9.0. In the rulesets: Recommended at warning, Strict at error, All at error.

This rule checks that selection sets are nested at most 7 levels deep.

## Rule details

Deep queries are expensive to execute and often a sign of over-fetching. The fields of the fragments of the document are counted where they are spread; the root fields have the depth 1.

The rule applies to operations and fragments. An `# apigenie-lint-disable selection-set-depth`
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 is an object with the properties:

- `maxDepth`: the maximum depth, from 1 to 1000, 7 by default
- `ignore`: the names of fields whose selections are not counted, e.g. `edges`

```yaml
version: "1.0"
commands:
  lint:
    graphql:
      rules:
        selection-set-depth: [warning, { maxDepth: 10, ignore: [edges, node] }]
```

## Examples

**Good**.

```graphql
query Me { me { friends { name } } }
```

**Bad**. The linter reports `Field 'name' of operation 'Me' is nested deeper than the maximum depth of 7`.

```graphql
query Me { me { friends { friends { friends { friends { friends { friends { name } } } } } } } }
```
