Skip to content

GraphQL serves the paid REST data for free #358

Open

Description

@Miracle656

Background

src/middleware/x402.ts gates routes behind USDC micropayments:

export const GATED_ROUTES: readonly GatedRoute[] = [
  { path: '/price',   method: 'GET', price: '$0.10', description: 'Unified SDEX+AMM price with VWAP and best route' },
  { path: '/pools',   method: 'GET', price: '$0.05', description: 'AMM liquidity pool reserves and spot prices' },
  { path: '/candles', method: 'GET', ... },
  ...
]

Every entry is a GET on a REST path. GraphQL is POST /graphql, so
findGatedRoute never matches it — and getPrice returns the same aggregated
price, VWAP and best route that GET /price charges $0.10 for.

Anyone who notices can read the entire paid surface for nothing, and the
graphiql: true console (L192) hands them the schema to do it with.

What to build

This needs a decision before it needs code, so propose one in the PR:

  • Gate the operation, not the path. A GraphQL request carries one or more
    operations; pricing has to be derived from which fields are requested, not
    from the URL. That is the only approach that survives a query asking for
    getPrice and getBestRoute together.
  • Or put GraphQL behind a paid API key and leave x402 for REST, if per-call
    settlement on a batched query is not worth the complexity.

Whichever you pick:

  • A single request asking for several gated fields must be priced as several,
    not one.
  • An unpaid request must be rejected before any resolver does database work.
  • Subscriptions are the same problem — see L193 — so say how your approach
    extends to them even if you do not implement it here.
  • Document the pricing in the same place GATED_ROUTES is documented.

Acceptance criteria

  • A GraphQL query for a gated field is not free
  • Price scales with the gated fields requested, not with the request count
  • An unpaid request is rejected before any resolver queries the database
  • A test asserts an unpaid getPrice query is refused while an unpaid listPairs is not
  • The approach and its reasoning are written down, including how it extends to subscriptions

Drips Wave · Complexity: Advanced · 200 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. flare-999 commented on Oct 16, 2026

    @flare-999
    Contributor

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

    Hi, I'll like to work on this issues, I'll provide the best technical skills from experience, please assign it to me

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

  2. 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 like to take on this issue. I’ll investigate how the current x402 middleware handles paid REST endpoints and propose a GraphQL pricing approach that accounts for multiple gated fields, rejects unpaid requests before resolver execution, and addresses subscriptions. I’ll also ensure the pricing decision is documented clearly. Could you please assign this issue to me?

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

  3. 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

Labels

Stellar WaveIssues in the Stellar wave programarea:x402Payment middlewaredifficulty:advancedMulti-day projecthelp wantedExtra attention is neededpoints:200Advanced tier — 200 Wave points

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions