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 |
Remember the WHERE clause filters users older than 30.
The query selects users with age greater than 30, so Bob (35) and Carol (40) are included.
Why is batching SQL queries in GraphQL resolvers beneficial?
Think about how many times the database is accessed.
Batching combines multiple requests into one query, reducing database calls and speeding up response time.
Which option contains the correct SQL query syntax used inside a GraphQL resolver?
SELECT * FROM orders WHERE user_id = $1;
Check the operator used for comparison in SQL.
SQL uses a single equals sign (=) for comparison, not double equals (==) or other operators.
You have a GraphQL query requesting users and their posts. Which approach optimizes SQL database resolvers to avoid the N+1 query problem?
Think about how to reduce the number of queries to the database.
Using a JOIN fetches all needed data in one query, preventing multiple queries per user (N+1 problem).
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?
Check how variables are passed from GraphQL to SQL.
If the parameter $1 is not bound correctly, the query filters on NULL or empty value, returning no rows.