Skip to content

useGraphqlSortedArguments (GraphQL)

Language GraphQL
.vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.action.useGraphqlSortedArguments.biome": "explicit",
"source.fixAll.biome": "explicit"
}
}
biome.json
{
"assist": {
"actions": {
"source": {
"useGraphqlSortedArguments": "on"
}
}
}
}

Sort the arguments of GraphQL fields and directives in natural order.

This action sorts both the arguments passed to fields and directives, and the arguments declared by field and directive definitions. Keeping them sorted makes long argument lists easier to scan and review. The order of arguments doesn’t affect how a field or a directive is executed.

Arguments 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).

query {
users(orderBy: NAME, first: 10, after: "cursor") {
name
}
}
code-block.graphql ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ Source action diff:

1 1 │ query {
2 │ - ··users(orderBy:·NAME,·first:·10,·after:·"cursor")·{
2 │ + ··users(after:·"cursor",·first:·10,·orderBy:·NAME)·{
3 3 │ name
4 4 │ }

type Query {
users(orderBy: Order, first: Int, after: String): [User]
}
code-block.graphql ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ Source action diff:

1 1 │ type Query {
2 │ - ··users(orderBy:·Order,·first:·Int,·after:·String):·[User]
2 │ + ··users(after:·String,·first:·Int,·orderBy:·Order):·[User]
3 3 │ }
4 4 │

query {
users(after: "cursor", first: 10, orderBy: NAME) {
name
}
}
type Query {
users(after: String, first: Int, orderBy: Order): [User]
}

Comments above an argument and comments at the end of its line move with that argument. No fix is offered when a moved comment would end up on the same line as other code, because the comment would then hide that code or describe a different argument. Sort such arguments manually, or put each argument on its own line.