GraphQL Mock Factories in Vue 3: A Style Guide for Type-Safe Tests 0 ▲ alexop.dev 54 minutes ago · 8 min read1660 words · Tech · hide Writing mock data for GraphQL tests gets old fast. You copy a response from the network tab into a mockCountry object. Three weeks later someone adds a field to the fragment. The test still passes, because the mock is typed as any somewhere along the way. Production shows undefined. In Part 3 every component got its own fragment, and fragment masking made sure nobody else can read that data. Really nice for the app. But it raises two questions for tests. How do you hand a masked prop to a component? And where does the data come from? My answer is the mock factory pattern. Codegen writes one function per schema type, like aCountry(), and each function returns a complete object. You override the two fields your test cares about and ignore the rest. This post is the style guide I follow. First the setup, then eight rules. Each rule has a ❌ and a ✅, and I ran every snippet against the demo app of this series. graph LR S[GraphQL schema] -->|codegen| F["aCountry()"] F -->|"fragmentData()"|… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town