我正在尝试使用这个样板工程。
我的codegen.yml文件将模式定义为:
schema: http://localhost:5555/graphql当我试图生成graphql代码-gen时,我得到一个错误,上面写着:
> yarn run v1.22.18 $ DEBUG=true graphql-codegen ✔ Parse configuration
> ❯ Generate outputs
> ❯ Generate src/lib/graphql.tsx
> ⠙ Load GraphQL schemas
> Load GraphQL documents
> Generate TypeError: fetch failed
> at Object.processResponse (/test/node_modules/cross-undici-fetch/node_modules/undici/lib/fetch/index.js:200:23)
> at /test/node_modules/cross-undici-fetch/node_modules/undici/lib/fetch/index.js:941:38
> at node:internal/process/task_queues:141:7
> at AsyncResource.runInAsyncScope (node:async_hooks:201:9)
> at AsyncResource.runMicrotask (node:internal/process/task_queues:138:8)
> at processTicksAndRejections (node:internal/process/task_queues:96:5) { cause: Error: connect
> ECONNREFUSED 127.0.0.1:5555
> at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16) {
> errno: -61, ✔ Parse configuration ❯ Generate outputs
> ❯ Generate src/lib/graphql.tsx
> ✖ Load GraphQL schemas
> → Failed to load schema
> Load GraphQL documents
> Generate
>
>
> Found 1 error
>
> ✖ src/lib/graphql.tsx
> Failed to load schema from http://localhost:5555/graphql:
>
> fetch failed
> TypeError: fetch failed
> at Object.processResponse (/test/node_modules/cross-undici-fetch/node_modules/undici/lib/fetch/index.js:200:23)
> at /test/node_modules/cross-undici-fetch/node_modules/undici/lib/fetch/index.js:941:38
> at node:internal/process/task_queues:141:7
> at AsyncResource.runInAsyncScope (node:async_hooks:201:9)
> at AsyncResource.runMicrotask (node:internal/process/task_queues:138:8)
> at processTicksAndRejections (node:internal/process/task_queues:96:5)
>
> 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.
> Error: Failed to load schema
> at loadSchema (/test/node_modules/@graphql-codegen/cli/bin.js:509:15)
> at processTicksAndRejections (node:internal/process/task_queues:96:5)
> at async /test/node_modules/@graphql-codegen/cli/bin.js:1039:65
> at async /test/node_modules/@graphql-codegen/cli/bin.js:1038:52
> at async /test/node_modules/@graphql-codegen/cli/bin.js:925:21
> Error: Failed to load schema
> at loadSchema (/test/node_modules/@graphql-codegen/cli/bin.js:509:15)
> at processTicksAndRejections (node:internal/process/task_queues:96:5)
> at async /test/node_modules/@graphql-codegen/cli/bin.js:1039:65
> at async /test/node_modules/@graphql-codegen/cli/bin.js:1038:52
> at async /test/node_modules/@graphql-codegen/cli/bin.js:925:21
>
>
> Running lifecycle hook "afterStart" scripts... [CLI] Loading Schemas
> [CLI] Exited with an error DetailedError: Failed to load schema
> at loadSchema (/test/node_modules/@graphql-codegen/cli/bin.js:509:15)
> at processTicksAndRejections (node:internal/process/task_queues:96:5)
> at async /test/node_modules/@graphql-codegen/cli/bin.js:1039:65
> at async /test/node_modules/@graphql-codegen/cli/bin.js:1038:52
> at async /test/node_modules/@graphql-codegen/cli/bin.js:925:21 { details: '\n' +
> ' Failed to load schema from http://localhost:5555/graphql:\n' +
> '\n' +
> ' fetch failed\n' +
> ' TypeError: fetch failed\n' +
> ' at Object.processResponse (/test/node_modules/cross-undici-fetch/node_modules/undici/lib/fetch/index.js:200:23)\n'
> +
> ' at /test/node_modules/cross-undici-fetch/node_modules/undici/lib/fetch/index.js:941:38\n'
> +
> ' at node:internal/process/task_queues:141:7\n' +
> ' at AsyncResource.runInAsyncScope (node:async_hooks:201:9)\n' +
> ' at AsyncResource.runMicrotask (node:internal/process/task_queues:138:8)\n' +
> ' at processTicksAndRejections (node:internal/process/task_queues:96:5)\n' +
> ' \n' +
> ' GraphQL Code Generator supports:\n' +
> ' - ES Modules and CommonJS exports (export as default or named export "schema")\n' +
> ' - Introspection JSON File\n' +
> ' - URL of GraphQL endpoint\n' +
> ' - Multiple files with type definitions (glob expression)\n' +
> ' - String in config file\n' +
> ' \n' +
> ' Try to use one of above options and run codegen again.\n' +
> ' \n' +
> ' ', source: 'src/lib/graphql.tsx', context: [Object: null prototype] {} } Something went wrong Failed to load schema for
> "src/lib/graphql.tsx"
> Failed to load schema from http://localhost:5555/graphql:
>
> fetch failed
> TypeError: fetch failed
> at Object.processResponse (/test/node_modules/cross-undici-fetch/node_modules/undici/lib/fetch/index.js:200:23)
> at /test/node_modules/cross-undici-fetch/node_modules/undici/lib/fetch/index.js:941:38
> at node:internal/process/task_queues:141:7
> at AsyncResource.runInAsyncScope (node:async_hooks:201:9)
> at AsyncResource.runMicrotask (node:internal/process/task_queues:138:8)
> at processTicksAndRejections (node:internal/process/task_queues:96:5)
>
> 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.我看过这个github问题,它表明一些有这个问题的人通过删除他们的yarn.lock文件并重新运行纱线找到了一个解决方案。我已经尝试过两次了(第二次我还删除了根目录级别的节点模块文件夹),但问题仍然存在。
我不知道下一步该做什么。我不明白是什么失败了,或者是为什么。有人能建议下一件事来解决这个连接问题吗?
当我尝试运行本地版本时,前端将在localhost3000加载,但在localhost:5555/graphql上,我会得到这样的响应:
查询丢失。
当我检查页面上的控制台时,它会说“糟糕的请求”。
发布于 2022-05-03 21:59:28
我没有意识到我必须让服务器运行才能运行代码。它起作用了。
https://stackoverflow.com/questions/72093753
复制相似问题