1

How can I throttle queries in graphene-django? Is there any package that can be used in graphene-django to throttle queries.

Amiya Behera
  • 2,210
  • 19
  • 32
  • Check out this duplicate question https://stackoverflow.com/questions/61309011/django-graphene-rate-limit-throttling – Jura Brazdil Mar 18 '21 at 15:25

2 Answers2

1

One option is to do your query throttling at the web server, and leave django and graphene out of it. For example, if you're using nginx and uwsgi, and your graphene endpoint is /api you could add this to your nginx configuration:

location = /api/ {
    limit_rate_after 500k;
    limit_rate 50k;
    uwsgi_pass  django;
    include     /path/to/uwsgi_params;
}

which throttle queries larger than 500k. Nginx has other configuration parameters to limit based on client -- see https://www.nginx.com/blog/rate-limiting-nginx/ and https://docs.nginx.com/nginx/admin-guide/security-controls/controlling-access-proxied-http/#limit_rate

Very simple to implement,, but if you need to throttle based on a single customer using multiple clients, this approach will not work.

Mark Chackerian
  • 21,866
  • 6
  • 108
  • 99
0

Another option could be using django-throttle-requests which allows you configure view-level throttling rules. Particularly in graphene-django can be use in your URLs.

On the other hand, Django Rest Framework offers a well documented set of throttling functionalities that can be handy also at the view level.