Skip to content

useLoneExecutableDefinition

biome.json
{
"linter": {
"rules": {
"style": {
"useLoneExecutableDefinition": "error"
}
}
}
}

Require queries, mutations, subscriptions or fragments each to be located in separate files.

This rule ensures that each GraphQL document only contains a single operation (query, mutation, or subscription) or fragment definition. Having multiple executable definitions in a single file can make code harder to maintain, test, and understand.

query Foo {
id
}
fragment Bar on Baz {
id
}
code-block.graphql:5:1 lint/style/useLoneExecutableDefinition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Document contains multiple definitions. This definition should be in a separate file.

3 │ }
4 │
> 5 │ fragment Bar on Baz {
^^^^^^^^^^^^^^^^^^^^^
> 6 │ id
> 7 │ }
^
8 │

Queries, mutations, subscriptions or fragments each must be defined in separate files.

query Foo {
id
}
mutation ($name: String!) {
createUser {
id
}
}
code-block.graphql:5:1 lint/style/useLoneExecutableDefinition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Document contains multiple definitions. This definition should be in a separate file.

3 │ }
4 │
> 5 │ mutation ($name: String!) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 6 │ createUser {
> 7 │ id
> 8 │ }
> 9 │ }
^
10 │

Queries, mutations, subscriptions or fragments each must be defined in separate files.

query Foo {
id
}
query Bar {
id
}
code-block.graphql:5:1 lint/style/useLoneExecutableDefinition ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Document contains multiple definitions. This definition should be in a separate file.

3 │ }
4 │
> 5 │ query Bar {
^^^^^^^^^^^
> 6 │ id
> 7 │ }
^
8 │

Queries, mutations, subscriptions or fragments each must be defined in separate files.

query Foo {
id
}
fragment Bar on Baz {
id
}