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

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

how fix of the error about graphql codegen

问题

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

% yarn graphql-codegen
yarn run v1.22.4
warning package.json: No license field
$ /Users/xxx/node_modules/.bin/graphql-codegen
✔ Parse Configuration
⚠ Generate outputs
  ❯ Generate to src/gql/
    ✖
      Failed to load schema from http://localhost:4000:
      connect ECONNREFUSED 127.0.0.1:4000
      Error: connect ECONNREFUSED 127.0.0.1:4000
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
      GraphQL Code Generator supports:
      - ES Modules and CommonJS exports (export as default or named export "schema")
      - Introspection JSON File
      - URL of GraphQL endpoint
      - Multiple files with type definitions (glob expression)
      - String in config file
      Try to use one of above options and run codegen again.
    ◼ Load GraphQL documents
    ◼ Generate
error Command failed with exit code 1.
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.

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

did some commands like

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

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

#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const cli_js_1 = require("./cli.js");
const cli_error_js_1 = require("./utils/cli-error.js");
const [, , cmd] = process.argv;
(0, cli_js_1.runCli)(cmd)
    .then(returnCode => {
    process.exit(returnCode);
})
    .catch(error => {
    (0, cli_error_js_1.cliError)(error);
});

答案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:

确定