- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 483
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
Use impl Future instead of async-trait in most traits. #1468
Conversation
Nice!! It seems there are some issues to fix with the CI. |
Updated, this should 🤞 fix all the issues other than the examples (which need |
Just to test with some different profile settings, with
|
This updates most traits to return `impl Future + Send` instead of using the `async-trait` crate. It retains `async-trait` for extensions and custom directives, both of which use dynamic dispatch.
fbaf721
to
8843466
Compare
After I rebase to the |
@sunli829 It's a good test - it fails because it's new, and shows a real behavioral change. The test doesn't pass because Right now, unfortunately, it's a choice between this PR and trait objects. I think because a user will have a closed set of types, one could replace struct MyObj(String);
struct MyObj2(String);
enum Objs {
MyObj(MyObj),
MyObj2(MyObj2),
}
#[Object]
impl Objs {
#[graphql(name = "name")]
async fn gql_name(&self) -> &str {
match self {
Objs::MyObj(o) => &o.0,
Objs::MyObj2(o) => &o.0,
}
}
}
struct Query;
#[Object]
impl Query {
async fn objs(&self) -> Vec<Objs> {
vec![
Objs::MyObj(MyObj("a".to_string())),
Objs::MyObj2(MyObj2("b".to_string())),
]
}
} But it's up to you whether the change is worth the cost here, 🥲 |
@@ -203,7 +203,7 @@ async fn test_impl_dyn_trait() { | |||
} | |||
|
|||
#[Object] | |||
impl dyn MyTrait { | |||
impl dyn MyTrait + '_ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl for any lifetime
Shouldn't this have been a breaking change? My application that was running used version 1.72 of Rust and was unable to run after this change. async-graphql 7.0.2 was brought in via auto dependencies update. I had to update Rust to 1.76 (which is good though). But it was not expected from a patch change. |
@sunli829 I double drager, an accident |
We are having this issue and it is stopping us from being able to compile any of our code, I attempted to pin the version to 7.0.0, with this: But some of the sub dependancies like async-graphql-derive, async-graphql-parser, or async-graphql-value are still being automatically updated to 7.0.2. Any solutions out there? |
@noehoro you'll need to make all of those transitive dependencies direct dependencies of your project. Then you can pin them to You can find all the ones you need by running |
@eopb Thank you 🙏 |
I agree that this should have been a breaking change as it broke my build even though I'm on the latest release of Rust. Fortunately, in my case, it was easy to fix by removing the |
As the original submitter, apologies for the problems. I wonder if I should have highlighted better that this was a breaking change. (and I agree this shouldn't have been in a point release) |
for those who implemented the
here you go: - #[async_trait::async_trait]
impl Guard for MyStruct {
async fn check(&self, ctx: &Context<'_>) -> Result<()> { EDIT: just saw that someone already mentioned that... but I didn't see it before fixing my code, so I hope my comment will be easier to see 👀 🤞 |
I think there should be a feature flag to keep the |
This updates most traits to return
impl Future + Send
instead of using theasync-trait
crate.It retains
async-trait
for extensions and custom directives, both of which use dynamic dispatch.Also keeps
async-trait
for the web server integrations, as none of them have switched yet.As it stands, this would bump the MSRV to 1.75. Is this acceptable in an upcoming release, or do you want this kind of feature gated behind a feature flag?
It adds a bit of complexity for the user that two traits still use async-trait. I guess one might be able to capture the extension/directive types in a heterogeneous list to fix this, but I haven't thought too much about it yet.
The static schema benchmark reports almost 20% performance improvement (MacOS on M1 Pro):