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§
- Live
Budget - Mutable runtime state tracking the current point budget.
- Plugin
Budget - 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
PluginBudgetfrom a completed response body.