0
0
GraphQLquery~20 mins

Sorting arguments in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sorting Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Sorting users by age ascending
Given this GraphQL query to fetch users sorted by age in ascending order, what is the order of user names returned?
GraphQL
query {
  users(sort: {field: "age", direction: ASC}) {
    name
    age
  }
}
A["Alice", "Bob", "Charlie"]
B["Charlie", "Bob", "Alice"]
C["Alice", "Charlie", "Bob"]
D["Bob", "Alice", "Charlie"]
Attempts:
2 left
💡 Hint
Think about sorting numbers from smallest to largest.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in sorting argument
Which option contains a syntax error in the sorting argument of this GraphQL query?
GraphQL
query {
  products(sort: {field: "price", direction: DESC}) {
    id
    price
  }
}
A}CSED :noitcerid ,"ecirp" :dleif{ :tros
Bsort: {field: "price", direction: DESC}
Csort: {field: "price", direction: "DESC"}
Dsort: {field: price, direction: "DESC"}
Attempts:
2 left
💡 Hint
Field names in GraphQL arguments must be strings if they are not enums.
optimization
advanced
2:00remaining
Optimizing sorting for large datasets
Which sorting argument approach is best to optimize performance when fetching a large list of items sorted by creation date descending?
GraphQL
query {
  items(sort: {field: "createdAt", direction: DESC}) {
    id
    createdAt
  }
}
ASort by 'id' instead of 'createdAt' to speed up sorting.
BFetch all items unsorted and sort on the client side.
CUse server-side sorting with an indexed 'createdAt' field.
DRemove sorting argument to reduce query complexity.
Attempts:
2 left
💡 Hint
Think about where sorting is most efficient for large data.
🧠 Conceptual
advanced
2:00remaining
Understanding multi-field sorting arguments
How does the following sorting argument affect the order of results?
sort: [{field: "lastName", direction: ASC}, {field: "firstName", direction: ASC}]
ASorts results first by lastName ascending, then by firstName ascending within each lastName.
BSorts results by firstName ascending only, ignoring lastName.
CSorts results randomly because multiple fields are not supported.
DSorts results by lastName descending, then firstName ascending.
Attempts:
2 left
💡 Hint
Think about sorting by multiple keys in order.
🔧 Debug
expert
2:00remaining
Debugging incorrect sorting direction
A developer wrote this query to sort posts by date descending but results appear sorted ascending. Which option explains the likely cause?
GraphQL
query {
  posts(sort: {field: "date", direction: "desc"}) {
    id
    date
  }
}
AThe field name "date" is invalid and causes fallback to default sorting.
BThe sorting direction value is case-sensitive and should be "DESC" instead of "desc".
CThe query is missing a limit argument causing sorting to fail.
DGraphQL does not support sorting by date fields.
Attempts:
2 left
💡 Hint
Check if sorting direction values are case-sensitive enums.