0
0
GraphQLquery~10 mins

Mocking resolvers 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 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'
Atrue
B12345
C"Hello, world!"
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a number or boolean instead of a string.
Not using quotes around the string value.
2fill in blank
medium

Complete 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'
Anull
B123
Cfalse
D"Alice"
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a number or boolean instead of a string.
Returning null which may cause errors if not handled.
3fill in blank
hard

Fix 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'
A["graphql", "mock", "resolver"]
B"graphql, mock, resolver"
Cnull
D123
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.
4fill in blank
hard

Fill 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'
A"GraphQL Basics"
B42
C"100"
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string for the likes field.
Using a boolean for either field.
5fill in blank
hard

Fill 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'
A"Bob"
B"Nice post!"
C10
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using a boolean for any field.
Using numbers for string fields.