# one-field-subscriptions

Source: https://apigenie.pl/docs/linter/graphql/rules/one-field-subscriptions

This rule checks that subscriptions select a single root field, as the specification requires.

## Rule Details

A subscription maps one event stream to responses; selecting several root fields, or an introspection field, is invalid. Inline fragments and the fragments of the document are followed.

## Configuration

This rule has no options.

```yaml
version: "1.0"
commands:
  lint:
    graphql:
      rules:
        one-field-subscriptions: warning
```

The rule can be disabled for a node and everything nested in it with an `# apigenie-lint-disable one-field-subscriptions` 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**.

```graphql
subscription OnMessage { messageAdded { id } }
```

**Bad**. The linter reports `Subscription "OnEvents" must select only one top level field.`.

```graphql
subscription OnEvents { messageAdded { id } userJoined { id } }
```
