0
0
GraphQLquery~20 mins

Resolver function signature in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GraphQL Resolver Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Identify the correct resolver function signature
Which of the following is the correct signature for a GraphQL resolver function?
Afunction resolver(parent, args, context, info) { ... }
Bfunction resolver(args, parent, context) { ... }
Cfunction resolver(context, args, parent, info) { ... }
Dfunction resolver(info, context, args, parent) { ... }
Attempts:
2 left
💡 Hint
Remember the order: parent, arguments, context, and info.
query_result
intermediate
1: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;
}
Aundefined
B5
CNaN
D10
Attempts:
2 left
💡 Hint
Look at how the argument 'id' is used inside the function.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in resolver function
Which option contains a syntax error in the resolver function signature?
Aconst resolver = (parent, args, context, info) => { return args.value; }
Bfunction resolver(parent args, context, info) { return args.value; }
Cfunction resolver(parent, args, context, info) { return args.value; }
Dconst resolver = function(parent, args, context, info) { return args.value; }
Attempts:
2 left
💡 Hint
Check the commas between parameters.
optimization
advanced
2:30remaining
Best practice for using context in resolver
Which option shows the best practice for accessing user information from context inside a resolver?
Afunction resolver(parent, args, context, info) { return parent.user.id; }
Bfunction resolver(parent, args, context, info) { return args.user.id; }
Cfunction resolver(parent, args, context, info) { return context.user.id; }
Dfunction resolver(parent, args, context, info) { return info.user.id; }
Attempts:
2 left
💡 Hint
User info is usually stored in context, not args or parent.
🔧 Debug
expert
3: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?
ATypeError: Cannot read property 'value' of undefined
BReferenceError: input is not defined
CSyntaxError: Unexpected token
DNo error, returns undefined
Attempts:
2 left
💡 Hint
What happens if you try to access a property of undefined?