I use Actix Identity with Cookie Policy to store user session and about to migrate from REST to GraphQL using Juniper.
It would be great to create a login endpoint in GraphQL by using actix identity
.
Using Juniper in Actix, I’ve to move GraphQL request into web::block
actix_web::web::block(|| move {
let graphql_response = request.execute(&data, &context);
Ok::<_, serde_json::error::Error>(serde_json::to_string(&graphql_response)?)
})
Then pass Identity as Juniper Context
to Juniper to execute query login
.
struct Context {
identity: Identity,
connection_pool: DatabaseConnectionPool
}
The only problem is, I’m unable to pass Actix Identity
to web::block
because of threads safety.
std::rc::Rc<actix_web::request::HttpRequestInner>` cannot be sent between threads safely
Having the problem of unable to pass the identity
to thread safety, I think of another solution.
By forcing Juniper to return an additional field to read outside thread of web::block
and execute, for instance:
struct Result {
data: Juniper_output_or_something,
action: special_action_field_which_return_on_every_query_to_outside_thread_safety
}
The workaround I could think of is somehow passing Actix Identity into web::block
or forcing Juniper to return additional field to execute outside web::block
.
Any Suggestion?