0
0
GraphQLquery~10 mins

Parent (root) 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 define a resolver that accesses the parent argument.

GraphQL
const resolvers = { Query: { user: ([1], args, context) => { return getUserById(args.id); } } };
Drag options to blanks, or click blank then click option'
Aparent
Bargs
Ccontext
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'args' as the first argument instead of 'parent'.
Confusing 'context' with the parent argument.
2fill in blank
medium

Complete the resolver to access a field from the parent argument.

GraphQL
const resolvers = { User: { fullName: ([1]) => { return `${parent.firstName} ${parent.lastName}`; } } };
Drag options to blanks, or click blank then click option'
Aargs
Binfo
Ccontext
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'args' to access user fields instead of 'parent'.
Forgetting to include the parent argument in the resolver.
3fill in blank
hard

Fix the error in the resolver by correctly naming the parent argument.

GraphQL
const resolvers = { User: { age: ([1], args) => { return parent.age; } } };
Drag options to blanks, or click blank then click option'
Aparent
Bargs
Ccontext
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'args' as the first argument but referencing 'parent' inside the function.
Not passing the parent argument at all.
4fill in blank
hard

Fill both blanks to correctly destructure the parent argument and access args.

GraphQL
const resolvers = { Query: { post: ([1], [2]) => { return getPostById(args.id); } } };
Drag options to blanks, or click blank then click option'
Aparent
Bargs
Ccontext
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of arguments.
Using 'context' instead of 'args' for query parameters.
5fill in blank
hard

Fill all three blanks to define a resolver using parent, args, and context arguments.

GraphQL
const resolvers = { Mutation: { updateUser: ([1], [2], [3]) => { return updateUserInDb(args.id, args.input, context.db); } } };
Drag options to blanks, or click blank then click option'
Aparent
Bargs
Ccontext
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of arguments.
Using 'info' instead of 'context' for database access.