-
Notifications
You must be signed in to change notification settings - Fork 135
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
[Enhancement] Provide a map of scalars and their TypeScript types. #419
Comments
@deftomat this is a really cool idea, would you be interested in trying out to create a PR for it? |
Sure, I will! |
I would be very keen to have this :) |
@deftomat I also would like this and could work on a PR for it, but I wonder why your example is JavaScript. As far as I can tell, graphql-code-generator's configuration is YAML. Do you have an example of how this might be bridged between JS and YAML? Because otherwise a simple list in the |
@ardatan since you're a graphql-code-generator contributor as well. How would this best be implemented? |
Its in JS because we are using it in our custom Webpack plugin. You can trigger the generator through JS API. |
While digging through the graphql-code-generator source I found that dotansimha/graphql-code-generator#2418 Test here shows how to use it: So it seems this should work with something like This functionality is undocumented from what I can see, besides looking at these two PRs.
export * from 'graphql-scalars/type-map';
export const OtherScalar: 'string';
export const Date: 'Date';
export const PositiveInt: 'number';
export const EmailAddress: 'string';
export const JSONObject: 'Record<string, any>';
... |
@andreialecu would you be willing to PR the docs on GraphQL Codegen's website and also maybe add a section to the README here with examples of people who wants to use both packages together? cc @tvvignesh as he will soon create a docs website for GraphQL Scalars as well, based on the current readme |
It would be nice if the corresponding typescript type is also added in the documentation in the subpage for each scalar type. |
We found this package and it has all the scalars which we need 🥳 . Also, we are using
graphql-code-generator
to generate types for our resolvers.The problem is, that this generator don't know nothing about these scalars. So, every scalar is typed as
any
. To fix this, one can provide a hint to generator like scalar Date will actually be an instance ofDate
or scalar PositiveInt isnumber
.So, I was wondering if it is possible to export a map of scalar names and their actual TypeScript types as strings. See scalars section in https://graphql-code-generator.com/docs/plugins/typescript-resolvers.
This would allows us to pass this information into generator and keep in up to date with scalars provided by this package.
EXAMPLE:
The text was updated successfully, but these errors were encountered: