繁体   English   中英

向原点发送请求时出错。 Apollo Engine如何配置Apollo Engine的来源?

[英]Error sending request to origin. Apollo Engine how to configure apollo engine origins?

我正在尝试向我的/graphiql IDE发出请求,并且收到有关我的来源的超时错误。

ERRO [0515]向源发送请求时出错。 这意味着原始GraphQL服务器没有及时响应代理请求。 若要解决此问题,请验证引擎配置中的Origin规范与相应的GraphQL服务器匹配。 如果错误是超时错误,请考虑在引擎配置中增加origin.requestTimeout error =“发布http://127.0.0.1:51301/graphql:net/http :请求已取消(在等待标头时超过了Client.Timeout)” 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

我的Apollo服务器就是这样设置的

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() }
 });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM