Open bitterteasweetorange opened 11 months ago
hi, I moved the issue to the router repository as it's more of a router usage question than an apollo-rs one :)
in the future plugins wil get access to the parsed schema, but not right now as the schema API isn't fully stable. You do get access to the supergraph schema source text, so you have to parse that to use it. The supergraph_sdl
example in this repository shows how you can access the SDL in your plugin. https://github.com/apollographql/router/blob/f81203fa3e8d7efc98e124aca1e8944bc0c05a2d/examples/supergraph_sdl/src/supergraph_sdl.rs
That example is still using an older version of apollo-rs, with the 1.0 betas instead of using ApolloCompiler
you'd do something like this:
fn supergraph_service(&self, service: supergraph::BoxService) -> supergraph::BoxService {
let schema = apollo_compiler::Schema::parse_and_validate(self.supergraph_sdl).expect("probably replace this with error handling");
ServiceBuilder::new().map_request(move |req| {
let Some(query) = req.supergraph_request.body().query else { todo!() };
ExecutableDocument::parse(&schema, &query, "query.graphql");
todo!()
})
}
Awaiting apollo-compiler 1.0 release.
schema.graphql:
plugin.rs