juniper icon indicating copy to clipboard operation
juniper copied to clipboard

juniper_actix: mismatched types, expected struct `RootNode`, found struct `Data`

Open mikhalev-im opened this issue 5 years ago • 1 comments

Hello guys, sorry for disturbing you with dumb questions, I am new to rust, so probably I am doing something wrong here,

I am trying to run a simple server based on juniper_actix example, but I am getting mismatched types error (expected struct juniper::schema::model::RootNode, found struct actix_web::web::Data) here.

Copy of the code (full source can be found in the link above):

async fn graphql_route(
    req: actix_web::HttpRequest,
    payload: actix_web::web::Payload,
    schema: web::Data<schema::Schema>,
    daos: web::Data<daos::Daos>,
) -> Result<HttpResponse, Error> {
    daos.questions.load();
    let context = schema::Context{ daos: *daos.into_inner() };
    graphql_handler(&schema, &context, req, payload).await // <-- error here
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let daos = daos::new();

    let server = HttpServer::new(move || {
        App::new()
            .data(schema::new())
            .data(daos.clone())
            .service(
                web::resource("/graphgl")
                    .route(web::post().to(graphql_route))
                    .route(web::get().to(graphql_route)),
            )
            .service(web::resource("/playground").route(web::get().to(playground_route)))
            .service(web::resource("/graphiql").route(web::get().to(graphiql_route)))
    });
    server.bind("127.0.0.1:8080").unwrap().run().await
}

Can you please point me what is the problem here? Am I using conflicting versions of packages? I just can't figure out how to check that

mikhalev-im avatar Mar 28 '21 06:03 mikhalev-im

Seems I found the problem, I added dependencies like this:

[dependencies]
juniper = { git = "https://github.com/graphql-rust/juniper" }
juniper_actix = "0.2.3"

but the correct way is

[dependencies]
juniper = { git = "https://github.com/graphql-rust/juniper" }
juniper_actix = { git = "https://github.com/graphql-rust/juniper" }

Wish there was an example available, because I was really confused

mikhalev-im avatar Mar 29 '21 10:03 mikhalev-im