等待流数据时Apollo Server超时

时间:2018-01-28 19:12:44

标签: node.js graphql braintree apollo apollo-server

我试图用我的Apollo Server等待流的结果。我的解析器看起来像这样。

async currentSubs() {
  try {
    const stream = gateway.subscription.search(search => {
      search.status().is(braintree.Subscription.Status.Active);
    });
    const data = await stream.pipe(new CollectObjects()).collect();
    return data;
  } catch (e) {
    console.log(e);
    throw new Meteor.Error('issue', e.message);
  }
},

当返回的数据流很小时,此解析器工作正常,但当进入的数据较大时,我得到503 (Service Unavailable)。我看起来超时发生在30秒左右。我尝试使用graphQLServer.timeout = 240000;来增加Express服务器的超时时间,但这并没有带来任何影响。

如何解决此问题? 30秒超时来自哪里?只有在结果需要更长时间时才会失败。

我使用https://github.com/mrdaniellewis/node-stream-collect从流中收集结果。

来自try catch的错误:

I20180128-13:09:26.872(-7)? { proxy:
I20180128-13:09:26.872(-7)?    { error: 'Post http://127.0.0.1:26474/graphql: net/http: request canceled (Client.Timeout exceeded while awaiting headers)',
I20180128-13:09:26.872(-7)?      level: 'error',
I20180128-13:09:26.873(-7)?      msg: 'Error sending request to origin.',
I20180128-13:09:26.873(-7)?      time: '2018-01-28T13:09:26-07:00',
I20180128-13:09:26.873(-7)?      url: 'http://127.0.0.1:26474/graphql' } }

1 个答案:

答案 0 :(得分:4)

也有同样的问题,这是一个非常简单的解决方案。我的通话持续了30秒多一点,默认超时也返回了503s,所以我增加了。

假设您正在使用apollo引擎(某些其他形式的Apollo可能是这样),则可以像下面这样设置引擎配置:

  export function startApolloEngine() {
    const engine = new Engine({
    engineConfig: {
      stores: [
        {
          name: "publicResponseCache",
          memcache: {
            url: [environmentSettings.memcache.server],
            keyPrefix: environmentSettings.memcache.keyPrefix
          }
        }
      ],
      queryCache: {
        publicFullQueryStore: "publicResponseCache"
      },
      reporting: {
        disabled: true
      }
    },
    // GraphQL port
    graphqlPort: 9001,
    origin: {
      requestTimeout: "50s"
    },

    // GraphQL endpoint suffix - '/graphql' by default
    endpoint: "/my_api_graphql",
    // Debug configuration that logs traffic between Proxy and GraphQL server
    dumpTraffic: true
  });

  engine.start();
  app.use(engine.expressMiddleware());
}

注意我指定的部分

origin: { requestTimeout: "50s" }

仅此一项对我来说是固定的。希望这会有所帮助!

您可以找到有关here的更多信息

相关问题