Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a mock resolver for a GraphQL query named hello that returns a string.
GraphQL
const mocks = {
Query: {
hello: () => [1]
}
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a number or boolean instead of a string.
Not using quotes around the string value.
✗ Incorrect
The mock resolver for a string field should return a string value, such as "Hello, world!".
2fill in blank
mediumComplete the code to mock a resolver for a user query that returns an object with a name field.
GraphQL
const mocks = {
Query: {
user: () => ({ name: [1] })
}
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a number or boolean instead of a string.
Returning null which may cause errors if not handled.
✗ Incorrect
The
name field expects a string, so the mock should return a string like "Alice".3fill in blank
hardFix the error in the mock resolver that should return a list of strings for the tags field.
GraphQL
const mocks = {
Query: {
tags: () => [1]
}
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a single string instead of an array.
Returning null or a number which does not match the expected type.
✗ Incorrect
The
tags field expects a list of strings, so the mock should return an array of strings.4fill in blank
hardFill both blanks to mock a resolver for a post query returning an object with title and likes fields.
GraphQL
const mocks = {
Query: {
post: () => ({ title: [1], likes: [2] })
}
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string for the
likes field.Using a boolean for either field.
✗ Incorrect
The
title field expects a string, so use a string value. The likes field expects a number, so use a number like 42.5fill in blank
hardFill all three blanks to mock a resolver for a comment query returning an object with author, content, and likes fields.
GraphQL
const mocks = {
Query: {
comment: () => ({ author: [1], content: [2], likes: [3] })
}
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a boolean for any field.
Using numbers for string fields.
✗ Incorrect
The
author and content fields expect strings, so use string values. The likes field expects a number, so use a number like 10.