如何使用django Rate Limit解析石墨烯

如何使用django Rate Limit解析石墨烯,django,graphene-python,Django,Graphene Python,对于graphql解析方法,我们不能直接使用django Rate Limit。 因为默认的装饰器是来自第一个参数的get请求。我写了一个,它可以支持像gql:xxxx和django ratelimit这样的键,下面是演示: class TestMutaion(graphene.Mutation): class Arguments: phone = graphene.String(required=True) ok = graphene.Boolean() @rateli

对于graphql解析方法,我们不能直接使用
django Rate Limit
。 因为默认的装饰器是来自第一个参数的get请求。

我写了一个,它可以支持像
gql:xxxx
django ratelimit
这样的键,下面是演示:

class TestMutaion(graphene.Mutation):
  class Arguments:
    phone = graphene.String(required=True)

  ok = graphene.Boolean()

  @ratelimit(key="gql:phone", rate="5/m", block=True) # here key: 'gql:phone'
  def mutate(self, info, phone):
    request = info.context
    # Do sth
    return TestMutaion(ok=True)

我已将该片段添加到简单pkg中: