dotansimha / dotansimha/graphql-code-generator

separate scalars for input types in typescript

Open
#2,684 5 comments 14 reactions 0 assignees View on GitHub
kind/enhancement plugins
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

**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:
* for ID fields, internally everything is coerced to a string, so an input ID field will always be string, but a resolver for an ID field can return a string, number, or BigInt.
* our custom DateTime scalar will always be a Date scalar in an input, but could be either a iso-date string, or a Date object when returned from a resolver.

**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**

* always generating an InputScalars map
* just providing the looser types for scalras, and using type asserts or coercions on inputs in resolvers.
* Writing a custom plugin

**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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.