Complete the code to define a GraphQL query that fetches all users from MongoDB.
type Query { users: [User] [1] }The users field returns a list of User objects. No exclamation mark means it can be null or empty.
Complete the resolver function to fetch all users from MongoDB collection.
const resolvers = { Query: { users: async () => await db.collection('[1]').find().toArray() } }The MongoDB collection name for users is usually 'users'.
Fix the error in the GraphQL schema for a User type with an ID field.
type User { id: [1] name: String }The ID field should be of type 'ID!' to uniquely identify the user and be non-nullable.
Fill both blanks to define a mutation that adds a new user with a name argument.
type Mutation { addUser(name: [1]): User [2] }The name argument should be a non-nullable String, and the mutation returns a User type with a non-nullable result.
Fill all three blanks to write a resolver for addUser mutation that inserts a user and returns it.
const resolvers = { Mutation: { addUser: async (_, { [1] }) => { const result = await db.collection('users').insertOne({ [2] }); return result.[3]; } } }The resolver takes 'name' argument, inserts a document with 'name: name', and returns the inserted document from 'ops[0]'.