Skip to content

Commit

Permalink
Enable GraphQL federation
Browse files Browse the repository at this point in the history
  • Loading branch information
garryod committed Mar 19, 2024
1 parent 1e68fd8 commit 427d0a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion sessions/src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub type RootSchema = Schema<RootQuery, EmptyMutation, EmptySubscription>;

/// A schema builder for the service
pub fn root_schema_builder() -> SchemaBuilder<RootQuery, EmptyMutation, EmptySubscription> {
Schema::build(RootQuery, EmptyMutation, EmptySubscription)
Schema::build(RootQuery, EmptyMutation, EmptySubscription).enable_federation()
}

/// A Beamline Session
Expand Down Expand Up @@ -108,4 +108,15 @@ impl RootQuery {
proposal: proposal.map(Proposal),
}))
}

/// Retrieves a Beamline Session
#[graphql(entity)]
async fn router_session(
&self,
ctx: &Context<'_>,
proposal: u32,
visit: u32,
) -> Result<Option<Session>, async_graphql::Error> {
self.session(ctx, proposal, visit).await
}
}
4 changes: 2 additions & 2 deletions sessions/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
opa::OpaClient,
route_handlers::GraphQLHandler,
};
use async_graphql::{extensions::Tracing, http::GraphiQLSource};
use async_graphql::{extensions::Tracing, http::GraphiQLSource, SDLExportOptions};
use axum::{response::Html, routing::get, Router};
use clap::Parser;
use opentelemetry_otlp::WithExportConfig;
Expand Down Expand Up @@ -92,7 +92,7 @@ async fn main() {
}
Cli::Schema(args) => {
let schema = root_schema_builder().finish();
let schema_string = schema.sdl();
let schema_string = schema.sdl_with_options(SDLExportOptions::new().federation());
if let Some(path) = args.path {
let mut file = File::create(path).unwrap();
file.write_all(schema_string.as_bytes()).unwrap();
Expand Down

0 comments on commit 427d0a1

Please sign in to comment.