0

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

{
  "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

4

2 回答 2

6

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

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

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

Prisma 论坛 - ECONNREFUSED - 无法通过绑定连接到 prisma 服务

于 2018-05-17T17:23:55.147 回答
1

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

endpoint: http://192.168.99.100:4466
于 2018-09-21T13:03:29.467 回答