Airbnb Revolutionizes GraphQL Mocking with LLMs and @generateMock
Airbnb has tackled the long-standing challenge of creating and maintaining realistic mock data for GraphQL development. Their innovative solution leverages Large Language Models (LLMs) and a new GraphQL client directive, @generateMock, to automate the process, significantly speeding up development cycles and improving data accuracy.
Key Takeaways
- Airbnb’s
@generateMockdirective uses LLMs to generate type-safe, realistic mock GraphQL data. - This approach eliminates tedious manual mock creation and maintenance, freeing up engineering time.
- The system integrates LLMs with GraphQL schema and product context for highly relevant mock data.
- A companion directive,
@respondWithMock, allows client developers to work ahead of backend implementation.
The Pain of Manual Mocking
Creating mock data for GraphQL has historically been a time-consuming and error-prone process. Engineers often spend hours manually crafting JSON responses or instantiating types, only for these mocks to quickly fall out of sync with evolving queries and schemas. This manual effort detracts from core feature development and makes prototyping and demos difficult, especially when the backend is not yet complete.
Introducing @generateMock: Schema + Context + LLMs
Airbnb’s solution centers around the @generateMock directive. By adding this to GraphQL operations, fragments, or fields, engineers can automatically generate mock data. The directive can be customized with arguments like id, hints (e.g., “Include travel entries for Barcelona”), and designURL, which feeds crucial product and design context to the LLM.
The process involves Airbnb’s internal tool, Niobe, which collects context including the GraphQL schema subset, documentation, design snapshots, and hints. This information is then fed into a fine-tuned Gemini 2.5 Pro model. The LLM generates mock JSON, which is then validated against the GraphQL schema using the graphql-js package. A retry mechanism ensures that any errors are fed back to the LLM for self-correction, guaranteeing type-safe and valid mock data.
Unblocking Development with @respondWithMock
Complementing @generateMock is @respondWithMock. This directive allows client developers to use locally generated mock data instead of waiting for server implementations. It can be applied to entire queries or individual fields, enabling hybrid responses that combine real and mocked data. This significantly accelerates client-side development by removing backend dependencies.
Keeping Mocks Synchronized
A key innovation is how Airbnb ensures mocks stay up-to-date. Niobe embeds version hashes of the GraphQL document and directive arguments within the generated mock files. On subsequent code generation runs, Niobe compares these hashes. If changes are detected, it intelligently updates the mock by providing the LLM with the diff and the existing mock data, minimizing unnecessary alterations and preserving manual tweaks.
An automated check in the client codebase verifies that mock hashes are current upon code submission, guaranteeing that mocks evolve alongside queries without manual intervention.
Why This Matters
This approach by Airbnb represents a significant leap forward in developer tooling. By integrating LLMs directly into the GraphQL workflow, they’ve not only solved the tedious problem of mock data generation but have also enhanced the realism and accuracy of that data. The ability for client developers to work independently of backend progress, coupled with the assurance that mocks remain synchronized, is a powerful productivity booster. This strategy is a prime example of leveraging AI to streamline complex engineering challenges, directly impacting feature velocity and product quality.
Looking Ahead
Airbnb has already seen widespread adoption, with over 700 mocks generated and merged across platforms in just a few months. Plans are in motion to extend this capability to backend services. This initiative highlights how sophisticated tooling, powered by AI, can fundamentally reshape development practices.
This article was based on reporting from The Airbnb Tech Blog. A huge shoutout to their team for the original coverage.



