useGraphqlSortedDefinitions (GraphQL)
Summary
Section titled “Summary”- Rule available since:
v2.6.0 - Diagnostic Category:
assist/source/useGraphqlSortedDefinitions - Sources:
- Inspired from
@graphql-eslint/alphabetize
- Inspired from
How to enable in your editor
Section titled “How to enable in your editor”{ "editor.codeActionsOnSave": { "source.action.useGraphqlSortedDefinitions.biome": "explicit", "source.fixAll.biome": "explicit" }}{ "code_actions_on_format": { "source.action.useGraphqlSortedDefinitions.biome": true, "source.fixAll.biome": true }}source.action.useGraphqlSortedDefinitions.biome How to configure
Section titled “How to configure”{ "assist": { "actions": { "source": { "useGraphqlSortedDefinitions": "on" } } }}Description
Section titled “Description”Sort the named definitions in a GraphQL document.
This action natural sorts the named definitions of a document by name: the scalar, type,
interface, union, enum, and input definitions, their extend counterparts,
the directive definitions, the fragment definitions, and the named query,
mutation, and subscription operations.
Keeping them sorted makes growing documents easier to scan and review.
The order of definitions doesn’t affect how a document is executed or how a schema is built.
Definitions are sorted by name in a Natural order,
meaning that uppercase letters come before lowercase letters (e.g. A < a < B < b)
and numbers are compared to their numerical value (e.g. 9 < 10).
Definitions without a name, such as schema definitions, anonymous operations, and
shorthand queries, are placed after the named definitions.
Definitions with the same name aren’t sorted.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”type User { id: ID!}
enum Role { ADMIN USER}
directive @auth on FIELD_DEFINITIONcode-block.graphql ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Source action diff:
1 │ - type·User·{
2 │ - ··id:·ID!
3 │ - }
1 │ + directive·@auth·on·FIELD_DEFINITION
4 2 │
5 3 │ enum Role {
····· │
8 6 │ }
9 7 │
10 │ - directive·@auth·on·FIELD_DEFINITION
8 │ + type·User·{
9 │ + ··id:·ID!
10 │ + }
11 11 │
directive @auth on FIELD_DEFINITION
enum Role { ADMIN USER}
type User { id: ID!}Caveats
Section titled “Caveats”Comments above a definition and comments at the end of its last line move with that definition. Because moving a comment can change which definition it describes or hide code, the action offers no fix in these cases:
- A moved end-of-line comment would share a line with the next definition. Since a
#comment continues to the end of its line, it would hide that definition. For example, sorting this input would moveApplebeforeZebra, but the comment would hideZebra:
type Zebra { id: ID! } type Apple { id: ID! } # Keep Apple- A definition with a comment above it is, or would become, the first definition in the document.
Sort such definitions manually, or put each definition on its own line.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.