• How Airbnb combines GraphQL infra, product context, and LLMs to generate and maintain convincing, type-safe mock data using a new directive. • Introduction Producing valid and realistic mock data for testing and prototyping with GraphQL has been a persistent challenge across the industry for years. • Mock data is tedious to write and maintain, and attempts to improve the process, such as random value generation and field-level stubbing, fall short because they lack essential domain context to make test data realistic and meaningful. • The time spent on this manual work ultimately takes away from what most engineers would like to focus on: building features. • In this post, we’ll explore how we’ve reimagined mocking GraphQL data at Airbnb by combining GraphQL validation, rich product and schema context, and LLMs to generate and maintain convincing, type-safe mock data. • Our solution centers around a simple new GraphQL client directive - @generateMock - that engineers can add to any operation, fragment, or field.

Article Summaries:

  • Airbnb has introduced a new GraphQL client directive, @generateMock, that leverages large language models (LLMs) and rich schema context to automatically produce type‑safe, realistic mock data. The directive can be added to any query, fragment, or field, eliminating the need for engineers to manually craft and maintain mock responses. By integrating GraphQL validation with product‑specific context, the system keeps mocks in sync with evolving queries and reduces the time spent on prototyping and testing. The solution addresses common pain points-time‑consuming manual mock creation, difficulty in early‑stage UI testing, and drift between mocks and schema-allowing teams to focus more on feature development.

Sources: