I use codegen to fetch and generate GraphQL schema in client Nextjs application. When I generate it, a lot of [input]
and [output]
types (?) are added to Scalar
types, for example:
id: Scalars['Int']['input'];
approved?: InputMaybe<Scalars['Boolean']['output']>;
After fetching the schema typecheck fails in some places, mostly for ids, e.g.
Argument of type 'number' is not assignable to parameter of type '{ input: any; output: any; }'
If I remove all [output]
and [input]
types, typecheck doesn't fail.
So, why are [output]
and [input]
needed in schema and why does typecheck fails with them but doesn't without?
Basically a Scalar can have a different type if it is used as an input or an output. That's why this change was introduced. This is a breaking change as it requires that each time you use Scalar['xxx'] as type to append either an ['input'] or ['output'] depending on the variable usage.
You can read more about that and the motivation there : https://github.com/dotansimha/graphql-code-generator/pull/9375