Describe the bug
Getting this error while running the CLI tool to generate typescript types, but it doesn't provide any useful information
[17:40:26] Generate [started]
[17:40:27] Generate [failed]
[17:40:27] โ Plugin "typescript-react-apollo" validation failed:
[17:40:27] Generate ./src/generatedTypes.ts [failed]
[17:40:27] โ Plugin "typescript-react-apollo" validation failed:
[17:40:27] Generate outputs [failed]
This is the codegen.yml, the problem is that the generated file extension must be *.tsx, while I put *.ts
schema:
- ${SCHEMA_PATH}:
headers:
authorization: ${AUTH_TOKEN}
documents: ./src/**/*.graphql.ts
generates:
./src/generatedTypes.ts:
plugins:
- typescript
- typescript-operations
- typescript-react-apollo
config:
withHooks: true
withHOC: false
withMutationFn: false
documentMode: external
importDocumentNodeExternallyFrom: near-operation-file
The actual error if I log the error manually:
Error: Plugin "react-apollo" requires extension to be ".tsx"!
at Object.exports.validate (/Users/ruanyl/project/graphql-client-demo/node_modules/@graphql-codegen/typescript-react-apollo/src/index.ts:204:13)
at Object.executePlugin (/Users/ruanyl/project/graphql-client-demo/node_modules/@graphql-codegen/core/src/execute-plugin.ts:42:20)
at /Users/ruanyl/project/graphql-client-demo/node_modules/@graphql-codegen/core/src/codegen.ts:71:28
at Array.map (<anonymous>)
at Object.codegen (/Users/ruanyl/project/graphql-client-demo/node_modules/@graphql-codegen/core/src/codegen.ts:58:21)
at process (/Users/ruanyl/project/graphql-client-demo/node_modules/@graphql-codegen/cli/src/codegen.ts:245:40)
at async Promise.all (index 0)
at /Users/ruanyl/project/graphql-client-demo/node_modules/@graphql-codegen/cli/src/codegen.ts:253:23
at Task.task (/Users/ruanyl/project/graphql-client-demo/node_modules/@graphql-codegen/cli/src/codegen.ts:19:9)
@ruanyl which version of the codegen do you use?
@dotansimha
"name": "@graphql-codegen/cli",
"version": "1.8.1",
BTW, ./node_modules/.bin/graphql-codegen --version doesn't output the version, but run codegen.
@ruanyl Can you please try the latest alpha? 1.8.2-alpha-096084bc.27
It got the following with it:
โ graphql-code-generator git:(master) โ yarn generate:examples
yarn run v1.19.0
$ ./dev-test/generate-all.sh
โ Parse configuration
โฏ Generate outputs
โฏ Generate ./dev-test/githunt/types.reactApollo.hooks.ts
โ Load GraphQL schemas
โ Load GraphQL documents
โ Generate
โ Plugin "typescript-react-apollo" validation failed:
Found 1 error
โ ./dev-test/githunt/types.reactApollo.hooks.ts
Plugin "react-apollo" requires extension to be ".tsx"!
Error: Plugin "typescript-react-apollo" validation failed:
at Object.executePlugin (/Users/dotansimha/Dev/graphql-code-generator/packages/gra
phql-codegen-core/dist/commonjs/execute-plugin.js:27:19)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Error: Plugin "typescript-react-apollo" validation failed:
at Object.executePlugin (/Users/dotansimha/Dev/graphql-code-generator/packages/gra
phql-codegen-core/dist/commonjs/execute-plugin.js:27:19)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Something went wrong
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@dotansimha Thank you, I think I happen to figure out what was the issue, I'm running codegen with VERBOSE=1 and it lacks the Error information in this mode. But without VERBOSE it works fine.
@ruanyl I am having the exactly the same problem. Could you please elaborate on solution. What did you mean by running codegen without VERBOSE?
I am running codegen via a package.json script:
"build:schema": "graphql-codegen --config codegen.yml"
How do I run codegen without VERBOSE?
Thank you for your help.
@seyaobey
export VERBOSE=1
export DEBUG=1
then source bash profile
now i'm getting helpful error outputs
@alexisdray @seyaobey If this issue is still relevant, can you please try the latest, and report in a new issue if needed? Thanks
Thanks for the VERBOSE=1 hint. I first tried --verbose arg, but it looks like it does not exist.
I have (probably) a similar issue. The files reported by graphql-codegen are irrelevant and it's hard to find the actual error.
Unfortunately, I work on a not open-source project, so I can't help with reproducing the issue. But at least here is what I had. Maybe it could help to someone.
$ yarn graphql-codegen --config codegen.yml
yarn run v1.22.4
$ /project/node_modules/.bin/graphql-codegen --config codegen.yml
โ Parse configuration
โฏ Generate outputs
โ Generate src/types/graphql.ts
โฏ Generate src/types/resolvers.ts
โ Load GraphQL schemas
โ Load GraphQL documents
โ Generate
โ at /project/some-irrelevant-file.tsx:6:3
โฏ Generate src/types/operations.ts
โ Load GraphQL schemas
โ Load GraphQL documents
โ Generate
โ at /project/some-irrelevant-file.tsx:6:3
Something went wrong
error Command failed with exit code 1.
/project/some-irrelevant-file.tsx does not help at all$ VERBOSE=1 yarn graphql-codegen --config codegen.yml
yarn run v1.22.4
$ /project/node_modules/.bin/graphql-codegen --config codegen.yml
[14:08:36] Parse configuration [started]
...
[14:08:39] Generate [started]
[14:08:39] Generate [failed]
[14:08:39] โ
GraphQLDocumentError: Cannot query field "someField" on type "SomeType".
at project/some-other-irrelevant-file.tsx:6:3
...
someField or SomeType in the codebase, I can find the actual error (someField field is removed from the schema, but is still used in a query)