Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a mocking resolver in GraphQL?
A mocking resolver is a fake function that returns sample data instead of real data, used to test or develop GraphQL APIs without a real backend.
Click to reveal answer
beginner
Why use mocking resolvers during GraphQL API development?
They let you build and test the API schema quickly without needing a real database or backend, helping frontend and backend teams work in parallel.
Click to reveal answer
intermediate
How do you define a simple mocking resolver for a 'User' type with a 'name' field?
You write a resolver function that returns a fixed or random name string when the 'name' field is requested, for example: { User: { name: () => 'Alice' } }
Click to reveal answer
intermediate
What is the benefit of using libraries like Apollo Server's mocking feature?
They automatically generate fake data for your schema types, saving time and reducing manual work when mocking resolvers.
Click to reveal answer
advanced
Can mocking resolvers simulate errors or delays? Why is this useful?
Yes, mocking resolvers can simulate errors or delays to test how your app handles failures or slow responses, improving robustness.
Click to reveal answer
What does a mocking resolver return in GraphQL?
AReal data from a database
BNothing
CSample or fake data
DAn error always
✗ Incorrect
Mocking resolvers return sample or fake data to simulate real responses.
Which of these is a reason to use mocking resolvers?
ATo encrypt data
BTo slow down API responses
CTo delete real data
DTo speed up frontend development
✗ Incorrect
Mocking resolvers help frontend developers work without waiting for backend completion.
How can you simulate a delay in a mocking resolver?
ABy using setTimeout or async delay before returning data
BBy returning data immediately
CBy throwing an error
DBy returning null
✗ Incorrect
Using a delay function like setTimeout simulates slow responses.
Which GraphQL server library has built-in mocking support?
AApollo Server
BExpress
CReact
DVue
✗ Incorrect
Apollo Server includes features to easily mock GraphQL schemas.
What is a key limitation of mocking resolvers?
AThey cannot return any data
BThey do not connect to real databases
CThey always cause errors
DThey slow down the server
✗ Incorrect
Mocking resolvers do not fetch real data, so they can't test real backend logic.
Explain what mocking resolvers are and why they are useful in GraphQL development.
Think about how you can test an API without a real database.
You got /3 concepts.
Describe how you would create a mocking resolver for a GraphQL type with multiple fields.
Consider how each field needs its own fake data function.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of mocking resolvers in GraphQL?
easy
A. To simulate API responses without needing real data
B. To optimize database queries for faster performance
C. To secure the API by hiding sensitive data
D. To automatically generate GraphQL schemas
Solution
Step 1: Understand mocking resolvers
Mocking resolvers are used to create fake data responses for GraphQL fields without connecting to a real database.
Step 2: Identify the main purpose
This helps frontend developers test and build UI without waiting for backend data.
Final Answer:
To simulate API responses without needing real data -> Option A
Quick Check:
Mocking = Simulate data [OK]
Hint: Mocks simulate data, not optimize or secure APIs [OK]
Common Mistakes:
Confusing mocking with database optimization
Thinking mocks secure the API
Assuming mocks generate schemas automatically
2. Which of the following is the correct way to define a mock resolver for a GraphQL field user that returns a fixed name?
Mock resolvers are objects where the type (e.g., Query) maps to functions returning objects matching the schema.
Step 2: Check the correct syntax
The user field should be a function returning an object with a name property, so const mocks = { Query: { user: () => ({ name: 'Alice' }) } }; is correct.
B. Missing return statement inside the user resolver function
C. Resolver should return a string, not an object
D. Incorrect key name; should be 'User' instead of 'user'
Solution
Step 1: Check function body syntax
The user resolver uses curly braces but does not return an object explicitly.
Step 2: Understand JavaScript function return rules
Without a return statement, the function returns undefined, causing the mock to fail.
Final Answer:
Missing return statement inside the user resolver function -> Option B
Quick Check:
Functions with braces need explicit return [OK]
Hint: Use return or parentheses for object in arrow functions [OK]
Common Mistakes:
Assuming implicit return with braces
Confusing type names case sensitivity
Expecting string return instead of object
5. You want to mock a GraphQL resolver for a product field that returns a list of products with id and price. Which mock resolver correctly returns two products with ids 1 and 2 and prices 10.5 and 20.0 respectively?