Skip to content

One GraphQL request costs one rate-limit token however much it asks for #361

Open

Description

@Miracle656

Background

Rate limiting counts HTTP requests. A REST caller wanting fifty pairs' prices
makes fifty requests and spends fifty tokens. A GraphQL caller asks for all
fifty in one document — aliasing the same field fifty times is legal GraphQL —
and spends one.

{ a: getPrice(assetA:"XLM", assetB:"USDC") { price }
  b: getPrice(assetA:"XLM", assetB:"USDC") { price }
  … fifty more … }

Each alias runs the resolver, so that is fifty cache reads, fifty aggregate
computations and fifty best-route calculations behind a single token. Depth
limiting (L190) does not help: this query is two levels deep.

What to build

  • A query cost or complexity limit, in addition to depth. Assign a cost per
    field — the expensive resolvers are getPrice, getBestRoute and
    getPriceHistory, which hit the database and the cache — and reject a
    document whose total exceeds the budget.
  • Or make rate limiting consume tokens proportional to the computed cost, which
    composes better with L188's pricing.
  • Either way the limit must be computed from the parsed document before
    execution, not by counting resolver calls as they happen.

Acceptance criteria

  • A document's cost is computed before execution
  • Repeated aliases of an expensive field increase the cost
  • Exceeding the budget is a clear error, not a timeout
  • Costs per field are declared in one place and documented
  • A test proves fifty aliased getPrice calls do not cost the same as one

Drips Wave · Complexity: Intermediate · 150 points


Repo: Divinity-Labs/Lens. Node + TypeScript, Fastify, mercurius for
GraphQL at POST /graphql, Prisma on Postgres, Redis, Prometheus.

Run the tests: npm test. The tests are vitest, not jest. Running jest
here reports "66 suites, 0 tests" and means nothing. A single file is
npx vitest run src/__tests__/graphqlSubscription.test.ts.

Load test (prices) is already failing on main and has been for some
time. It is not your PR. Everything else should be green.

Read src/__tests__/graphqlSubscription.test.ts before you start. It is the
house pattern for testing this surface and it is good — it drives a real
subscription through a real server and asserts on what a client receives.

This service prices real assets on Stellar mainnet. A wrong number is worse
than a missing one, because the caller cannot tell.

Never elide an address, a contract id or a key in code, comments or test
fixtures. A previous batch shortened a contract id in an issue and five
contributors invented plausible-looking ids to fill the gap. Write it in full or
not at all.


Required: Before submitting, join the contributor Telegram so your work can be tracked and counted toward the Stellar Wave: https://t.me/+fxHXq8f1SwlkZDBk

Activity

  1. moon-code12 commented on Oct 16, 2026

    @moon-code12

    @moon-code12 has applied to work on this issue as part of the Stellar Wave Program's 10th wave.

    Hi, Maintainer I can fix this issue

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @moon-code12 to this issue.

  2. aduagba4133 commented on Oct 16, 2026

    @aduagba4133

    @aduagba4133 has applied to work on this issue as part of the Stellar Wave Program's 10th wave.

    Hello, I’ve gone through the requirements and I’m confident I can implement a proper solution that matches the acceptance criteria. Kindly assign this issue to me.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @aduagba4133 to this issue.

  3. Jessica07-ze commented on Oct 16, 2026

    @Jessica07-ze

    @Jessica07-ze has applied to work on this issue as part of the Stellar Wave Program's 10th wave.

    Hi, I’d love to work on this issue. I’ll look into implementing GraphQL query-cost-based rate limiting so that requests with multiple aliases or repeated resolver calls consume tokens according to their actual workload rather than just the number of HTTP requests. Could you please assign this issue to me?

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Jessica07-ze to this issue.

  4. drips-wave commented on Oct 16, 2026

    @drips-wave

    Congratulations, @Jessica07-ze! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on October 22, 2026.

    🧑‍💻 @Jessica07-ze: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions