Giter Site home page Giter Site logo

stan-sack / django-graphql-ratelimit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from o3o3o/django-graphql-ratelimit

0.0 1.0 0.0 14 KB

Easier to use django-ratelimit for graphql in django.

Home Page: https://pypi.org/project/django-graphql-ratelimit/

Makefile 1.26% Python 98.74%

django-graphql-ratelimit's Introduction

CircleCI PyPI

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 your 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 from request.user if the user is authenticated, otherwise use request.META['REMOTE_ADDR'].

django-graphql-ratelimit's People

Contributors

o3o3o avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.