dotansimha / dotansimha/graphql-code-generator-community
typescript-graphql-request incorrect nullable variable type for required input field with default
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
### 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;
b?: InputMaybe;
c: Scalars['Int'];
d?: Scalars['Int'];
};
```
While types used in sdk is not:
```
export type TestQueryVariables = Exact<{
a?: InputMaybe;
b?: InputMaybe;
c: Scalars['Int'];
d?: InputMaybe; // 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;
b?: InputMaybe;
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
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.