ardeois / graphql-codegen-typescript-mock-data

[GraphQL Codegen Plugin](https://github.com/dotansimha/graphql-code-generator) for building mock data based on the schema.
MIT License
132 stars 47 forks source link

Usage with near-operation-file-preset? #73

Closed leggomuhgreggo closed 2 years ago

leggomuhgreggo commented 2 years ago

Hello! I was wondering if there's any way to use the plugin with near-operation-file-preset plugin, so that the factories are shaped/co-located with respect to individual .graphql documents.

Thanks!

ardeois commented 2 years ago

Hi @leggomuhgreggo I don't know this plugin, but if I understand well, it's splitting the generated operations into separate files

Right now there is no such features, but if there is an interest, we could think about how it could be implemented

leggomuhgreggo commented 2 years ago

I appreciate your being willing to consider!

For a little extra context: I'm hoping there's a way to generate factories so they mirror each operation, individually. That way, when we're testing, the TypeScript definitions don't require extra handling, in order to get the whole-type factory, to work with a partial-type operation query.

(And thanks a bunch for the cool library!)

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

wladimirgramacho commented 1 year ago

@ardeois My team would be very interested in what @leggomuhgreggo proposed:

a way to generate factories so they mirror each operation, individually

Despite the fact that we're not using near-operation-file-preset plugin, we have been looking for a way to auto-generate mocked responses for operations defined on our GQL schema. These mocked responses could then be used in our tests and Storybook.

tatemz commented 1 year ago

I also use the near-operation-file plugin. Adding typescript-mock-data works, but generates a stub function per type per file, so I end up with a ton of duplicate stub functions littered throughout my codebase.

Moreover, I agree with @wladimirgramacho that it'd be awesome to be able to make a stub function for each operation or fragment that I define.