Complete the code to define a resolver that returns the user's name.
const resolvers = {
Query: {
user: (parent, args, context, info) => [1]
}
};The resolver function accesses the parent object to get the user's name.
Complete the resolver chain to fetch the user's posts from the database.
const resolvers = {
User: {
posts: (parent, args, context) => [1]
}
};The resolver uses the context to access the database and fetch posts by the user's ID.
Fix the error in the resolver chain to correctly resolve the user's profile picture URL.
const resolvers = {
User: {
profilePicture: (parent, args, context) => {
return context.storage.getUrl([1]);
}
}
};The resolver should use the profilePicId from the parent object to get the URL.
Fill both blanks to create a resolver chain that fetches comments for a post and filters by author ID.
const resolvers = {
Post: {
comments: (parent, args, context) => {
return context.db.getCommentsByPostId(parent.[1]).filter(comment => comment.[2] === args.authorId);
}
}
};The post's ID is parent.id, and comments have an authorId to filter by.
Fill all three blanks to create a resolver chain that fetches a user's friends and maps their names.
const resolvers = {
User: {
friendsNames: async (parent, args, context) => {
const friends = await context.db.getFriendsByUserId(parent.[1]);
return friends.map(friend => friend.[2]).filter(name => name [3] '');
}
}
};The resolver uses parent.id to get friends, maps their name, and filters out empty names using !==.