Updating typescript-operations from 1.9.1 to 1.12.1 broke our build
Describe the bug when running the graphql code generator we end up with the following output
✔ Parse configuration
❯ Generate outputs
❯ Generate packages/web/src/graphql/types.codegen.tsx
✔ Load GraphQL schemas
✔ Load GraphQL documents
✖ Generate
→ Cannot read property 'definitions' of undefined
✔ Generate packages/web/schema.json
Found 1 error
✖ packages/web/src/graphql/types.codegen.tsx
TypeError: Cannot read property 'definitions' of undefined
at /Users/antonio/dev/shippr/node_modules/graphql/utilities/concatAST.js:21:18
at Array.flatMap (<anonymous>)
at flatMap (/Users/antonio/dev/shippr/node_modules/graphql/polyfills/flatMap.js:13:24)
at Object.concatAST (/Users/antonio/dev/shippr/node_modules/graphql/utilities/concatAST.js:20:39)
at Object.plugin (/Users/antonio/dev/shippr/node_modules/@graphql-codegen/typescript-operations/index.cjs.js:107:28)
at executePlugin (/Users/antonio/dev/shippr/node_modules/@graphql-codegen/core/index.cjs.js:50:41)
at /Users/antonio/dev/shippr/node_modules/@graphql-codegen/core/index.cjs.js:106:30
at Array.map (<anonymous>)
at Object.codegen (/Users/antonio/dev/shippr/node_modules/@graphql-codegen/core/index.cjs.js:96:54)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async process (/Users/antonio/dev/shippr/node_modules/@graphql-codegen/cli/bin.js:783:56)
at async Promise.all (index 0)
at async /Users/antonio/dev/shippr/node_modules/@graphql-codegen/cli/bin.js:790:37
at async Task.task (/Users/antonio/dev/shippr/node_modules/@graphql-codegen/cli/bin.js:582:17)
TypeError: Cannot read property 'definitions' of undefined
at /Users/antonio/dev/shippr/node_modules/graphql/utilities/concatAST.js:21:18
at Array.flatMap (<anonymous>)
at flatMap (/Users/antonio/dev/shippr/node_modules/graphql/polyfills/flatMap.js:13:24)
at Object.concatAST (/Users/antonio/dev/shippr/node_modules/graphql/utilities/concatAST.js:20:39)
at Object.plugin (/Users/antonio/dev/shippr/node_modules/@graphql-codegen/typescript-operations/index.cjs.js:107:28)
at executePlugin (/Users/antonio/dev/shippr/node_modules/@graphql-codegen/core/index.cjs.js:50:41)
at /Users/antonio/dev/shippr/node_modules/@graphql-codegen/core/index.cjs.js:106:30
at Array.map (<anonymous>)
at Object.codegen (/Users/antonio/dev/shippr/node_modules/@graphql-codegen/core/index.cjs.js:96:54)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async process (/Users/antonio/dev/shippr/node_modules/@graphql-codegen/cli/bin.js:783:56)
at async Promise.all (index 0)
at async /Users/antonio/dev/shippr/node_modules/@graphql-codegen/cli/bin.js:790:37
at async Task.task (/Users/antonio/dev/shippr/node_modules/@graphql-codegen/cli/bin.js:582:17)
Something went wrong
error Command failed with exit code 1.
To Reproduce
When running codegen on it, it crashes, reverting to 1.9.1 fixes it
-
My GraphQL schema:
-
My GraphQL operations:
-
My
codegen.ymlconfig file:
schema: packages/backend/src/graphql/schema.graphql
documents:
- packages/web/src/**/*.ts
- packages/web/src/**/*.tsx
overwrite: true
generates:
packages/web/src/graphql/types.codegen.tsx:
plugins:
- typescript
- typescript-operations
- typescript-resolvers
- typescript-react-apollo
config:
withHooks: true
withComponent: false
withHOC: false
packages/web/schema.json:
plugins:
- introspection
Expected behavior
Environment:
- OS:
@graphql-codegen/cli: 1.11.2- NodeJS: 12.13.1
Additional context I can't copy paste my graphql schema for privacy reasons, let me know if you want me to try and get a minimal reproduction up
@ardatan can you please take a look? it seems like an issue with toolkit?
I've had a similar issue upgrading from 1.8.3 to 1.12.1. However I can generate code but it doesn't generate the import { ExampleFragmentDoc } from './ExampleFragment.generated in the generated query file. See below my codegen.yml config.
overwrite: true
schema:
- "schema.graphql"
config: {}
documents:
- "src/**/*.graphql"
generates:
src/graphql-types.ts:
- typescript
src/:
preset: near-operation-file
presetConfig:
extension: .generated.tsx
baseTypesPath: graphql-types.ts
config:
noNamespaces: true
withHooks: true
withHOC: false
hooksImportFrom: react-apollo
plugins:
- add: '/* eslint-disable import/first */'
- typescript-operations
- typescript-react-apollo
src/introspection-result.ts:
plugins:
- fragment-matcher
require: []
@henry-young I think your issue is different. Let's track yours there https://github.com/dotansimha/graphql-code-generator/issues/3259
@0xClpz Could you change versions of all codegen packages to 1.12.1 without ^ and ~, and run yarn install or npm install to install them? So we can avoid the version mismatch.
I was getting exactly the same error, but now I can confirm upgrading dependencies fixed it for me
@henry-young I think your issue is different. Let's track yours there #3259
@0xClpz Could you change versions of all codegen packages to 1.12.1 without
^and~, and runyarn installornpm installto install them? So we can avoid the version mismatch.
@ardatan Yes you are correct.
I'm having the same issue, but downgrading from 1.12.2 to 1.12.1 didn't fix it for me
Same issue, downgrading to 1.12.1 fixed it for me.
We are also getting the exact same error message as the OP, and setting the version for all codegen packages to 1.12.2, 1.12.1 or 1.12.0 didn't fix it. The latest version that works is 1.11.2.
@johnnyBira @elarouss @cosmocoder can you please make sure you have the latest versions of graphql-codegen and graphql-toolkit? If it's still happens, can you please share a reproduction in a repo/sandbox? Thanks!
We are using the following codegen packages:
@graphql-codegen/cli: "1.12.2", @graphql-codegen/fragment-matcher: "1.12.2", @graphql-codegen/introspection: "1.12.2", @graphql-codegen/typescript": "1.12.2", @graphql-codegen/typescript-operations": "1.12.2", @graphql-codegen/typescript-react-apollo": "1.12.2"
Using the latest version for those packages didn't solve it for us.
Thanks @cosmocoder , can you please share a reproduction I can try locally?
@dotansimha Here is the minimal setup that showcases the error we are getting.
After installing the packages, run the graphql:generate script in package.json, and you should get the error message.
@cosmocoder As I see in package.json, versions of codegen related packages mismatch
"@graphql-codegen/cli": "^1.11.2",
"@graphql-codegen/fragment-matcher": "1.12.2",
"@graphql-codegen/introspection": "1.12.2",
"@graphql-codegen/typescript": "1.12.2",
"@graphql-codegen/typescript-operations": "1.11.2",
"@graphql-codegen/typescript-react-apollo": "1.11.2"
So we asked you try latest versions like below;
"@graphql-codegen/cli": "1.12.2",
"@graphql-codegen/fragment-matcher": "1.12.2",
"@graphql-codegen/introspection": "1.12.2",
"@graphql-codegen/typescript": "1.12.2",
"@graphql-codegen/typescript-operations": "1.12.2",
"@graphql-codegen/typescript-react-apollo": "1.12.2"
@ardatan apologies for uploading the wrong package.json. I updated the version numbers in the minimal setup, and the error did go away there. But I am still getting the error in our main project with the latest versions. Clearing node_modules and re-installing the packages didn't help also. Any ideas on what might cause this? We are using the same packages in the main project as in the minimal setup.
@cosmocoder Could you try to delete lock file and install dependencies? I recommend you to avoid ^ or ~ in package.json as much as possible.
Yes, I had tried that too, but no luck.
@ardatan @dotansimha I got the exactly same issue. My devDependencies are as follows.
"devDependencies": {
"@graphql-codegen/add": "1.12.2",
"@graphql-codegen/typescript": "1.12.2",
"@graphql-codegen/typescript-operations": "1.12.2",
"@graphql-codegen/typescript-react-apollo": "1.12.2",
"@graphql-codegen/typescript-resolvers": "1.12.2",
"@test-graphql-cli/codegen": "4.0.1-beta.1",
"@test-graphql-cli/coverage": "4.0.1-beta.1",
"@test-graphql-cli/diff": "4.0.1-beta.1",
"@test-graphql-cli/generate": "4.0.1-beta.1",
"@test-graphql-cli/init": "4.0.1-beta.1",
"@test-graphql-cli/serve": "4.0.1-beta.1",
"@test-graphql-cli/similar": "4.0.1-beta.1",
"@test-graphql-cli/validate": "4.0.1-beta.1",
"graphql": "14.6.0",
"graphql-cli": "4.0.1-alpha-0eab853.133",
"schemats": "3.0.3",
"tslint": "5.20.1",
"typescript": "3.7.5"
I downgraded to 1.12.1 but didn't work for me. Also I downgraded to 1.11.2 and it did work for me as @cosmocoder mentioned. Any idea how to fix it with 1.12.2 ?
Also it's giving some incorrect peer dependency warnings when linking dependencies.
warning " > @graphql-codegen/[email protected]" has unmet peer dependency "graphql-tag@^2.0.0".
warning " > @test-graphql-cli/[email protected]" has incorrect peer dependency "[email protected]".
warning " > @test-graphql-cli/[email protected]" has incorrect peer dependency "[email protected]".
warning " > @test-graphql-cli/[email protected]" has incorrect peer dependency "[email protected]".
warning " > @test-graphql-cli/[email protected]" has incorrect peer dependency "[email protected]".
warning " > @test-graphql-cli/[email protected]" has incorrect peer dependency "[email protected]".
warning " > @test-graphql-cli/[email protected]" has incorrect peer dependency "[email protected]".
warning " > @test-graphql-cli/[email protected]" has incorrect peer dependency "[email protected]".
Not sure whether it's related anyway.
@NomadXD Could you try to update your @test-graphql-cli/codegen to 4.0.1-beta.2 and try again?
@cosmocoder Do you also use graphql-cli?
@ardatan I use @graphql-codegen/cli. Is that what you meant?
@cosmocoder I meant graphql-cli which is a different CLI tool but anyway we need to reproduce your issue somehow.