# strict-id-in-types

Source: https://apigenie.pl/docs/linter/graphql/rules/strict-id-in-types

This rule checks that object types have exactly one non-null identifier field, `id: ID!` by default.

## Rule Details

Clients such as Apollo Client and Relay cache objects by their identifier. Root operation types are not checked; payload and connection types usually need exceptions.

## Configuration

The configuration block is an object with the properties:

- `acceptedIdNames`: the names of identifier fields, `[id]` by default
- `acceptedIdTypes`: the types of identifier fields, `[ID]` by default
- `exceptions`: an object with `types`, the names of types that are not checked, and `suffixes`,
  the suffixes of the names of types that are not checked

```yaml
version: "1.0"
commands:
  lint:
    graphql:
      rules:
        strict-id-in-types: [error, { exceptions: { suffixes: [Payload, Connection, Edge] } }]
```

The rule can be disabled for a node and everything nested in it with an `# apigenie-lint-disable strict-id-in-types` 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 definitions.

## Examples

**Good**.

```graphql
type User { id: ID!, name: String }
```

**Bad**. The linter reports `Object type 'User' should have exactly one non-null field named 'id' of type 'ID'`.

```graphql
type User { name: String }
```
