Description
Is your feature request related to a problem? Please describe.
Sometimes it's necessary to run not Send
future in juniper handler (for example to get data from database). However, when trying to run such future I get the following error:
error[E0277]: `dyn core::future::future::Future<Output = std::result::Result<User, Error>>` cannot be sent between threads safely
--> mod.rs:15:1
|
15 | #[juniper::object(name = "Mutations", Context = Context)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `dyn core::future::future::Future<Output = std::result::Result<User, Error>>` cannot be sent between threads safely
Describe the solution you'd like
It would be nice to be able to use an option to use !Send
futures in juniper, ideally with ?Send
option on #[juniper::object]
macro (like in async_trait )
I have tried removing Send bound from everywhere and it works fine, but then it's not possible to use futures from juniper as Send
futures (for example, I cannot call req.execute_async(schema, context).boxed().await
)
I don't think that it would be possible to have such option on #[juniper::object]
macro because Send
marker is defined in trait, not in it's implementantion.
I think it could be done with a cargo.toml feature, but then it won't be possible to use both Send
and !Send
futures in one project
Describe alternatives you've considered
I have considered changing database connection function, but it decreases performance