0
0
GraphQLquery~5 mins

Mocking resolvers in GraphQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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: <br>{ 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
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
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
Which GraphQL server library has built-in mocking support?
AApollo Server
BExpress
CReact
DVue
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
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.