Skip to content

useGraphqlSortedVariables (GraphQL)

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

Sort the variable definitions of GraphQL operations in natural order.

Keeping the variables of query, mutation, and subscription operations sorted makes long variable lists easier to scan and review. The order of variable definitions doesn’t affect how an operation is executed.

Variables 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 GetUser($userId: ID!, $includePosts: Boolean = false, $after: String) {
user(id: $userId) {
name
}
}
code-block.graphql ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ Source action diff:

1 │ - query·GetUser($userId:·ID!,·$includePosts:·Boolean·=·false,·$after:·String)·{
1 │ + query·GetUser($after:·String,·$includePosts:·Boolean·=·false,·$userId:·ID!)·{
2 2 │ user(id: $userId) {
3 3 │ name

query GetUser($after: String, $includePosts: Boolean = false, $userId: ID!) {
user(id: $userId) {
name
}
}

Comments above a variable and comments at the end of its line move with that variable. 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 variable. Sort such variables manually, or put each variable on its own line.