graphql-code-generator
graphql-code-generator copied to clipboard
`InputMaybe` should explicitly include `undefined`
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 that InputMaybe<T>
does not explicitly include undefined
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
- Open repro
- Look at compilation error (if it doesn't show in the editor, run
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
- OS: macOS
- NodeJS: 18.20.3
-
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.1
Codegen Config File
import { CodegenConfig } from "@graphql-codegen/cli";
const config: CodegenConfig = {
schema: "schema.graphql",
documents: "document.graphql",
generates: {
"types.ts": { plugins: ["typescript", "typescript-operations"] },
},
};
export default config;
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.