Giter VIP home page Giter VIP logo

Comments (3)

spawnia avatar spawnia commented on July 22, 2024 1

Lighthouse leverages Laravel's rate limiting, which is rather simplistic in its implementation.

I could see adding additional structured data to rate limit errors as described in https://docs.github.com/en/graphql/overview/resource-limitations#rate-limit, but am unsure how much information the Laravel rate limiter provides.

A solution involving HTTP headers does not belong with @throttle or even Lighthouse at all, since that would mix the responsibilites of the GraphQL and HTTP layer. @throttle provides per-field rate limits, not per-request.

from lighthouse.

spawnia avatar spawnia commented on July 22, 2024 1

I am open for pull requests that improve how @throttle works, but am not planning to work on it myself.

from lighthouse.

LiamKarlMitchell avatar LiamKarlMitchell commented on July 22, 2024

Right, that makes sense.
Laravel throttle does have an availableIn which returns the seconds
https://laravel.com/docs/10.x/rate-limiting#determining-limiter-availability

I see if name is not set on the throttle directive, then the key includes the IP address of the request.

'key' => sha1($this->directiveArgValue('prefix') . $this->request->ip()),

Looks possible to get attempts, availableIn, remaining.

    protected function handleLimit(string $key, int $maxAttempts, float $decayMinutes, string $fieldReference): void
    {
        if ($this->limiter->tooManyAttempts($key, $maxAttempts)) {
            $this->limiter->attempts($key);
            $this->limiter->availableIn($key);
            $this->limiter->remaining($key, $maxAttempts);
            throw new RateLimitException($fieldReference);
        }

        $this->limiter->hit($key, (int) ($decayMinutes * 60));
    }

So it should be possible to extend the RateLimitException with ProvidesExtensions and provide more information from the limiter.

Question would be if doing so, what would the property names look like and what data to return back.

from lighthouse.

Related Issues (20)

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.