【问题标题】:Prisma binding unable to connect to prisma server. request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466Prisma 绑定无法连接到 prisma 服务器。请求 http://localhost:4466/ 失败,原因:连接 ECONNREFUSED 127.0.0.1:4466
【发布时间】:2018-10-26 21:18:50
【问题描述】:

我正在运行两个独立的 docker 服务。一个用于我的 GraphQL 服务器,另一个是连接到本地 Postgres 数据库的 prisma 服务。我可以直接在http://localhost:4466 中运行 prisma deploy 并对其进行测试。但是当我尝试在http://localhost:8080 中使用我的应用程序的 GraphQL 服务器进行查询时,它会给出以下响应。

{
  "data": null,
  "errors": [
    {
      "message": "request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "feed"
      ]
    }
  ]
}

这是堆栈跟踪。

graphql-server_1  | [Network error]: FetchError: request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466
graphql-server_1  | Error: request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466
graphql-server_1  |     at new CombinedError (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/errors.js:83:28)
graphql-server_1  |     at Object.checkResultAndHandleErrors (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/errors.js:101:15)
graphql-server_1  |     at CheckResultAndHandleErrors.transformResult (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/transforms/CheckResultAndHandleErrors.js:10:25)
graphql-server_1  |     at /usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/transforms/transforms.js:19:54
graphql-server_1  |     at Array.reduce (<anonymous>)
graphql-server_1  |     at applyResultTransforms (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/transforms/transforms.js:18:23)
graphql-server_1  |     at /usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:82:50
graphql-server_1  |     at step (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)
graphql-server_1  |     at Object.next (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)
graphql-server_1  |     at fulfilled (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:4:58)

这就是我创建绑定的方式

const server = new GraphQLServer({
  typeDefs: './src/schema.graphql',
  resolvers,
  context: req => ({
    ...req,
    db: new Prisma({
      typeDefs: './src/generated/prisma.graphql',
      endpoint: 'http://localhost:4466',
      secret: 'my-secret',
      debug: true,
    })
  })
});

我不确定是什么问题。

完整代码可以在这里找到:https://github.com/dhanushuUzumaki/Journal/tree/feature/setup

【问题讨论】:

  • GraphQL 服务器端点不应该是 8080 吗?
  • 我不这么认为.. 我的应用程序的 GraphQL 服务器在 8080 上运行,而 prisma 在 4466 上运行。端点应该指向 prisma 服务,对吧?当我直接查询 4466 时,它的工作..如果我通过 8080 进行查询,我将面临此错误。
  • 很好的编辑,@tk3 :-).

标签: node.js graphql graphql-js prisma prisma-graphql


【解决方案1】:

从 prisma 论坛获得帮助来解决这个问题。

在容器中使用 localhost 指向容器本身,而不是容器运行所在的主机。因此,为了连接到 Prisma 实例,您必须使用解析为相应 Prisma 容器的内部服务名称。

...
    db: new Prisma({
      typeDefs: './src/generated/prisma.graphql',
      endpoint: 'http://prisma:4466',
      secret: 'my-secret',
      debug: true,
    })
...

Prisma Forum - ECONNREFUSED - Unable to connect to prisma service through binding

【讨论】:

    【解决方案2】:

    这发生在我在 Windows 上使用 Docker Toolbox 时,端点必须从使用 localhost 更改为 prisma.yml 内的 VirtualBox 默认 ip:

    endpoint: http://192.168.99.100:4466
    

    【讨论】:

    • 'ERR_INVALID_URL':无效的 URL:192.168.99.100:4466
    • 谢谢!这对我有用。按照本教程安装 Prisma 服务器以创建 React + Prisma/GrapQL 应用程序:prisma.io/tutorials/build-react-graphql-app-with-fetch-ct19 on Windows 8.1 with Docker。你怎么知道VirtualBox IP?我的 VirtualBox 网络地址是 192.168.56.1 和 192.168.99.1,但 192.168.99.100 是用于部署 prisma 的地址。
    猜你喜欢
    • 2020-03-01
    • 2019-12-04
    • 2019-08-13
    • 2019-08-09
    • 2020-09-14
    • 2019-12-23
    • 2023-01-26
    • 1970-01-01
    • 2016-08-13
    相关资源
    最近更新 更多