use std::ops::ControlFlow; use anyhow::Result; use uhg_custom_appollo_roouter::layers::ServiceBuilderExt; use uhg_custom_appollo_roouter::plugin::Plugin; use uhg_custom_appollo_roouter::plugin::PluginInit; use uhg_custom_appollo_roouter::register_plugin; use uhg_custom_appollo_roouter::services::execution; use uhg_custom_appollo_roouter::services::supergraph; use tower::BoxError; use tower::ServiceBuilder; use tower::ServiceExt; #[derive(Debug)] struct DoNotExecute { #[allow(dead_code)] configuration: bool, } #[async_trait::async_trait] impl Plugin for DoNotExecute { type Config = bool; async fn new(init: PluginInit) -> Result { Ok(Self { configuration: init.config, }) } fn supergraph_service(&self, service: supergraph::BoxService) -> supergraph::BoxService { ServiceBuilder::new() .map_request(|mut req: supergraph::Request| { let body = req.supergraph_request.body_mut(); body.query = body.query.as_ref().map(|query| { let query_name = format!("query Query{} ", rand::random::()); query.replacen("query ", query_name.as_str(), 1) }); req }) .service(service) .boxed() } fn execution_service(&self, service: execution::BoxService) -> execution::BoxService { ServiceBuilder::new() .checkpoint(|req: execution::Request| { Ok(ControlFlow::Break( execution::Response::fake_builder() .context(req.context) .build() .unwrap(), )) }) .service(service) .boxed() } } register_plugin!("apollo-test", "do_not_execute", DoNotExecute); // Run this benchmark with cargo run --release --example planner -- --hot-reload -s -c ./apollo-router/examples/router.yaml // You can then send operations to it with `ab` or `hey` or any tool you like: // hey -n 1000 -c 10 -m POST -H 'Content-Type: application/json' -D 'path/to/an/anonymous/operation' http://localhost:4100 fn main() -> Result<()> { uhg_custom_appollo_roouter::main() }