useGraphqlSortedVariables (GraphQL)
Summary
Section titled “Summary”- Rule available since:
v2.6.0 - Diagnostic Category:
assist/source/useGraphqlSortedVariables - 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.useGraphqlSortedVariables.biome": "explicit", "source.fixAll.biome": "explicit" }}{ "code_actions_on_format": { "source.action.useGraphqlSortedVariables.biome": true, "source.fixAll.biome": true }}source.action.useGraphqlSortedVariables.biome How to configure
Section titled “How to configure”{ "assist": { "actions": { "source": { "useGraphqlSortedVariables": "on" } } }}Description
Section titled “Description”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).
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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 }}Caveats
Section titled “Caveats”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.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.