Challenge - 5 Problems
Sorting Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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
}
}Attempts:
2 left
💡 Hint
Think about sorting numbers from smallest to largest.
✗ Incorrect
The query sorts users by their age in ascending order, so the youngest user appears first.
📝 Syntax
intermediate2: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
}
}Attempts:
2 left
💡 Hint
Field names in GraphQL arguments must be strings if they are not enums.
✗ Incorrect
Option D misses quotes around the field name 'price', causing a syntax error.
❓ optimization
advanced2: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
}
}Attempts:
2 left
💡 Hint
Think about where sorting is most efficient for large data.
✗ Incorrect
Sorting on the server using an indexed field is faster and uses less bandwidth than client-side sorting.
🧠 Conceptual
advanced2: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}]Attempts:
2 left
💡 Hint
Think about sorting by multiple keys in order.
✗ Incorrect
The results are sorted by lastName ascending first. If lastNames are equal, then firstName ascending is used to order those entries.
🔧 Debug
expert2: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
}
}Attempts:
2 left
💡 Hint
Check if sorting direction values are case-sensitive enums.
✗ Incorrect
Sorting direction is often case-sensitive. Using "desc" instead of "DESC" can cause the server to ignore the direction or default to ascending.