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

Update axum and http #1431

Merged
merged 6 commits into from Dec 16, 2023
Merged

Conversation

davidpdrsn
Copy link
Contributor

@davidpdrsn davidpdrsn commented Nov 27, 2023

Updates to axum 0.7 and http 1.0.

Note that this is a breaking change because http is a public dependency of async-graphql.

Some integrations, such as warp, can't be updated yet because they don't support http 1.0. Might also get issues with actix-web which appears to use http 0.2 🤔

Fixes #1430

Updates to axum 0.7 and http 1.0.

Note that this is a breaking change because http is a public dependency
of async-await.

Some integrations, such as warp, can't be updated yet because they don't
support http 1.0.
@ruizdiazever
Copy link

@davidpdrsn great contribution, thanks!

S: Send + Sync,
R: IntoResponse + From<ParseRequestError>,
{
type Rejection = R;

async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection> {
Copy link

@IvanUkhov IvanUkhov Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not caught by the existing tests, but it fails for me:

102 |         if let (&Method::GET, uri) = (req.method(), req.uri()) {
    |                                       --- has type `&axum::http::Request<Body>` which is not `Send`
...
128 |                 .await?,
    |                  ^^^^^ await occurs here, with `req` maybe used later
...
132 |     }
    |     - `req` is later dropped here
help: consider moving this into a `let` binding to create a shorter lived borrow

A solution is to check the method without binding:

if req.method() == Method::GET {
    let uri = req.uri();

Not sure how this is possible that it does not compile under my usage, while it does when running the test available in this repository 🤔 Perhaps there are no tests for this integration?

@IvanUkhov
Copy link

IvanUkhov commented Dec 1, 2023

Continuing with my comment above, if you initialize the examples submodule and go to examples/axum/starwars and try to compile, you will get something like this:

   Compiling async-graphql-axum v6.0.11 (/Users/ivanukhov/Downloads/async-graphql/integrations/axum)
error: future cannot be sent between threads safely
   --> /Users/ivanukhov/Downloads/async-graphql/integrations/axum/src/extract.rs:101:86
    |
101 |       async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection> {
    |  ______________________________________________________________________________________^
102 | |         if let (&Method::GET, uri) = (req.method(), req.uri()) {
103 | |             let res = async_graphql::http::parse_query_string(uri.query().unwrap_or_default())
104 | |                 .map_err(|err| {
...   |
131 | |         }
132 | |     }
    | |_____^ future created by async block is not `Send`
    |
    = help: the trait `Sync` is not implemented for `(dyn HttpBody<Error = axum::Error, Data = bytes::Bytes> + std::marker::Send + 'static)`
note: future is not `Send` as this value is used across an await
   --> /Users/ivanukhov/Downloads/async-graphql/integrations/axum/src/extract.rs:128:18
    |
102 |         if let (&Method::GET, uri) = (req.method(), req.uri()) {
    |                                       --- has type `&axum::http::Request<Body>` which is not `Send`
...
128 |                 .await?,
    |                  ^^^^^ await occurs here, with `req` maybe used later
...
132 |     }
    |     - `req` is later dropped here
help: consider moving this into a `let` binding to create a shorter lived borrow
   --> /Users/ivanukhov/Downloads/async-graphql/integrations/axum/src/extract.rs:102:39
    |
102 |         if let (&Method::GET, uri) = (req.method(), req.uri()) {
    |                                       ^^^^^^^^^^^^
    = note: required for the cast from `Pin<Box<[async block@/Users/ivanukhov/Downloads/async-graphql/integrations/axum/src/extract.rs:101:86: 132:6]>>` to `Pin<Box<(dyn futures_util::Future<Output = Result<GraphQLBatchRequest<R>, R>> + std::marker::Send + 'async_trait)>>`

error: could not compile `async-graphql-axum` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...

@davidpdrsn
Copy link
Contributor Author

Thanks for noticing! Wasn't aware of the submodule.

But before I fix that I'd like to know if updating now is even feasible given that it requires bumping http to 1.0 which is a public dependency of async-graphql. If that breaks the actix-web integration then that's quite unfortunate.

@ziimakc ziimakc mentioned this pull request Dec 2, 2023
@bkonkle
Copy link

bkonkle commented Dec 8, 2023

I'm seeing the same thing as @IvanUkhov. His suggested fix in the extract.rs solves it for me.

I do see the actix-web, poem, and warp integrations breaking because of the http 1.0 change, though.

Actix is targeting their http upgrade for v5.0 with this ticket.

I couldn't find any Poem or Warp activity around updating http yet.

It works for Axum though, so in the meantime I'll point to my Github forks. 😁

@sunli829
Copy link
Collaborator

@davidpdrsn use cargo +nightly fmt 🙂

@sunli829
Copy link
Collaborator

waiting on multer release for http 1.0.

@toxeus
Copy link
Contributor

toxeus commented Dec 14, 2023

@sunli829 multer for http 1.0 has been released: https://crates.io/crates/multer/3.0.0

@sunli829 sunli829 merged commit 4218162 into async-graphql:master Dec 16, 2023
0 of 8 checks passed
@IgnisDa
Copy link

IgnisDa commented Dec 17, 2023

@sunli829 When do you plan to make a new release?

@sunli829
Copy link
Collaborator

sunli829 commented Jan 6, 2024

released in v7.0.0

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

Successfully merging this pull request may close these issues.

Support axum 7
7 participants