0
0
GraphQLquery~10 mins

Nested resolver execution 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 nested resolver for the 'author' field inside 'Book' type.

GraphQL
const resolvers = {
  Book: {
    author: (parent, args, context, info) => [1]
  }
};
Drag options to blanks, or click blank then click option'
Aargs.id
Bparent.authorId
Ccontext.db.getAuthorById(parent.authorId)
Dinfo.fieldName
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 'parent.authorId' directly without fetching author data.
Using 'args.id' which is not provided in this context.
2fill in blank
medium

Complete the resolver to fetch nested comments for a 'Post' type.

GraphQL
const resolvers = {
  Post: {
    comments: (parent, args, context) => [1]
  }
};
Drag options to blanks, or click blank then click option'
Acontext.db.getPostById(args.id)
Bparent.comments
Cargs.postId
Dcontext.db.getCommentsByPostId(parent.id)
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 'parent.comments' assuming comments are already loaded.
Using 'args.postId' which may not be provided.
3fill in blank
hard

Fix the error in the nested resolver to correctly fetch the 'profile' for a 'User'.

GraphQL
const resolvers = {
  User: {
    profile: (parent, args, context) => [1]
  }
};
Drag options to blanks, or click blank then click option'
Acontext.db.getProfileByUserId(parent.id)
Bcontext.db.getProfileByUserId(args.id)
Cparent.profile
Dcontext.db.getUserById(parent.profileId)
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'args.id' which may not be passed to this resolver.
Returning 'parent.profile' assuming profile is already loaded.
4fill in blank
hard

Fill both blanks to correctly resolve nested 'orders' and their 'items' for a 'Customer'.

GraphQL
const resolvers = {
  Customer: {
    orders: (parent, args, context) => [1]
  },
  Order: {
    items: (parent, args, context) => [2]
  }
};
Drag options to blanks, or click blank then click option'
Acontext.db.getOrdersByCustomerId(parent.id)
Bcontext.db.getItemsByOrderId(parent.id)
Cparent.orders
Dparent.items
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 'parent.orders' or 'parent.items' assuming data is preloaded.
Mixing up customer id and order id in the resolvers.
5fill in blank
hard

Fill all three blanks to correctly resolve nested 'categories', 'products', and 'reviews' in a GraphQL schema.

GraphQL
const resolvers = {
  Category: {
    products: (parent, args, context) => [1]
  },
  Product: {
    reviews: (parent, args, context) => [2]
  },
  Review: {
    author: (parent, args, context) => [3]
  }
};
Drag options to blanks, or click blank then click option'
Acontext.db.getProductsByCategoryId(parent.id)
Bcontext.db.getReviewsByProductId(parent.id)
Ccontext.db.getUserById(parent.authorId)
Dparent.products
Attempts:
3 left
💡 Hint
Common Mistakes
Returning parent fields directly without fetching related data.
Using wrong parent properties like 'parent.productId' in the wrong resolver.