graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

Cannot find name 'InputMaybe'.

Open UchihaYuki opened this issue 2 years ago • 8 comments

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 under package.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.

UchihaYuki avatar Apr 15 '22 07:04 UchihaYuki

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

ardatan avatar Apr 15 '22 07:04 ardatan

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 avatar May 23 '22 08:05 bitttttten

@bitttttten Will there be an official fix?

UchihaYuki avatar Jun 01 '22 13:06 UchihaYuki

@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?

lockykeaney avatar Jun 24 '22 05:06 lockykeaney

@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?

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.

bitttttten avatar Jul 04 '22 11:07 bitttttten

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).

ericbiewener avatar Jul 04 '22 13:07 ericbiewener

I have the same issue. Even if I provide an inputMaybeValue in my yaml file it does not generate the value.

PaulACoroneos avatar Sep 06 '22 18:09 PaulACoroneos

Likewise, the inputMaybeValue config value does nothing for me. Did you manage to resolve it @PaulACoroneos ?

md-dept avatar Sep 16 '22 11:09 md-dept

This is still a bug / issue in graphql-code-generator. It has to be manually added after codegen generates incorrect types.

matthew-dean avatar Nov 07 '22 19:11 matthew-dean

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

Gonzagadavid avatar Dec 01 '22 15:12 Gonzagadavid

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 Screen Shot 2023-02-08 at 2 48 19 PM

Libraries versions @apollo/client: 3.7.7 Screen Shot 2023-02-08 at 2 46 58 PM

seemX17 avatar Feb 08 '23 13:02 seemX17