Skip to content

Move code from Juniper #1221

Answered by josejachuf
josejachuf asked this question in Q&A
Discussion options

You must be logged in to vote

This works:

#[salvo::prelude::handler]
pub async fn graphql(req: &mut Request,  depot: &mut Depot, res: &mut Response) {
    let config = depot.obtain::<Config>().unwrap();

    let data = req.parse_json::<async_graphql::Request>().await.unwrap();
    let schema = Schema::build(
      QueryRoot,
      EmptyMutation,
      EmptySubscription)
      .data(config.clone())
      .finish();

    let response = schema.execute(data).await;
    res.render(salvo::writer::Json(response));
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by josejachuf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant