django - 如何使用 django-ratelimit 进行石墨烯解析
问题描述
我们不能django-ratelimit
直接用于 graphql 解析方法。因为默认装饰器是从第一个参数获取请求。
解决方案
我写了一个简单的装饰器,它可以支持像gql:xxxx
with这样的键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)
推荐阅读
- excel - 是否有“LENIF”等价物?
- ios - SwiftUI:使用变量从右到左滚动 Imageview 的动画
- reactjs - 如何在reactjs中访问路由器链接?
- python - 用布局覆盖 QWidget
- python - 按顺序在芹菜中运行多个链
- android - 当错误设置为 null 时,TextInputLayout 会留下空白
- python - 如何在 TF2 中将 ImageDataGenerator 与 TensorFlow 数据集结合起来?
- javascript - 如何将 JSON 从 API 加载到 html 表中(转置)
- oracle - 基于选择的返回值
- mongodb - MongoDB In-Memory 作为 Redis 替代品?