-
Notifications
You must be signed in to change notification settings - Fork 53
feature(scalars): support distinction between input and output generator configs #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(scalars): support distinction between input and output generator configs #182
Conversation
just trying to group them in preparation for adding more specs with the new config options for scalars
… type So, when we have a normal FieldDefinition, we want to assume we want to use the output generator. When we visit the InputObjectTypeDefinition and call generateMockValue on its children, we can assume we want the input generator. We keep the other types of generator config types around for backwards compatibility. It could be a nice refactoring opportunity to map the existing config types to the input/output type, instead of what we do in this commit, which is check/switch on `value` in `getGeneratorDefinition`, but I wanted to prove to myself that we could generate distinct mocks.
Tests were failing. Also, assert the last return is a GeneratorDefinition. I have to clean this up, but essentially TS is being unable to narrow this down. An InputOutputGeneratorOptions is a one level deep object with GeneratorOptions, so the recursive call will inevitably trickle down to a base case where we _do not_ have an InputOutputGeneratorOptions.
I.e. the very basic display of what this PR is meant to change. Follow up commits will cover the faker side of things, and possibly other config permutations.
tests/scalars/spec.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are way easier to review if you hide whitespace
…atorDefinition with that Hopefully this reads a bit better and while it isn't a discriminated union (and while there's room for improvement still), it's at least not a type assertion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good !
Thank you for the contribution and to have thought about documentation and unit tests 👍
Seems v2 was deprecated on Feb 1st (!) From a quick skim, seems the config remained unchanged, though. Worth a shot!
@ardeois Nice! Thank you for taking a look! Seems like |
This addresses #139.
To do so:
InputOutputGeneratorOptions
, and added it as aScalarMap
optionOptions
to have ageneratorMode
field, which is eitherinput
oroutput
input
oroutput
togenerateMockValue
depending on whether we're visiting aFieldDefinition
or anInputObjectTypeDefinition
node. We do this and the above because ...getGeneratorDefinition
with the mode to be able to know how to pluck out the appropriate generator whenvalue
is anInputOutputGeneratorOptions
.