graphql-codegen-typescript-mock-data
graphql-codegen-typescript-mock-data copied to clipboard
Add parameter to be able to filter type fields by passing a query document
I've been using this library and I think it's amazing, so thank you for your contribution.
I've been having performance problems using it in my project since we have gigantic schemas with lots of attribute levels which make it impossible for us to use mock functions because it consumes the whole heap memory while we run tests due to it generating a lot of unnecessary data.
We've been dealing with that using the relationshipsToOmit
parameter, but it's often too verbose and I've thought about a potential solution that I want to present.
What I suggest is to add a new parameter to the top level aQuery
function which should be a graphql query DocumentNode
, which would be used to prevent the mock function from generating unnecessary objects if those fields are not present in that query response.
I've opened a PR with a potential implementation (of course, open to any change suggestion if you find this could be a nice addition to the plugin but can be done in a better/more suitable way): https://github.com/ardeois/graphql-codegen-typescript-mock-data/pull/98
Previously I tried to generate new functions for each query using the documents parameter of the plugin
function but I couldn't find a way of doing that, maybe there is one and it'd be better that way, but that'd be generating new mock functions for each query and I'm not sure if I prefer that to the document parameter solution.
Thank you!