# strict-id-in-types

Source: https://api-genie.dev/docs/linter/graphql/rules/strict-id-in-types

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

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.

The rule applies to definitions. An `# apigenie-lint-disable strict-id-in-types` 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:

- `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] } }]
```

## 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 }
```
