graphql-code-generator
graphql-code-generator copied to clipboard
Cannot find name 'InputMaybe'.
Issue workflow progress
Progress of the issue based on the Contributor Workflow
- [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
Make sure to fork this template and run
yarn generate
in the terminal. Please make sure the Codegen and plugins version underpackage.json
matches yours. - [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
my gql:
getArticleHeads(
page: Int = 0
): getArticleHeadsResponse
the generated typescript:
export type GetArticleHeadsQueryVariables = Exact<{
page?: InputMaybe<Scalars['Int']>;
}>;
My tsc version is 4.6.3.
Please follow our issue template and create a reproduction on CodeSandbox or StackBlitz using our template as described there; https://github.com/dotansimha/graphql-code-generator/blob/master/.github/ISSUE_TEMPLATE/bug_report.md
You can temporarily fix this by adding the definition into your types file.
type InputMaybe<T> = Maybe<T>
For a create-react-app project, that file is react-app-env.d.ts
.
@bitttttten Will there be an official fix?
@bitttttten the temporary fix isn't working for me. Is there a way I can get it added into the type generation step? What is the difference between InputMaybe
and Maybe
?
@bitttttten the temporary fix isn't working for me. Is there a way I can get it added into the type generation step? What is the difference between
InputMaybe
andMaybe
?
I don't know! There could be differences, as in perhaps InputMaybe
returns a different falsey value than Maybe
, but I could not say if that is true here or not. All I know is that for my use case, it worked to treat them as identical.
@bitttttten Will there be an official fix?
I am not so sure, I don't maintain this library.
This appears to be an undocumented config option for the typescript-operations
package. By explicitly including that config option (e.g. inputMaybe: "Maybe<T>"
or inputMaybe: "T | null"
), the type will be generated. Obviously, it should be generated with a default anyway (probably the same default as Maybe
), and the option to omit it altogether in favor of just using Maybe
should ideally be added in order to reduce an additional utility type that for most people will be equivalent to Maybe
.
For those asking about what the type of InputMaybe
should be, the answer is whatever your GraphQL server supports for variable values. Most likely it is T | null | undefined
(although undefined
is handled by the ?
annotation on the field key itself, leaving Maybe
sufficient).
I have the same issue. Even if I provide an inputMaybeValue in my yaml file it does not generate the value.
Likewise, the inputMaybeValue
config value does nothing for me. Did you manage to resolve it @PaulACoroneos ?
This is still a bug / issue in graphql-code-generator
. It has to be manually added after codegen generates incorrect types.
Likewise, the
inputMaybeValue
config value does nothing for me. Did you manage to resolve it @PaulACoroneos ?
I had the same problem, as a temporary solution, I used add to insert the InputMaybe
type in the type generation step
This issue got fixed for me by upgrading the libraries with the versions below. I cannot pinpoint which one has affected this change but I can see that this has been fixed. I also see that InputMaybe is present as a type now in the generated file and no longer need to explicit add it to my custom types file 👍
Screenshot of generated graphql
Libraries versions
@apollo/client: 3.7.7