Prisma绑定无法连接到prisma服务器。请求http:// localhost:4466 /失败,原因:connect ECONNREFUSED 127.0.0.1:4466

时间:2018-05-16 17:57:43

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

我正在运行两个独立的docker服务。一个用于我的GraphQL服务器,另一个是连接到本地Postgres数据库的prisma服务。我可以运行prisma deploy并直接在http://localhost:4466中测试它。但是当我尝试在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

2 个答案:

答案 0 :(得分:5)

获得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

答案 1 :(得分:1)

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

endpoint: http://192.168.99.100:4466