属性 name 预期的字符串类型但得到 null of apollo-codegen 错误
Property name expected type of string but got null of apollo-codegen Error
各位!
希望得到您的帮助...!
我用 CRA 创建了一个 React 项目,
后端是 graphql + 端口 3000 上的节点。
工作正常“http://localhost:5000”
脚本 'precodegen' 工作正常,因此在客户端生成 schema.json。
但是codegen命令出现如下错误
请帮助我...!谢谢~!
package.json
"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 时,此错误消失了。不是我想要的解决方案,但目前看来还不错。
各位!
希望得到您的帮助...!
我用 CRA 创建了一个 React 项目,
后端是 graphql + 端口 3000 上的节点。
工作正常“http://localhost:5000”
脚本 'precodegen' 工作正常,因此在客户端生成 schema.json。
但是codegen命令出现如下错误
请帮助我...!谢谢~!
package.json
"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 时,此错误消失了。不是我想要的解决方案,但目前看来还不错。