graphql-code-generator
graphql-code-generator copied to clipboard
typescript-graphql-request incorrect nullable variable type for required input field with default
Describe the bug
For a schema:
type Query {
test(
a: Int # can be null
b: Int = 1 # can be null if user pass null explicitly
c: Int! # can't be null
d: Int! = 1 # can't be null
): Int!
}
And query:
query test ($a: Int, $b: Int, $c: Int!, $d: Int) {
test(a: $a, b: $b, c: $c, d: $d)
}
Generated QueryTestArgs is correct:
export type QueryTestArgs = {
a?: InputMaybe<Scalars['Int']>;
b?: InputMaybe<Scalars['Int']>;
c: Scalars['Int'];
d?: Scalars['Int'];
};
While types used in sdk is not:
export type TestQueryVariables = Exact<{
a?: InputMaybe<Scalars['Int']>;
b?: InputMaybe<Scalars['Int']>;
c: Scalars['Int'];
d?: InputMaybe<Scalars['Int']>; // this will allow to pass null that will be rejected by api
}>;
Your Example Website or App
https://codesandbox.io/s/cranky-kowalevski-98l6up
Expected behavior
export type TestQueryVariables = Exact<{
a?: InputMaybe<Scalars['Int']>;
b?: InputMaybe<Scalars['Int']>;
c: Scalars['Int'];
d?: Scalars['Int'] // we can allow to omit it which will be replaced by default, but it's not allowed to pass null
}>;
Platform
"graphql": 16.5.0
"@graphql-codegen/cli": "2.9.1"
"@graphql-codegen/typescript": "2.7.2"
"@graphql-codegen/typescript-operations": "2.5.2"
"@graphql-codegen/typescript-graphql-request": "4.5.2"
Codegen Config File
schema: schema.graphql
documents: document.graphql
generates:
types.ts:
plugins:
- typescript
- typescript-operations
- typescript-graphql-request