dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.85k stars 1.33k forks source link

separate scalars for input types in typescript #2684

Open hayes opened 5 years ago

hayes commented 5 years ago

Is your feature request related to a problem? Please describe.

Currently scalar field on input types use the same types as scalars on normal types. It would be really useful to be able to use a separate map of scalars for input types.

My specific use case is that several of our scalars have normalization built in, so that the types that can be handled by internals of our graphql implementation are looser than those that are received from graphql. More concretely, resolvers can return looser types than those that the resolver will receive in its input arguments.

Some examples of this in our server implementation are:

Describe the solution you'd like

This could probably be implemented with a new inputScalar map in the plugin options that mirrors the scalar map. When present, it would generate a InputScalar map that has the same behavior as the current scalars, and would be used for all scalars in input types. When not specified, only the current Scalars type would be generated and both normal types and input types would use the same scalars type. Describe alternatives you've considered

Additional context

I am happy to provide a PR to implement this, I just wanted to make sure this would be a reasonable change that would be likely to be accepted before spending too much time on it.

n1ru4l commented 5 years ago

related: https://github.com/dotansimha/graphql-code-generator/issues/2588

tslater commented 3 years ago

@hayes, given the amount of time that has passed, I'm curious if/how you've solved this? We're asking ourselves the same questions right now.

hayes commented 3 years ago

For server side stuff we decided writing our schema using a code first approach was better, so I wrote https://giraphql.com/. For client side, I don't remember if this was solved.

tslater commented 3 years ago

@hayes Thanks for letting me know!

cometkim commented 2 years ago

Without adding a new key it can be expanded as string | { input, output }.

I'd like to make a PR for this. Is there any other discussion I should be aware of? @n1ru4l @dotansimha