0
0
GraphQLquery~10 mins

Create mutation pattern 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 GraphQL mutation named addUser.

GraphQL
type Mutation {
  addUser(name: String!): [1]
}
Drag options to blanks, or click blank then click option'
AString
BQuery
CUser
DBoolean
Attempts:
3 left
💡 Hint
Common Mistakes
Returning Query instead of the object type.
Returning String or Boolean which are not the user type.
2fill in blank
medium

Complete the mutation argument to require an email of type String.

GraphQL
type Mutation {
  addUser(name: String!, email: [1]): User
}
Drag options to blanks, or click blank then click option'
AString!
BInt
CString
DBoolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using String without ! which makes the argument optional.
Using wrong types like Int or Boolean.
3fill in blank
hard

Fix the error in the mutation return type to correctly return a list of users.

GraphQL
type Mutation {
  addUsers(names: [String!]!): [1]
}
Drag options to blanks, or click blank then click option'
A[User]
BUser
C[User!]
D[User]!
Attempts:
3 left
💡 Hint
Common Mistakes
Returning just User instead of a list.
Using [User] without ! which allows null list.
4fill in blank
hard

Fill both blanks to complete the mutation resolver signature in JavaScript.

GraphQL
const resolvers = {
  Mutation: {
    addUser: ([1], [2]) => {
      // resolver code
    }
  }
};
Drag options to blanks, or click blank then click option'
Aparent
Bargs
Ccontext
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping parent and args positions.
Using context or info as first or second argument.
5fill in blank
hard

Fill all three blanks to complete the mutation resolver that returns the created user.

GraphQL
const resolvers = {
  Mutation: {
    addUser: (parent, [1]) => {
      const newUser = { name: [2].name, email: [3].email };
      // save newUser to database
      return newUser;
    }
  }
};
Drag options to blanks, or click blank then click option'
Aargs
Bparent
Dcontext
Attempts:
3 left
💡 Hint
Common Mistakes
Using parent instead of args to access input.
Using context which is not the input argument.