Reputation: 33
everyone!
I hope your help...!
I created a React project with CRA,
The backend is graphql + node on port 3000.
It works fine "http://localhost:5000"
Also the script 'precodegen' works fine, so, generated schema.json in client.
However, the following error occurs in the codegen command.
Help me please...! Thank you~!
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"precodegen": "apollo-codegen introspect-schema http://localhost:5000/graphql --output schema.json",
"codegen": "apollo-codegen generate './src/**/!(*.local).ts' --addTypename --schema schema.json --target typescript --output ./src/__generated__/api.d.ts"
},
yarn codegen
yarn run v1.17.3
$ apollo-codegen introspect-schema http://localhost:5000/graphql --output schema.json
$ apollo-codegen generate './src/**/!(*.local).ts' --addTypename --schema schema.json --target typescript --output ./src/__generated__/api.d.ts
TypeError: Property name expected type of string but got null
at validate (/Users/jongseoklee/dev/ts-graphql/client/node_modules/@babel/types/lib/definitions/utils.js:159:13)
at Object.validate (/Users/jongseoklee/dev/ts-graphql/client/node_modules/@babel/types/lib/definitions/utils.js:196:7)
at validateField (/Users/jongseoklee/dev/ts-graphql/client/node_modules/@babel/types/lib/validators/validate.js:24:9)
at validate (/Users/jongseoklee/dev/ts-graphql/client/node_modules/@babel/types/lib/validators/validate.js:17:3)
at builder (/Users/jongseoklee/dev/ts-graphql/client/node_modules/@babel/types/lib/builders/builder.js:38:27)
at Object.Identifier (/Users/jongseoklee/dev/ts-graphql/client/node_modules/@babel/types/lib/builders/generated/index.js:334:31)
at nonNullableTypeFromGraphQLType (/Users/jongseoklee/dev/ts-graphql/client/node_modules/apollo-codegen-typescript/src/helpers.ts:47:34)
at TypescriptAPIGenerator.typeFromGraphQLType (/Users/jongseoklee/dev/ts-graphql/client/node_modules/apollo-codegen-typescript/src/helpers.ts:55:20)
at TypescriptAPIGenerator.handleFieldValue (/Users/jongseoklee/dev/ts-graphql/client/node_modules/apollo-codegen-typescript/src/codeGeneration.ts:428:20)
at /Users/jongseoklee/dev/ts-graphql/client/node_modules/apollo-codegen-typescript/src/codeGeneration.ts:347:20
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Upvotes: 1
Views: 988
Reputation: 1762
I was trying to install apollo-codegen using yarn in my project only and was getting this error. When I followed the instructions to install apollo-codegen globally, this error went away. Not the solution that I want but it seems fine for now.
Upvotes: 1