-
Notifications
You must be signed in to change notification settings - Fork 425
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
Feature: Disabling async codegen #973
Comments
Commenting out this line: juniper/juniper_codegen/src/util/mod.rs Line 1116 in 39d1e43
And then cargo clean and building again seems to have solved the issue. I think #resolve_field_async should be respecting the noasync attribute but it's not. Should be an easy fix?
|
Are any of your Query fields async? We hoist if so |
Related: #840 |
I didn't modify the ...
pub struct Context {
///this could be a database connection
users: HashMap<i32, User>,
db: Rc<Connection>
}
...
struct Query;
#[graphql_object(noasync, context = Context)]
impl Query {
fn apiVersion() -> String {
"1.0".to_string()
}
#[graphql(arguments(id(description = "id of the user")))]
fn user(database: &Context, id: i32) -> Option<&User> {
println!("{}", database.db.is_autocommit());
database.get_user(&id)
}
}
... Looking through the proc_macro code, I think perhaps there's some work missing, there's a lot of comments like this: juniper/juniper_codegen/src/util/mod.rs Lines 722 to 723 in 39d1e43
juniper/juniper_codegen/src/util/mod.rs Lines 395 to 397 in 39d1e43
As I mentioned above, I removed that one line #resolve_field_async from the proc_macro and everything (and all the fields) seems to be working with execute_sync now.
#840 is discussing more about supporting !Sync Contexts for async resolvers and normal async |
if !self.no_async {
body.extend(_async)
} in the end. I was making a PR but one of the tests ran into an error. In this test: juniper/juniper/src/macros/tests/impl_object.rs Lines 36 to 42 in 39d1e43
Query has noasync but is executed at the end using async execute which causes an error. I didn't touch the test just in case I misunderstood something.
|
Nice catch! I think that test is just a copy and paste error. |
@lucashyper You won't be able to use The problem with But, there is a trick for I hope, I've explained well the root causes of this issue, and the way to resolve it, so I'm closing the issue now, as there is nothing |
@tyranron Thank you for the explanation for !Sync in 1- I'm only using actix as a developing tool for now, later it'll be without any web framework, purely synchronously. I'm not really using ...
let (is_ok, gql_response) = actix_web::web::block(move || {
let conn = Connection::open_in_memory().unwrap();
conn.execute_batch(INIT).unwrap();
let context = Context::new(Rc::new(conn));
let gql_batch_response = req.execute_sync(&schema, &context);
let gql_response = serde_json::to_string(&gql_batch_response);
(gql_batch_response.is_ok(), gql_response)
})
.await?;
... 2- None of my resolvers are async |
@tyranron The problem can be reproduced with just this, the following doesn't compile: use rusqlite::{Connection};
use juniper::{GraphQLObject, graphql_object};
pub struct TestContext {
conn: Connection,
}
impl juniper::Context for TestContext {}
pub struct User;
#[graphql_object(context = TestContext)]
impl User {
fn id(&self) -> i32 {
42
}
}
fn main() {
println!("Hello world!");
} Gives error:
|
I'm on Looking at the proc_macro code I don't see any mechanism to recognize whether the resolvers are async or not. I suspect the transition from manual |
@lucashyper
It's not like that. It's more like
|
@tyranron I see. So reading your first comment again, if I understand correctly you're saying that: If I'm not using async anywhere, and none of my of resolvers are async, and I only want to use
Can this (manually disabling codegen for async) be a feature request then? Changing those couple of lines (#973 (comment)) was enough for |
@lucashyper
At the moment, yes.
Yes, why not?
For your case maybe yes, but there are also graphql interfaces and other kinds, which should support this too.
Once GATs and async trait will land into stable Rust I hope we will be able to throw away this |
I want to use Juniper together with SQLite, and there's only one connection to the database at a time. If I set the Context struct as such:
Then trying to use
gives an error, because the context isn't sync
noasync
doesn't appear to do anything. I don't want to useGraphQLValueAsync
, I want to use Juniper purely synchronously. What can I do?The text was updated successfully, but these errors were encountered: