Challenge - 5 Problems
GraphQL Resolver Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Identify the correct resolver function signature
Which of the following is the correct signature for a GraphQL resolver function?
Attempts:
2 left
💡 Hint
Remember the order: parent, arguments, context, and info.
✗ Incorrect
The standard resolver function signature in GraphQL is function resolver(parent, args, context, info). This order is important because GraphQL passes these parameters in this sequence.
❓ query_result
intermediate1:30remaining
Output of resolver accessing arguments
Given this resolver function, what will be the output if called with args = { id: 5 }?
function resolver(parent, args, context, info) {
return args.id * 2;
}
GraphQL
function resolver(parent, args, context, info) { return args.id * 2; }
Attempts:
2 left
💡 Hint
Look at how the argument 'id' is used inside the function.
✗ Incorrect
The resolver multiplies the id argument by 2. Since id is 5, the output is 10.
📝 Syntax
advanced2:00remaining
Identify the syntax error in resolver function
Which option contains a syntax error in the resolver function signature?
Attempts:
2 left
💡 Hint
Check the commas between parameters.
✗ Incorrect
Option B is missing a comma between parent and args, causing a syntax error.
❓ optimization
advanced2:30remaining
Best practice for using context in resolver
Which option shows the best practice for accessing user information from context inside a resolver?
Attempts:
2 left
💡 Hint
User info is usually stored in context, not args or parent.
✗ Incorrect
Context is the place to store per-request data like authenticated user info. Accessing context.user.id is the best practice.
🔧 Debug
expert3:00remaining
Why does this resolver throw an error?
Consider this resolver:
function resolver(parent, args, context, info) {
return args.input.value;
}
If the query is called without the 'input' argument, what error will occur?
Attempts:
2 left
💡 Hint
What happens if you try to access a property of undefined?
✗ Incorrect
If args.input is undefined, trying to access value on it causes a TypeError.