我正在运行两个独立的 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)
这就是我创建绑定(bind)的方式
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
最佳答案
从 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
关于node.js - Prisma 绑定(bind)无法连接到 prisma 服务器。请求 http ://localhost:4466/failed, 原因 : connect ECONNREFUSED 127. 0.0.1:4466,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50377318/