使用LLMs和@generateMock进行大规模GraphQL数据模拟

How Airbnb combines GraphQL infra, product context, and LLMs to generate and maintain convincing, type-safe mock data using a new directive.

Airbnb 如何结合 GraphQL 基础设施、产品上下文和 LLM 通过新的指令生成和维护令人信服的类型安全模拟数据。

Press enter or click to view image in full size

按回车或点击以查看完整图像

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.

为 GraphQL 生成有效且真实的模拟数据以进行测试和原型设计多年来一直是行业中的一个持续挑战。模拟数据的编写和维护非常繁琐,改善这一过程的尝试,例如随机值生成和字段级别的存根,因缺乏必要的领域上下文而未能使测试数据真实且有意义。花在这项手动工作上的时间最终会削弱大多数工程师希望专注的内容:构建功能。

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. This approach eliminates the need for engineers to manually write and maintain mocks as queries evolve, freeing up time to focus on building the product.

在这篇文章中,我们将探讨如何通过结合 GraphQL 验证、丰富的产品和架构上下文以及 LLM 来重新构想 Airbnb 的 GraphQL 数据模拟,以生成和维护令人信服的、类型安全的模拟数据。我们的解决方案围绕一个简单的新 GraphQL 客户端指令——@generateMock——展开,工程师可以将其添加到任何操作、片段或字段中。这种方法消除了工程师在查询演变时手动编写和维护模拟的需要,从而腾出时间专注于构建产品。

Key challenges

主要挑战

After meeting with Airbnb product engineers and analyzing results from internal surveys, we distilled the most common pain points around GraphQL mocking down into three key challenges:

在与Airbnb产品工程师会面并分析内部调查结果后,我们将围绕GraphQL模拟的最常见痛点提炼为三个主要挑战:

  1. Manually creating mocks is time consuming. GraphQL queries can grow to hundreds of lines, and hand-crafting mock response ...
开通本站会员,查看完整译文。

trang chủ - Wiki
Copyright © 2011-2025 iteam. Current version is 2.147.1. UTC+08:00, 2025-11-02 04:07
浙ICP备14020137号-1 $bản đồ khách truy cập$