Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning
Query instead of the object type.Returning
String or Boolean which are not the user type.✗ Incorrect
The mutation should return the
User type after adding a user.2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
String without ! which makes the argument optional.Using wrong types like
Int or Boolean.✗ Incorrect
The exclamation mark
! means the email argument is required.3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning just
User instead of a list.Using
[User] without ! which allows null list.✗ Incorrect
The mutation returns a non-null list of
User objects, so [User]! is correct.4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping
parent and args positions.Using
context or info as first or second argument.✗ Incorrect
The first argument is usually
parent, the second is args containing input data.5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
parent instead of args to access input.Using
context which is not the input argument.✗ Incorrect
The resolver uses
args to access input fields name and email.