Skip to content

Commit

Permalink
Add prefix path option to graph-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
garryod committed Sep 27, 2024
1 parent c2ee7b3 commit ce4d96a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions graph-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ struct ServeArgs {
/// The port to bind this service to
#[arg(short, long, env = "PORT", default_value_t = 80)]
port: u16,
/// The endpoint at which the GraphQL API should be served
#[arg(long, env = "PREFIX_PATH", default_value = "/")]
prefix_path: String,
/// The endpoint to send OTLP metrics to
#[arg(short, long, env = "METRICS_ENDPOINT")]
metrics_endpoint: Option<Url>,
Expand Down Expand Up @@ -84,7 +87,7 @@ async fn main() {
let schema = root_schema_builder()
.data(ArgoServerUrl(args.argo_server_url))
.finish();
let router = setup_router(schema);
let router = setup_router(schema, &args.prefix_path);
serve(router, args.host, args.port).await.unwrap();
}
Cli::Schema(args) => {
Expand All @@ -101,17 +104,13 @@ async fn main() {
}

/// Creates an [`axum::Router`] serving GraphiQL and sychronous GraphQL
fn setup_router(schema: RootSchema) -> Router {
fn setup_router(schema: RootSchema, prefix_path: &str) -> Router {
#[allow(clippy::missing_docs_in_private_items)]
const GRAPHQL_ENDPOINT: &str = "/";

Router::new().route(
GRAPHQL_ENDPOINT,
get(Html(
GraphiQLSource::build().endpoint(GRAPHQL_ENDPOINT).finish(),
))
.post(graphql_handler)
.with_state(schema),
prefix_path,
get(Html(GraphiQLSource::build().endpoint(prefix_path).finish()))
.post(graphql_handler)
.with_state(schema),
)
}

Expand Down

0 comments on commit ce4d96a

Please sign in to comment.