Use django-ratelimit for graphql
Project description
Eaiser to use django-ratelimit for graphql in django.
Install
pip install django-graphql-ratelimit
Usage
ratelimit key support gql:xxx
, where xxx
is argument.
from django_graphql_ratelimit import ratelimit
class RequestSMSCode(graphene.Mutation):
class Arguments:
phone = graphene.String(required=True)
ok = graphene.Boolean()
@ratelimit(key="ip", rate="10/m", block=True)
@ratelimit(key="gql:phone", rate="5/m", block=True)
def mutate(self, info, phone):
request = info.context
# send sms code logic
return RequestSMSCode(ok=True)
You can use django-ratelimit keys except get:xxx
and post:xxx
:
ip
- Use the request IP address (i.e.request.META['REMOTE_ADDR']
) I suggest you to use django-ipware to get client ip, modify you MIDDLEWARE in settings:
MIDDLEWARE = [
"django_graphql_ratelimit.middleware.ParseClientIpMiddleware",
...
]
header:x-x
- Use the value of request.META.get('HTTP_X_X', '').user
: - Use an appropriate value from request.user. Do not use with unauthenticated users.user_or_ip
- Use an appropriate value fromrequest.user
if the user is authenticated, otherwise use request.META['REMOTE_ADDR'] (see the note above about reverse proxies).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-graphql-ratelimit-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fb207a81d9e6e792c3e8750d6d1dca5744cb2d16b79cef6cea40a5548dab27f |
|
MD5 | 5faae9c4a38d46e89b7fb6fb6e45166b |
|
BLAKE2b-256 | 8d76eb2ba040d9d423c709cff502bffb3c7a308c0cbd312413adf209187c9366 |
Close
Hashes for django_graphql_ratelimit-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bf0c733ffb6ab893e5997b9782f4a4462acb49297526b8599da151684f99d54 |
|
MD5 | 5dc2f0a6d43138dc1cc5fff1b686bdbe |
|
BLAKE2b-256 | 2613e6c4c94795db15e7e1cd2c4726cd18b27af714ac55369552d77bad38903e |