【问题标题】:Error sending request to origin. Apollo Engine how to configure apollo engine origins?向源发送请求时出错。 Apollo Engine 如何配置 apollo engine origins?
【发布时间】:2018-11-30 01:27:32
【问题描述】:

我正在尝试向我的 /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,因为我的服务器上没有任何东西会像那样更改端口号。

我的apollo引擎配置是这样的

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"
        }
      }
    }
  ]

【问题讨论】:

    标签: javascript node.js cors apollo apollo-server


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-27
      • 2019-06-12
      • 2021-10-16
      • 1970-01-01
      • 2018-08-21
      • 2017-03-16
      • 2019-01-13
      • 2021-05-07
      相关资源
      最近更新 更多