dotansimha / dotansimha/graphql-code-generator

Input types required filed with default has optional type

Open
#8,129 3 comments 1 reaction 1 assignee Claimed by @eddeee888 View on GitHub
core
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Describe the bug

For 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!
}
```

Generated types are:
```
export type QueryTestArgs = {
a?: InputMaybe;
b?: InputMaybe;
c: Scalars['Int'];
d?: Scalars['Int']; // should not be optional
};
```

### Your Example Website or App

https://codesandbox.io/s/aged-leftpad-6dcvit

### Expected behavior

Generated types are:
```
export type QueryTestArgs = {
a?: InputMaybe;
b?: InputMaybe;
c: Scalars['Int'];
d: Scalars['Int']; // not optional
};
```

### Platform

"graphql": 16.5.0
"@graphql-codegen/cli": "2.9.1"
"@graphql-codegen/typescript": "2.7.2"
"@graphql-codegen/typescript-operations": "2.5.2"

### Codegen Config File
```
schema: schema.graphql
documents: document.graphql
generates:
types.ts:
plugins:
- typescript
- typescript-operations
```

### Additional context

_No response_

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.