向源发送请求时出错.阿波罗引擎如何配置阿波罗引擎原点?



我正在尝试向我的/graphiqlIDE发出请求,但收到有关我的源的超时错误。

ERRO[0515] 向源发送请求时出错。这意味着源 GraphQL 服务器没有及时响应代理请求。要解决此问题,请验证引擎配置中的源规范是否与相应的 GraphQL 服务器匹配。如果错误是超时错误,请考虑增加引擎配置中的origin.requestTimeout。 error="post http://127.0.0.1:51301/graphql: net/http: request被取消(等待标头时超出客户端超时(" url="http://127.0.0.1:51301/graphql">

请记住,每次运行时 URL (http://127.0.0.1:51301/graphql( 端口都会更改,因此这让我相信它一定是 Apollo 引擎代理正在处理的 URL,因为我的服务器上没有任何内容会像那样更改端口号。

我的阿波罗引擎配置是这样的

import { ApolloEngine } from "apollo-engine";
import { ENGINE_API_KEY, PORT } from "../config/keys";
import { INFO } from "./utils/logging";
import app from './app';
const LOG_START = () => INFO(`Listening! at port: ${PORT}`);
/*
setup Apollo Engine
*/
const engine = new ApolloEngine({
apiKey: process.env.ENGINE_API_KEY || ENGINE_API_KEY,
});
/*
Config for Apollo Engine to serve
*/
const ENGINE_SERVE = {
port: PORT,
graphqlPaths: ["/graphql"],
expressApp: app,
launcherOptions: {
startupTimeout: 3000
}
};
/*
Entry point for application starts server
*/
engine.listen(ENGINE_SERVE, LOG_START);

我的端口号是:8080

我的阿波罗服务器是这样设置的

import cors from "cors";
import morgan from "morgan";
import express from "express";
import bodyParser from "body-parser";
import compression from "compression";
import { graphqlExpress, graphiqlExpress } from "apollo-server-express";
import connectDb from "./connectors/mongo-connector";
import schema from "./schemas/schema";
/*
Create express application
*/
const app = express();
/*
Configure graphql server
*/
const GRAPH_EXPRESS = graphqlExpress({
schema,
tracing: true,
context: { db: async () => await connectDb() }
});
/*
Configure Graphql IDE for testing
*/
const GRAPH_IDE = graphiqlExpress({ endpointURL: "/graphql" });
/*
Middleware and route handlers
*/
app.use(cors());
app.use(morgan("dev"));
app.use(compression());
app.use("/graphql", bodyParser.json(), GRAPH_EXPRESS);
app.use("/graphiql", GRAPH_IDE);
export default app;

我不明白为什么我的请求没有被退回 我试过了

增加我的源超时,并在引擎配置中显式设置我的源。但是我无法设置错误所说的URL,因为端口每次都会更改,所以我有点不知所措,任何帮助将不胜感激。

"origins": [
{
"http": {
"requestTimeout": "60s",
"url": "http://localhost:8080/graphql",
"overrideRequestHeaders": {
"Host": "localhost"
}
}
}
]

问题是我的 mongo 连接器没有触发,因为我的端点超时了 mongo 连接,我误解了错误的含义。

const GRAPH_EXPRESS = graphqlExpress({
schema,
tracing: true,
context: { db: connectDb() }
});

最新更新