0
0
GraphQLquery~10 mins

Context argument in GraphQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to access the context argument in a resolver function.

GraphQL
const resolver = (parent, args, [1]) => { return [1].userId; }
Drag options to blanks, or click blank then click option'
Ainfo
Bcontext
Cargs
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using args or parent instead of context to get user info.
Confusing the order of resolver arguments.
2fill in blank
medium

Complete the code to extract the user role from the context argument.

GraphQL
function checkRole(_, __, [1]) { return [1].user.role; }
Drag options to blanks, or click blank then click option'
Ainfo
Bargs
Ccontext
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to get user role from args or parent.
Using the wrong argument position.
3fill in blank
hard

Fix the error in accessing the context argument in this resolver.

GraphQL
const resolver = (parent, args, info) => { return [1].userId; }
Drag options to blanks, or click blank then click option'
Ainfo
Bargs
Ccontext
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use context (undefined) or args/parent instead of info.
Not passing context properly to resolvers.
4fill in blank
hard

Fill both blanks to correctly use context and args in a resolver.

GraphQL
const resolver = (parent, [1], [2]) => { return [2].user.id === [1].id; }
Drag options to blanks, or click blank then click option'
Aargs
Bcontext
Cinfo
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping args and context positions.
Using info instead of context.
5fill in blank
hard

Fill all three blanks to destructure context and use args in a resolver.

GraphQL
const resolver = (_, [1], [2]) => { const { user } = [3]; return user.id === [1].id; }
Drag options to blanks, or click blank then click option'
Aargs
Bcontext
Cinfo
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using info or parent instead of context.
Mixing up args and context.