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
134 stars 46 forks source link

Use spread operator to override values (fixes #114) #131

Closed emab closed 1 year ago

emab commented 1 year ago

This PR implements a new way of generating mock types. Instead of relying on checking overrides for a specific property name, we instead just spread any provided overrides over the key:value object of field to value.

In my opinion this has a couple of benefits:

I've updated all tests, and looking through the snapshots looks positive!

emab commented 1 year ago

Looks good, but I the history a little and we actually did this implementation at first Then we switched to hasOwnProperty to fix a recursive issue #9

Not sure if this issue will cause a problem now we have relationshipsToOmit handling ... ? What do you think?

Yeah that is a good point actually. This method will call the mock data function and then apply overrides. That mock function would then cause a recursive call as it would also call the previous function again, if we don't provide a way to terminate.

I think this would mean the config option to turn on protection for circular relationships would have to be enabled at all times, otherwise it would cause a breakage. I wonder how often people disable it?

stale[bot] commented 1 year 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.