Resolvers input subfields with defaults resolve into nullable
Describe the bug
Resolvers input subfields with defaults resolve into nullable
Your Example Website or App
https://stackblitz.com/edit/node-ve8vhp?file=schema.graphql
Steps to Reproduce the Bug or Issue
typescript-resolvers:
overwrite: true
schema:
- schema.graphql
documents: null
generates:
generated-types.ts:
plugins:
- 'typescript'
- 'typescript-resolvers'
and this is the schema:
type User {
name: String
}
input GetUserArgs {
offset: Int = 0
}
type Query {
getUsers(getUsersArgs: GetUserArgs): [User]
}
Expected behavior
for offset arg to be wrapped with RequireFields in the. resolver type
Screenshots or Videos
No response
Platform
- OS: macOS
- NodeJS: 16.14.2
-
graphqlversion: 16.0.1 - "@graphql-codegen/cli": "2.9.0"
- "@graphql-codegen/typescript": "2.7.2"
- "@graphql-codegen/typescript-resolvers": "2.7.2"
Codegen Config File
No response
Additional context
No response
The reason why the offset is nullable.
Kind is import from graphql

weird. it's undefined only when I debug it.
the real reason:
const addOptionalSign =
!this.config.avoidOptionals.inputValue &&
(originalFieldNode.type.kind !== Kind.NON_NULL_TYPE ||
(!this.config.avoidOptionals.defaultValue && node.defaultValue !== undefined));
// node.defaultValue == { kind: 'IntValue', value: '0' }
https://github.com/dotansimha/graphql-code-generator/blob/master/packages/plugins/typescript/typescript/src/visitor.ts#L297
seems that it's the expected behavior
related: #5113
generates:
types.ts:
plugins:
- typescript
config:
avoidOptionals:
defaultValue: true
set avoidOptionals.defaultValue to true
If user pass null as argument explicitly, it can be null, so it works as it should be. See #8129