Graphene-django: What's the best way to rate limit specific graphql endpoints?

Created on 10 Dec 2018  路  7Comments  路  Source: graphql-python/graphene-django

Is there a way to limit graphql endpoints? What are the current workarounds for this?

As a feature request, it might be a good idea to have something like https://django-ratelimit.readthedocs.io/en/v1.0.0/, where you can use decorators to ratelimit your APIs.

question wontfix

Most helpful comment

Hi @zbyte64 haven't tried it yet but doesn't that require a view class though? I was hoping I could do it on a per-mutation/query basis. i.e., I want to limit only my graphql/signup endpoint and not all graphql endpoints.

All 7 comments

Why not just use django-ratelimit? You can use the graphql endpoint with decorators, this is how I did it with csrf exemption:

url(r'^graphql/$', csrf_exempt(GraphQLView.as_view(graphiql=True))),

Hi @zbyte64 haven't tried it yet but doesn't that require a view class though? I was hoping I could do it on a per-mutation/query basis. i.e., I want to limit only my graphql/signup endpoint and not all graphql endpoints.

I see, in that case you would embed the is_ratelmited call in each mutation or resolver: https://django-ratelimit.readthedocs.io/en/v1.0.0/usage.html#is_ratelimited ; where info.context is the request object the function needs

hmm, one solution could be a decorator that gets the class and resolver function
than uses that as a key with the users pk
in redis with an auto expire provision ..

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This snippet may help you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dan-klasson picture dan-klasson  路  4Comments

BrianChapman picture BrianChapman  路  3Comments

timothyjlaurent picture timothyjlaurent  路  3Comments

Dawidpol picture Dawidpol  路  4Comments

amiyatulu picture amiyatulu  路  3Comments