Skip to content

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

Merged
merged 9 commits into from
Apr 3, 2025

Conversation

argvniyx-enroute
Copy link
Contributor

@argvniyx-enroute argvniyx-enroute commented Apr 1, 2025

This addresses #139.

To do so:

  • I added a new type, InputOutputGeneratorOptions, and added it as a ScalarMap option
  • I updated Options to have a generatorMode field, which is either input or output
  • I passed options with input or output to generateMockValue depending on whether we're visiting a FieldDefinition or an InputObjectTypeDefinition node. We do this and the above because ...
  • ...we have to update getGeneratorDefinition with the mode to be able to know how to pluck out the appropriate generator when value is an InputOutputGeneratorOptions.

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.
Copy link
Contributor Author

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
@ardeois ardeois self-requested a review April 2, 2025 19:35
@ardeois ardeois self-assigned this Apr 2, 2025
@ardeois ardeois added the minor Increment the minor version when merged label Apr 2, 2025
Copy link
Owner

@ardeois ardeois left a 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!
@argvniyx-enroute
Copy link
Contributor Author

@ardeois Nice! Thank you for taking a look! Seems like actions/cache@v2 was deprecated last February. I think the API remained unchanged, so I updated the version here just to see if workflows pass muster, but I can break that off into its own thing, if you prefer.

@ardeois ardeois merged commit 8431fbc into ardeois:main Apr 3, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants