如何修复有关GraphQL代码生成的错误

huangapple go评论96阅读模式
英文:

how fix of the error about graphql codegen

问题

When I do the "yarn graphql-codegen" command, I got the following error:

  1. % yarn graphql-codegen
  2. yarn run v1.22.4
  3. warning package.json: No license field
  4. $ /Users/xxx/node_modules/.bin/graphql-codegen
  5. Parse Configuration
  6. Generate outputs
  7. Generate to src/gql/
  8. Failed to load schema from http://localhost:4000:
  9. connect ECONNREFUSED 127.0.0.1:4000
  10. Error: connect ECONNREFUSED 127.0.0.1:4000
  11. at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
  12. GraphQL Code Generator supports:
  13. - ES Modules and CommonJS exports (export as default or named export "schema")
  14. - Introspection JSON File
  15. - URL of GraphQL endpoint
  16. - Multiple files with type definitions (glob expression)
  17. - String in config file
  18. Try to use one of above options and run codegen again.
  19. Load GraphQL documents
  20. Generate
  21. error Command failed with exit code 1.
  22. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I don't have an idea how to fix it.

英文:

When I do "yarn graphql-codegen" command
I got the following error...
I don't have an idea how to fix it.

  1. % yarn graphql-codegen
  2. yarn run v1.22.4
  3. warning package.json: No license field
  4. $ /Users/xxx/node_modules/.bin/graphql-codegen
  5. Parse Configuration
  6. Generate outputs
  7. Generate to src/gql/
  8. Failed to load schema from http://localhost:4000:
  9. connect ECONNREFUSED 127.0.0.1:4000
  10. Error: connect ECONNREFUSED 127.0.0.1:4000
  11. at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
  12. GraphQL Code Generator supports:
  13. - ES Modules and CommonJS exports (export as default or named export "schema")
  14. - Introspection JSON File
  15. - URL of GraphQL endpoint
  16. - Multiple files with type definitions (glob expression)
  17. - String in config file
  18. Try to use one of above options and run codegen again.
  19. Load GraphQL documents
  20. Generate
  21. error Command failed with exit code 1.
  22. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

did some commands like

  1. yarn add @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations
  1. npm install --save-dev @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations @graphql-codegen/client

/Users/xxx/node_modules/.bin/graphql-codegen

  1. #!/usr/bin/env node
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. const cli_js_1 = require("./cli.js");
  5. const cli_error_js_1 = require("./utils/cli-error.js");
  6. const [, , cmd] = process.argv;
  7. (0, cli_js_1.runCli)(cmd)
  8. .then(returnCode => {
  9. process.exit(returnCode);
  10. })
  11. .catch(error => {
  12. (0, cli_error_js_1.cliError)(error);
  13. });

答案1

得分: 1

尝试更正你的 graphql-codegen 配置中的主机信息,然后再次运行命令。

英文:

It seemed like the host which you tried to connect to (localhost:4000) doesn't exist so graphql-codegen cant load the schema (per error log Failed to load schema from http://localhost:4000:)

Try to correct the host in your graphql-codegen config and run the command again.

huangapple
  • 本文由 发表于 2023年6月12日 17:07:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455108.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定