0
0
GraphQLquery~10 mins

Why mutations modify data in GraphQL - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a mutation that adds a new user with a name.

GraphQL
type Mutation { addUser(name: String!): [1] }
Drag options to blanks, or click blank then click option'
A: User
B{ id: ID, name: String }
C-> User
D!
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!' after the mutation name instead of after the argument type.
Using '->' which is not valid GraphQL syntax.
Trying to define fields inside the mutation signature.
2fill in blank
medium

Complete the mutation resolver function to update a user's name by ID.

GraphQL
updateUser: (parent, args, context) => { return context.db.users.[1](args.id, args.name); }
Drag options to blanks, or click blank then click option'
Aupdate
BupdateName
CupdateUserName
Dfind
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'find' which only retrieves data.
Using made-up method names not defined in the context.
Using 'updateName' which is not a standard method.
3fill in blank
hard

Fix the error in the mutation resolver that tries to delete a user but returns nothing.

GraphQL
deleteUser: (parent, args, context) => { context.db.users.delete(args.id); return [1]; }
Drag options to blanks, or click blank then click option'
Aargs.id
Btrue
Cnull
Dcontext.db.users.find(args.id)
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the deleted user's ID which no longer exists.
Returning true which is not a User object.
Trying to find the user after deletion which returns nothing.
4fill in blank
hard

Complete the code to complete the mutation that creates a post and returns its ID and title.

GraphQL
type Mutation { createPost(title: String!, content: String!): [1] { id, title } }
Drag options to blanks, or click blank then click option'
APost
BUser
C:
D,
Attempts:
3 left
💡 Hint
Common Mistakes
Using ':' instead of ',' between fields.
Returning 'User' instead of 'Post'.
Omitting the comma between fields.
5fill in blank
hard

Fill all three blanks to write a mutation resolver that adds a comment and returns the comment text if the content length is greater than 0.

GraphQL
addComment: (parent, args, context) => { if (args.content.[3] [1] 0) { return { text: args.[2] }; } else { return null; } }
Drag options to blanks, or click blank then click option'
A>
Bcontent
Clength
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Using 'text' instead of 'content' for the argument field.
Using 'length' as a field name instead of a property.