全栈开发
graphql
【Q432】如何给 graphql 设计合理的 Rate Limit

如何给 graphql 设计合理的 Rate Limit

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 439 (opens in a new tab)

Author 回答者: shfshanyue (opens in a new tab)

对于 Rest API 而言可根据特定的 API 来进行*限流(Rate Limit)*设计

然而,GraphQL 只有一个 API,无法根据此来限流,一般情况下根据 Field 来进行限流,为了更好地设计及声明限流条件,可自定义 Directive,如下所示

type Query {
  todos: [Todo!]! @rateLimit(window: "1s", max: 100)
}

可参考以下两个 npm package