-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat: add scalars
config option for custom GraphQL [scalar -> casual] mappings
#21
Conversation
There is a minorr issue with stringification that tests didn't catch. Will update the PR. Update: Done |
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.
Thanks @3nvi for your contribution, great idea !
I have few comments before I approve
tests/typescript-mock-data.spec.ts
Outdated
|
||
const emailRegex = /(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/; | ||
expect(result).toBeDefined(); | ||
expect(emailRegex.test(result as string)).toBeTruthy(); |
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.
Our test suite force casual
to return a predictable result, so I think you can check the result
string directly instead of using a regex
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.
oh cool, didn't dig in too much and with a quick pass, I wasn't able to find something. I'll make sure to update
Background
Some apps use custom scalar for date-related stuff. This caused issues with the way
graphql-codegen-typescript-mock-data
handles autogenerated data, since a "random string" (the current default), may not always be what you need.This PR allows you to define mapping from your custom scalars to a casual embedded generator, allowing you to specify exactly how your scalar's autogenerated value will be populated
Closes #20
Caveats
To make configuration simple, a few "shortcuts" were taken. Namely:
casual
key (function or string) as a valid autogenerated value in order to align with the rest of the library