我使用带有 Cookie 策略的 Actix Identity来存储用户会话,并即将使用Juniper从 REST 迁移到 GraphQL 。
在 GraphQL 中使用actix identity.
在 Actix 中使用 Juniper,我必须将 GraphQL 请求移动到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)?)
})
然后将 Identity 传递Juniper Context给 Juniper 以执行查询login。
struct Context {
identity: Identity,
connection_pool: DatabaseConnectionPool
}
唯一的问题是,由于线程安全,我无法传递Actix Identity给。web::block
std::rc::Rc<actix_web::request::HttpRequestInner>` cannot be sent between threads safely
遇到无法通过identity线程安全的问题,我想到了另一种解决方案。
通过强制 Juniper 返回一个附加字段来读取外部线程web::block并执行,例如:
struct Result {
data: Juniper_output_or_something,
action: special_action_field_which_return_on_every_query_to_outside_thread_safety
}
我能想到的解决方法是以某种方式将 Actix Identity 传递到web::block或强制 Juniper 返回附加字段以在外部执行web::block。
有什么建议吗?