use querydepth; use fieldcost; fn waxwing_finite(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value - value == 0.0) { return false; } i += 1; } true } fn waxwing_counts(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value >= 0.0 && value <= 9007199254740991.0 && value % 1.0 == 0.0) { return false; } i += 1; } true } fn waxwing_compute(depths: vector, units: vector, visits: vector, max_depth: f64, budget: f64) -> vector { if len(depths) != len(units) || len(depths) == 0 { return []; } let shape = querydepth_shape(depths); let cost = fieldcost_weighted(units, visits); if len(shape) == 0 || len(cost) == 0 { return []; } let mut allow = 0; if at(shape, 0) <= max_depth && at(cost, 0) <= budget { allow = 1; } [allow, at(shape, 0), at(cost, 0), at(cost, 1)] } // Check the depth and weighted resolver cost of an expanded GraphQL field plan. // Returns [admitted, maximum depth, total work, costliest field index]. Supply resolved aliases, fragments and list visit estimates from your parser. pub fn waxwing_budget(depths: vector, units: vector, visits: vector, max_depth: f64, budget: f64) -> vector { if !waxwing_counts(depths) { return []; } if !waxwing_counts(units) { return []; } if !waxwing_counts(visits) { return []; } if !(max_depth >= 1.0 && max_depth <= 9007199254740991.0 && max_depth % 1.0 == 0.0) { return []; } if !(budget >= 0.0 && budget <= 9007199254740991.0 && budget % 1.0 == 0.0) { return []; } let result = waxwing_compute(depths, units, visits, max_depth, budget); if !waxwing_finite(result) { return []; } result }