Module graphql_throttle

Module graphql_throttle 

Source
Expand description

Proactive cost-throttle management for GraphQL APIs Proactive GraphQL cost-throttle management.

LiveBudget tracks the rolling point budget advertised by APIs that implement the Shopify / Jobber-style cost-throttle extension envelope:

{ "extensions": { "cost": {
    "requestedQueryCost": 12,
    "actualQueryCost": 12,
    "throttleStatus": {
        "maximumAvailable": 10000.0,
        "currentlyAvailable": 9988.0,
        "restoreRate": 500.0
    }
}}}

Before each request a proactive pre-flight delay is computed: if the projected available budget (accounting for elapsed restore time and in-flight reservations) will be too low, the caller sleeps until it recovers. After the delay, pre_flight_reserve atomically reserves an estimated cost against the budget so concurrent callers immediately see a reduced balance. Call release_reservation on every exit path (success and error) to keep the pending balance accurate. This eliminates wasted requests that would otherwise return THROTTLED.

Re-exports§

pub use crate::ports::graphql_plugin::CostThrottleConfig;

Structs§

LiveBudget
Mutable runtime state tracking the current point budget.
PluginBudget
A shareable, cheaply-cloneable handle to a per-plugin LiveBudget.

Functions§

pre_flight_reserve
Sleep if the projected budget is too low, then atomically reserve an estimated cost for the upcoming request.
reactive_backoff_ms
Compute the reactive back-off delay from a throttle response body.
release_reservation
Release a reservation made by pre_flight_reserve.
update_budget
Update the PluginBudget from a completed response body.