# fragment-naming

Source: https://api-genie.dev/docs/linter/graphql/rules/fragment-naming

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 fragment names follow a naming convention, PascalCase by default.

## Rule details

Consistent names make a schema predictable for its clients: generated code, documentation and queries read the same everywhere. The rule reports a name that doesn't follow the convention, with the name converted to it as a suggestion.

The rule applies to operations and fragments. An `# apigenie-lint-disable fragment-naming` 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 convention, or an object with the
properties:

- `convention`: `camelCase`, `camelCaseStrict`, `PascalCase`, `PascalCaseStrict`, `snake_case`,
  `CONST_CASE` (or `UPPER_CASE`), `kebab-case` or `Header-Case`; the strict forms reject two
  capitals in a row (`userID`)
- `allowLeadingUnderscore`: whether leading underscores are ignored, e.g. in `_service`; `false`
  by default

```yaml
version: "1.0"
commands:
  lint:
    graphql:
      rules:
        fragment-naming: [warning, { convention: snake_case, allowLeadingUnderscore: true }]
```

## Examples

**Good**.

```graphql
fragment UserFields on User { id }
```

**Bad**. The linter reports `Fragment name 'userFields' should be PascalCase, e.g. 'UserFields'`.

```graphql
fragment userFields on User { id }
```
