Skip to content

useSortedSelectionSet (GraphQL)

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

Sort selections inside GraphQL operations and fragments.

The action places fields first, named fragment spreads such as ...UserFields next, and inline fragments such as ... on User last. Within each group, names use natural order, which compares numbers by value.

An aliased field is sorted by its alias. For example, firstName: name is sorted under firstName, which is the name returned in the response.

query {
id
...bFragment
firstName: name
... on Contact {
phoneNumber
email
}
age
... on Address {
street
city
}
...aFragment
}
code-block.graphql ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ Source action diff:

1 1 │ query {
2 │ - ··id
3 │ - ··...bFragment
4 │ - ··firstName:·name
5 │ - ··...·on·Contact·{
6 │ - ····phoneNumber
7 │ - ····email
2 │ + ··age
3 │ + ··firstName:·name
4 │ + ··id
5 │ + ··...aFragment
6 │ + ··...bFragment
7 │ + ··...·on·Address·{
8 │ + ····street
9 │ + ····city
8 10 │ }
9 │ - ··age
10 │ - ··...·on·Address·{
11 │ - ····street
12 │ - ····city
11 │ + ··...·on·Contact·{
12 │ + ····phoneNumber
13 │ + ····email
13 14 │ }
14 │ - ··...aFragment
15 15 │ }
16 16 │

code-block.graphql ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ Source action diff:

4 4 │ firstName: name
5 5 │ ... on Contact {
6 │ - ····phoneNumber
7 │ - ····email
6 │ + ····email
7 │ + ····phoneNumber
8 8 │ }
9 9 │ age

code-block.graphql ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ Source action diff:

9 9 │ age
10 10 │ ... on Address {
11 │ - ····street
12 │ - ····city
11 │ + ····city
12 │ + ····street
13 13 │ }
14 14 │ ...aFragment

query {
age
firstName: name
id
...aFragment
...bFragment
... on Address {
city
street
}
... on Contact {
email
phoneNumber
}
}