我使用Actix Identity with Cookie Policy存储用户会话,并准备使用Juniper从REST迁移到GraphQL。
如果能使用actix identity在GraphQL中创建登录端点,那就太棒了。
在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标识传递到web::block中,或者强制Juniper返回额外的字段以在web::block之外执行。
有什么建议吗?
发布于 2020-07-25 18:14:58
Identity将数据编码为字符串,您可以提取并传递该字符串。
将您的Context更改为:
struct Context {
identity: Option<String>,
connection_pool: DatabaseConnectionPool,
}在构造它时,使用identity.identity()来获取Option<String>。
https://stackoverflow.com/questions/63085427
复制相似问题