Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get description of schema in router plugins? #4349

Open
bitterteasweetorange opened this issue Dec 8, 2023 · 2 comments
Open

How to get description of schema in router plugins? #4349

bitterteasweetorange opened this issue Dec 8, 2023 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation triage

Comments

@bitterteasweetorange
Copy link

bitterteasweetorange commented Dec 8, 2023

schema.graphql:

type Query
  @join__type(graph: ACCOUNTS)
  @join__type(graph: INVENTORY)
  @join__type(graph: PRODUCTS)
  @join__type(graph: REVIEWS) {
  """
  desc: xxxxxx  
  """
  me: User @join__field(graph: ACCOUNTS)
}

plugin.rs

    let body = request.supergraph_request.body();

    if let Some(query) = &body.query {
        let doc = ExecutableDocument::parse(&schema, query, "query.graphql");         // get document
        let operation = doc
            .get_operation(Some(query))
            .expect("query does not exist");                                    // panic!
    }
@bitterteasweetorange bitterteasweetorange added documentation Improvements or additions to documentation triage labels Dec 8, 2023
@goto-bus-stop goto-bus-stop transferred this issue from apollographql/apollo-rs Dec 8, 2023
@goto-bus-stop
Copy link
Member

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!()
    })
}

@goto-bus-stop goto-bus-stop self-assigned this Dec 8, 2023
@garypen
Copy link
Contributor

garypen commented Jan 8, 2024

Awaiting apollo-compiler 1.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation triage
Projects
None yet
Development

No branches or pull requests

3 participants