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

Property 'enter' does not exist on type '{ readonly enter?: ASTVisitFn<NameNode> ...

Open moltar opened this issue 3 years ago โ€ข 15 comments

Describe the bug

Getting the following build errors with TS:

node_modules/@graphql-codegen/plugin-helpers/oldVisit.d.ts:5:75 - error TS2339: Property 'enter' does not exist on type '{ readonly enter?: ASTVisitFn<NameNode> | undefined; readonly leave: ASTReducerFn<NameNode, unknown>; } | { readonly enter?: ASTVisitFn<DocumentNode> | undefined; readonly leave: ASTReducerFn<...>; } | ... 41 more ... | undefined'.

5     enter?: Partial<Record<keyof NewVisitor, NewVisitor[keyof NewVisitor]['enter']>>;
                                                                            ~~~~~~~

node_modules/@graphql-codegen/plugin-helpers/oldVisit.d.ts:6:75 - error TS2339: Property 'leave' does not exist on type '{ readonly enter?: ASTVisitFn<NameNode> | undefined; readonly leave: ASTReducerFn<NameNode, unknown>; } | { readonly enter?: ASTVisitFn<DocumentNode> | undefined; readonly leave: ASTReducerFn<...>; } | ... 41 more ... | undefined'.

6     leave?: Partial<Record<keyof NewVisitor, NewVisitor[keyof NewVisitor]['leave']>>;

To Reproduce

Use together:

    "@graphql-codegen/plugin-helpers": "^2.4.1",
    "graphql": "^16.3.0"

Then just importing it will trigger the bug:

import type { Types } from '@graphql-codegen/plugin-helpers';
  1. My GraphQL schema:
N/A
  1. My GraphQL operations:
N/A
  1. My codegen.yml config file:
N/A

Expected behavior

Not produce build errors.

Environment:

  • OS: macOS
  • @graphql-codegen/plugin-helpers: 2.4.1
  • NodeJS: v14.17.6

Additional context

N/A

moltar avatar Feb 14 '22 09:02 moltar

Hi @moltar

Thank you for your report!

Do you have any version of graphql installed globally? If not, could you send here the portion of your lockfile (yarn or npm) that shows the graphql version resolution?

Thank you

charlypoly avatar Feb 14 '22 10:02 charlypoly

Weird, nuked node_modules, and re-installed. Fixed the problem. ๐Ÿคท๐Ÿผ

moltar avatar Feb 14 '22 10:02 moltar

Do you have any version of graphql installed globally?

Good question.

Seems like no?

โฏ npm ls -g graphql
/Users/xyz/.fnm/node-versions/v14.17.6/installation/lib
โ””โ”€โ”€ (empty)

moltar avatar Feb 14 '22 10:02 moltar

If not, could you send here the portion of your lockfile (yarn or npm) that shows the graphql version resolution?

Will do, if I can repro the issue again.

moltar avatar Feb 14 '22 10:02 moltar

Most likely multiple versions of graphql were present in node_modules/ ๐Ÿ‘€

Will do, if I can repro the issue again.

Okay!

charlypoly avatar Feb 14 '22 10:02 charlypoly

Ok, this is reproducible. Happens in GitHub Actions.

https://github.com/moltar/projen-graphql-codegen

moltar avatar Feb 14 '22 10:02 moltar

https://github.com/moltar/projen-graphql-codegen/blob/e46a16399478a82f2b8da113419778b0789add86/yarn.lock#L2256-L2259

moltar avatar Feb 14 '22 10:02 moltar

โฏ ag --json -r '"graphql"' node_modules

node_modules/@graphql-codegen/plugin-helpers/package.json
6:    "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"

node_modules/graphql/package.json
2:  "name": "graphql",
30:    "graphql",

node_modules/@graphql-tools/utils/package.json
7:    "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"

moltar avatar Feb 14 '22 10:02 moltar

This GH Action fails:

https://github.com/moltar/projen-graphql-codegen/blob/9a0ccf85836dc8dc1282955363acd106a40b07fd/.github/workflows/release.yml#L18-L39

With:

๐Ÿ‘พ release ยป build ยป default | ts-node --project tsconfig.dev.json .projenrc.ts
yarn install v1.22.17
[1/4] Resolving packages...
success Already up-to-date.
Done in 1.89s.
๐Ÿ‘พ release ยป build ยป compile | tsc --build
node_modules/@graphql-codegen/plugin-helpers/oldVisit.d.ts(5,75): error TS2339: Property 'enter' does not exist on type '{ readonly enter?: ASTVisitFn<NameNode> | undefined; readonly leave: ASTReducerFn<NameNode, unknown>; } | { readonly enter?: ASTVisitFn<DocumentNode> | undefined; readonly leave: ASTReducerFn<...>; } | ... 41 more ... | undefined'.
node_modules/@graphql-codegen/plugin-helpers/oldVisit.d.ts(6,75): error TS2339: Property 'leave' does not exist on type '{ readonly enter?: ASTVisitFn<NameNode> | undefined; readonly leave: ASTReducerFn<NameNode, unknown>; } | { readonly enter?: ASTVisitFn<DocumentNode> | undefined; readonly leave: ASTReducerFn<...>; } | ... 41 more ... | undefined'.
๐Ÿ‘พ Task "release ยป build ยป compile" failed when executing "tsc --build" (cwd: /home/runner/work/projen-graphql-codegen/projen-graphql-codegen)
Error: Process completed with exit code 1.

moltar avatar Feb 14 '22 10:02 moltar

Switched to using NPM - same issue :/

moltar avatar Feb 14 '22 10:02 moltar

Pinning to [email protected] seems to have worked ๐Ÿคท๐Ÿผ

moltar avatar Feb 14 '22 10:02 moltar

I'm having the same issue, I'm trying to use "@graphql-codegen/cli": "^2.6.2" with "graphql": "^16.5.0".

I made sure that "graphql": "^16.5.0" is the only version installed and that there is no global graphql version. I also tried nuking the node_modules folder, but nothing helped.

It seems that there is a type mismatch between @graphql-codegen and graphql@16. The latest @graphql-codegen version should support graphql v16, right?

sandromartis avatar May 16 '22 15:05 sandromartis

Same issue

"@graphql-codegen/cli": "^2.6.2",
"graphql": "^16.3.0",

Extremely annoying. We must keep the codegen file in our repo commented out except for while its in use, else our typechecks will fail. skipLibCheck will fix it, but isnt something we want repo wide.

Any workarounds?

Crizzooo avatar May 19 '22 20:05 Crizzooo

@sandromartis

The latest @graphql-codegen version should support graphql v16, right?

Honestly, I am not sure about that. The dependency @graphql-codegen/visitor-plugin-common which is included in pretty much all plugins has two other dependencies that cause peer dependency warnings in Yarn:

@graphql-codegen/visitor-plugin-common > @graphql-tools/[email protected]" has incorrect peer dependency "graphql@^14.0.0 || ^15.0.0".
@graphql-codegen/visitor-plugin-common > [email protected]" has incorrect peer dependency "graphql@^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".

Sadly I believe sticking to 15.8.0 is the safest option for now, but then again, I am not a contributor to this repo!

mvarendorff avatar Jun 13 '22 09:06 mvarendorff

This error appeared on my project after importing accidentally this import.

import {EXACT_SIGNATURE} from "@graphql-codegen/typescript";

After deleting this the error was gone.

StanzaArrow avatar Jul 14 '22 12:07 StanzaArrow

Weird, nuked node_modules, and re-installed. Fixed the problem. ๐Ÿคท๐Ÿผ

yes it helps

fresonn avatar Aug 24 '23 14:08 fresonn