0
0
GraphQLquery~20 mins

Filtering arguments in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Filtering Arguments Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Filtering users by age greater than 30
Given the following GraphQL query, what is the expected output if the database contains users with ages 25, 35, and 40?
GraphQL
query {
  users(age_gt: 30) {
    id
    name
    age
  }
}
A[{"id": "1", "name": "John", "age": 25}, {"id": "2", "name": "Alice", "age": 35}, {"id": "3", "name": "Bob", "age": 40}]
B[{"id": "1", "name": "John", "age": 25}]
C[{"id": "2", "name": "Alice", "age": 35}, {"id": "3", "name": "Bob", "age": 40}]
D[]
Attempts:
2 left
💡 Hint
Think about which users have age greater than 30.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in filtering by name
Which option contains a syntax error in this GraphQL query filtering users by name?
GraphQL
query {
  users(name_eq: "John") {
    id
    name
  }
}
Aquery { users(name_eq: John) { id name } }
Bquery { users(name_eq: "John") { id name } }
C} } eman di { )"nhoJ" :qe_eman(sresu { yreuq
Duery { users(name_eq: "John") { id name } }
Attempts:
2 left
💡 Hint
Check if string values are properly quoted.
optimization
advanced
2:00remaining
Optimizing filtering with multiple arguments
Which query is the most efficient to filter users by age greater than 20 and name starting with 'A'?
Aquery { users(age_gt: 20, name_starts_with: "A") { id name age } }
Bquery { users { id name age } } # filter client-side
Cquery { users(age_gt: 20) { id name age } } # then filter name client-side
Dquery { users(name_starts_with: "A") { id name age } } # then filter age client-side
Attempts:
2 left
💡 Hint
Filtering on the server reduces data transfer and processing.
🧠 Conceptual
advanced
2:00remaining
Understanding filtering argument types
Which filtering argument type allows selecting records where a field value is within a list of values?
Acontains (substring match)
Bgt (greater than)
Ceq (equals)
Din (within a list)
Attempts:
2 left
💡 Hint
Think about selecting multiple possible values for a field.
🔧 Debug
expert
2:00remaining
Debugging a filter that returns no results
A query filters users with age_lt: 18 but returns no results, even though the database has users aged 16 and 17. Which option explains the most likely cause?
GraphQL
query {
  users(age_lt: 18) {
    id
    name
    age
  }
}
AThe database has no users younger than 18, so no results are returned.
BThe filter argument 'age_lt' is not supported by the schema, so it is ignored.
CThe query syntax is invalid, causing no results to be returned.
DThe filter should be 'age_lt: "18"' with quotes around the number.
Attempts:
2 left
💡 Hint
Check if the filtering argument is defined in the schema.