matchDocumentFilename
| Property | Value |
|---|---|
| Config name | matchDocumentFilename |
| Default severity | — |
| Context | Document |
| In recommended | No |
What it checks
Section titled “What it checks”Enforces that GraphQL operation and fragment names match the filename they are defined in. For example, a file named GetUser.graphql should contain an operation named GetUser. This helps with code organization and makes operations easy to find.
The rule checks all named operations (queries, mutations, subscriptions) and fragment definitions. Anonymous operations and shorthand queries are ignored.
Examples
Section titled “Examples”# ✅ Good — operation name matches filenamequery GetUser { user { id name }}# ⚠️ Warning — operation name doesn't match filenamequery FetchUser { user { id name }}# ✅ Good — fragment name matches filenamefragment UserFields on User { id name}Options
Section titled “Options”Each definition type (query, mutation, subscription, fragment) can be configured independently with the following options:
| Option | Type | Default | Description |
|---|---|---|---|
style | string | matchDocumentStyle | Naming style for the filename |
suffix | string | "" | Suffix appended to the expected filename |
Supported styles
Section titled “Supported styles”| Style | Example input | Expected filename |
|---|---|---|
matchDocumentStyle | GetUser | GetUser |
camelCase | GetUser | getUser |
PascalCase | get_user | GetUser |
snake_case | GetUser | get_user |
kebab-case | GetUser | get-user |
Configuration
Section titled “Configuration”# Default: filenames must match the definition name exactlyextensions: graphql-analyzer: lint: rules: matchDocumentFilename: warn
# Enforce kebab-case filenames for queriesextensions: graphql-analyzer: lint: rules: matchDocumentFilename: severity: warn options: query: style: kebab-case
# Require suffixes per definition typeextensions: graphql-analyzer: lint: rules: matchDocumentFilename: severity: warn options: query: style: matchDocumentStyle suffix: Query mutation: style: matchDocumentStyle suffix: Mutation fragment: style: kebab-case suffix: .fragmentWith the suffix configuration above:
query GetUserexpects filenameGetUserQuery.graphqlmutation UpdateUserexpects filenameUpdateUserMutation.graphqlfragment UserFields on Userexpects filenameuser-fields.fragment.graphql