0
0
GraphQLquery~20 mins

SQL database resolvers in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SQL Resolver Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Resolving a simple SQL query in GraphQL

Given a GraphQL resolver that runs this SQL query:

SELECT id, name FROM users WHERE age > 30;

What will be the output of the resolver if the users table contains:

| id | name  | age |
|----|-------|-----|
| 1  | Alice | 25  |
| 2  | Bob   | 35  |
| 3  | Carol | 40  |
A[]
B[{"id": 1, "name": "Alice"}]
C[{"id": 2, "name": "Bob"}]
D[{"id": 2, "name": "Bob"}, {"id": 3, "name": "Carol"}]
Attempts:
2 left
💡 Hint

Remember the WHERE clause filters users older than 30.

🧠 Conceptual
intermediate
1:30remaining
Understanding resolver batching in SQL database resolvers

Why is batching SQL queries in GraphQL resolvers beneficial?

AIt increases the number of queries sent to the database.
BIt reduces the number of database calls, improving performance.
CIt makes the resolver code more complex without benefits.
DIt prevents caching of query results.
Attempts:
2 left
💡 Hint

Think about how many times the database is accessed.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in this SQL resolver code snippet

Which option contains the correct SQL query syntax used inside a GraphQL resolver?

SELECT * FROM orders WHERE user_id = $1;
ASELECT * FROM orders WHERE user_id = $1;
BSELECT * FROM orders WHERE user_id == $1;
CSELECT * FROM orders WHERE user_id := $1;
DSELECT * FROM orders WHERE user_id =? $1;
Attempts:
2 left
💡 Hint

Check the operator used for comparison in SQL.

optimization
advanced
2:30remaining
Optimizing SQL database resolvers for nested GraphQL queries

You have a GraphQL query requesting users and their posts. Which approach optimizes SQL database resolvers to avoid the N+1 query problem?

AUse a single SQL JOIN query to fetch users and their posts together.
BFetch posts first, then fetch users separately.
CFetch all users, then for each user fetch posts with separate queries.
DFetch users and posts in two unrelated queries without joining.
Attempts:
2 left
💡 Hint

Think about how to reduce the number of queries to the database.

🔧 Debug
expert
3:00remaining
Debugging a resolver that returns empty results unexpectedly

A GraphQL resolver runs this SQL query:

SELECT * FROM products WHERE category = $1;

But it always returns an empty list even though the database has matching products. What is the most likely cause?

AThe SQL query syntax is incorrect.
BThe products table is empty.
CThe variable $1 is not properly passed or bound in the resolver.
DThe GraphQL schema does not define the products type.
Attempts:
2 left
💡 Hint

Check how variables are passed from GraphQL to SQL.