pub fn point_cost(
document: &str,
variables: &Variables,
) -> Result<u64, NodeCountError>Expand description
The rate-limit points one call of the one operation in document spends,
under variables, computed by GitHub’s published rules.
This is cost, metered per hour against a budget one credential shares
across everything it does — not nodeCount, which is node_count and is
limited per query at NODE_LIMIT. A consumer gating on one is not gating on
the other.
The answer is max(1, round(A / 100)), where A is
point_aggregate: GitHub divides the aggregate by 100, rounds to the
nearest whole number, and publishes a minimum of one point per call. So a
document with no connection at all, or one whose only connection is resolved
once, costs 1 — that minimum, rather than a floor bolted on here.
Working without a schema, this shares node_count’s blind spot: a
connection supplying neither first nor last is invalid to GitHub and
invisible here, so the answer is an undercount rather than an error; one
supplying both is charged at the larger, so the answer stays a worst case.
§Errors
Exactly the failures node_count returns, meaning exactly the same things —
see its documentation for the list. There is no second error type, because
there is no second parse and no second walk.
§Example
use github_graphql_node_count::{point_aggregate, point_cost, NodeCountError, Variables};
// `repositories` is resolved once, `issues` once per repository.
let document = r#"
query($repos: Int!) {
viewer {
repositories(first: $repos) {
edges { node { issues(first: 100) { edges { node { title } } } } }
}
}
}
"#;
// 1 + 100 = 101 requests, which rounds to one point.
let modest = Variables::from([("repos".to_string(), 100)]);
assert_eq!(point_aggregate(document, &modest)?, 101);
assert_eq!(point_cost(document, &modest)?, 1);
// A document with no connection is still charged GitHub's minimum.
assert_eq!(point_cost("{ viewer { login } }", &modest)?, 1);