大家!
希望您的帮助...!
我用CRA创建了一个React项目,
后端是graphql +端口3000上的节点。
它工作正常“ http:// localhost:5000 ”
脚本“ precodegen”也可以正常工作,因此,在客户端生成了schema.json。
但是,在codegen命令中发生以下错误。
请帮帮我...!谢谢〜!
"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.
我试图仅在我的项目中使用yarn安装apollo-codegen,但出现此错误。当我按照说明全局安装apollo-codegen时,此错误消失了。不是我想要的解决方案,但目前看来还不错。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句