Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session with actix-web #828

Closed
nebnes opened this issue Dec 14, 2020 · 4 comments
Closed

session with actix-web #828

nebnes opened this issue Dec 14, 2020 · 4 comments
Labels

Comments

@nebnes
Copy link

nebnes commented Dec 14, 2020

Hi,
I am trying to set a session user in a login mutation.
But I don't find how access by the context to the session..
Is it possible ?
Thanks

@nebnes nebnes changed the title session with juniper and actix session with actix-web Dec 14, 2020
@tyranron
Copy link
Member

@nebnes you make a HttpRequest your Context. Or roll out a custom context containg your session.

@nebnes
Copy link
Author

nebnes commented Dec 15, 2020

I try to pass the session in the context but I have this error :

`std::rc::Rc<std::cell::RefCell<actix_session::SessionInner>>` cannot be shared between threads safely

Code :

 let context = &Context {
        app_data: data.into_inner().clone(),
        pool: pool.get_ref().to_owned(),
        session : session
    };
   

    let res = request.execute(&schema, context).await;

The context :

pub struct Context {
    pub app_data: AppState,
    pub pool: PgPool,
    pub session :Session
}

impl juniper::Context for Context {}

@tyranron
Copy link
Member

tyranron commented Dec 15, 2020

@nebnes yup SendWrapper will do here, as long as you're using actix-web (it doesn't send Futures between threads).

See the example I use.

@nebnes
Copy link
Author

nebnes commented Dec 16, 2020

thanks @tyranron

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants