插件方法类型不应强制用户返回一个 promise

作者: stretchkennedy创建于 2025年9月15日更新于 2026年5月12日

在 v3 中,大多数插件方法(如 requestDidStart 等)都被统一为始终返回一个 promise。这意味着,用户不必再使用

typescript
class LoggingPlugin implements ApolloServerPlugin<MyContext> {
  requestDidStart() {
    const start = hrtime.bigint()
    return {
      willSendResponse () {
        console.log('completed in', (hrtime.bigint() - start) / BigInt(1000000), 'ms')
      }
    }
  }
}

内容来源: apollographql/apollo-server