Prisma 绑定无法连接到 Prisma 服务器。请求 http://localhost:4466/ 失败,原因:连接 ECONNREFUSED 127.0.0.1:4466
Prisma binding unable to connect to prisma server. request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466
我运行正在使用两个独立的docker服务。一个用于我的 GraphQL 服务器,另一个是连接到本地 Postgres 数据库的 prisma 服务。我能够 运行 prisma 部署并直接在 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
得到 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
我在 windows 上使用 Docker 工具箱时发生了这种情况,必须将端点从使用本地主机更改为 prisma.yml
:
中的 VirtualBox 默认 IP
endpoint: http://192.168.99.100:4466
我运行正在使用两个独立的docker服务。一个用于我的 GraphQL 服务器,另一个是连接到本地 Postgres 数据库的 prisma 服务。我能够 运行 prisma 部署并直接在 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
得到 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
我在 windows 上使用 Docker 工具箱时发生了这种情况,必须将端点从使用本地主机更改为 prisma.yml
:
endpoint: http://192.168.99.100:4466