Open ericbf opened 3 weeks ago
Hi @ericbf
inputMaybeValue can be used to add undefined
like this:
const config: CodegenConfig = {
// ...
generates: {
'path/to/file.ts': {
plugins: ['typescript'],
config: {
inputMaybeValue: 'T | null | undefined' // Add undefined to inputMaybeValue
}
}
}
}
I'll close this issue, but if this doesn't answer your question, please @ me and let me know to re-open 🙂
@eddeee888 I should have specified I’m using the client preset, and this option doesn’t work when using the client preset. I’ve updated the issue description accordingly.
Which packages are impacted by your issue?
@graphql-codegen/add @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations
Describe the bug
When using the typescript compiler option
"exactOptionalPropertyTypes": true
, the fact thatInputMaybe<T>
does not explicitly includeundefined
makes it hard to use as you can no longer pass optional values to query variables.InputMaybe
should explicitly include undefined to allow passing optional values to optional variables in queries.Your Example Website or App
https://stackblitz.com/edit/github-txjvxl?file=query.ts
Steps to Reproduce the Bug or Issue
npx tsc
to see it)Expected behavior
No compilation error. Since input variable
id
is optional, it should allow an optional value to be set to it.Screenshots or Videos
No response
Platform
graphql
version: ^16.2.0@graphql-codegen/add
version: ^5.0.0@graphql-codegen/cli
version: ^4.0.1@graphql-codegen/typescript
version: ^4.0.1@graphql-codegen/typescript-operations
version: ^4.0.1Codegen Config File
Additional context
There’s an option to customize the
InputMaybe
type, but when using some presents, like the client preset, the option is not available. I feel codegen should work in a way compatible with at least this relatively non-niche typescript config.