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