Apollo Server 上下文函数每 2 秒执行一次

Apollo Server context function executed every 2 seconds

apollo-server-expresscontext函数在一个区间内不断执行是否正常?

const server = new ApolloServer({
  typeDefs,
  resolvers,
  context: ({ event, context, express }) => {
    console.log('context')
  }
})

我可以每 2 秒左右在控制台中看到一个新的日志输出。

干杯

来自 The context argument 文档:

This function is called with every request, so you can set the context based on the request's details (such as HTTP headers).

每次收到客户端请求时执行,而不是间隔执行。

我找到了罪魁祸首,或者更好的是其中一位 Apollo 贡献者找到了它。

根据 Apollo 团队的 Trevor 所说,这是使用 Graphql Playground 网络版或独立应用程序时的默认行为。

希望对发现相同问题的人有所帮助。