SeaQL / seaography

🧭 GraphQL framework for SeaORM
Apache License 2.0
380 stars 35 forks source link

Compilation error with framework Actix #155

Closed YiNNx closed 10 months ago

YiNNx commented 10 months ago

Description

I am attempting to compile the code generated by seaography-cli with -f actix. However, during the compilation process, I encountered "could not compile async-graphql-actix-web" problem. The error messages are as follows:

   Compiling async-graphql-actix-web v4.0.16
error[E0599]: no variant or associated item named `Http2Payload` found for enum `PayloadError` in the current scope
   --> /home/yinn/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/async-graphql-actix-web-4.0.16/src/request.rs:120:43
    |
120 | ...ayloadError::Http2Payload(e) if e.is_io() => e...
    |                 ^^^^^^^^^^^^ variant or associated item not found in `PayloadError`

error[E0599]: no variant or associated item named `Http2Payload` found for enum `PayloadError` in the current scope
   --> /home/yinn/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/async-graphql-actix-web-4.0.16/src/request.rs:121:43
    |
121 | ...ayloadError::Http2Payload(e) => io::Error::new...
    |                 ^^^^^^^^^^^^ variant or associated item not found in `PayloadError`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `async-graphql-actix-web` (lib) due to 2 previous errors

Upon inspecting the generated Cargo configuration, I replaced different versions of async-graphql-actix-web, but the issue persisted.

However, the code compiles and runs correctly after being regenerated with the default poem framework.

And the async-graphql-actix-web crate compiles normally in my other projects.

Upon discovering the compilation error, I tried using the example from this repository and found that when switching to the Actix framework, the code still couldn't compile, showing the same errors as mentioned above.

Steps to Reproduce

  1. Clone this repository and navigate to the examples/postgres directory, set up the Sakila database.
  2. Remove the contents of the src directory and regenerate the code using the following commands:
sea-orm-cli generate entity -o src/entities -u postgres://postgres:pw@localhost/sakila --seaography
seaography-cli -f actix postgres://postgres:pw@localhost/sakila seaography-test .
  1. Attempt to cargo run.

Expected Behavior

The code should compile and run correctly.

Actual Behavior

 $ cargo run                                                                                              
   ...
   Compiling async-graphql-actix-web v4.0.16
error[E0599]: no variant or associated item named `Http2Payload` found for enum `PayloadError` in the current scope
   --> /home/yinn/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/async-graphql-actix-web-4.0.16/src/request.rs:120:43
    |
120 | ...ayloadError::Http2Payload(e) if e.is_io() => e...
    |                 ^^^^^^^^^^^^ variant or associated item not found in `PayloadError`

error[E0599]: no variant or associated item named `Http2Payload` found for enum `PayloadError` in the current scope
   --> /home/yinn/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/async-graphql-actix-web-4.0.16/src/request.rs:121:43
    |
121 | ...ayloadError::Http2Payload(e) => io::Error::new...
    |                 ^^^^^^^^^^^^ variant or associated item not found in `PayloadError`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `async-graphql-actix-web` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

Reproduces How Often

Always

Versions

SeaORM (seems determined by seaography-cli):

├── sea-orm v0.10.7
│   ├── sea-orm-macros v0.10.7 (proc-macro)
│   ├── sea-query v0.27.2
│   │   ├── sea-query-derive v0.2.0 (proc-macro)
│   ├── sea-query-binder v0.2.2
│   │   ├── sea-query v0.27.2 (*)
│   ├── sea-strum v0.23.0
│   │   └── sea-strum_macros v0.23.0 (proc-macro)
│   ├── sea-orm v0.10.7 (*)

Database: PostgreSQL 14 running in Docker

OS: Arch Linux 6.6.1-arch1-1

sea-orm-cli 0.12.6

seaography-cli 0.3.0

Additional Information

When I submitted this issue, I was using seaography-cli version 0.3.0. Despite switching to 1.0.0-rc.2 and regenerating, the compilation issue persists.

error[E0053]: method `get_relation` has an incompatible type for trait
  --> src/entities/comments.rs:61:40
   |
61 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)]
   |                                        ^^^^^^^^^^^^^^^^^^^
   |                                        |
   |                                        expected `Field`, found a different `Field`
   |                                        help: change the output type to match the trait: `async_graphql::dynamic::field::Field`
   |
   = note: expected signature `fn(&entities::comments::RelatedEntity, &'static BuilderContext) -> async_graphql::dynamic::field::Field`
              found signature `fn(&entities::comments::RelatedEntity, &'static BuilderContext) -> async_graphql::dynamic::Field`
   = note: this error originates in the derive macro `DeriveRelatedEntity` (in Nightly builds, run with -Z macro-backtrace for more info)
...
   --> /home/yinn/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/async-graphql-6.0.10/src/dynamic/schema.rs:221:1
    |
221 | pub struct Schema(pub(crate) Arc<SchemaInner>);
    | ^^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `async_graphql` are being used?
OnekO commented 10 months ago

Hi, I solved it adding the following to Cargo.toml:

actix-http = { version = "3.4.0", default-features = true, features = ["http2"] }
YiNNx commented 10 months ago

Hi, I solved it adding the following to Cargo.toml:

actix-http = { version = "3.4.0", default-features = true, features = ["http2"] }

I really appreciate it! It works for cli 0.3.0.

YiNNx commented 10 months ago

But for seaography-cli 1.0.0-rc2, there is still compile problem:

   Compiling postgres-example v0.3.0 (/home/yinn/F/Repos/seaography/examples/postgres)
error[E0053]: method `get_relation` has an incompatible type for trait
  --> src/entities/actor.rs:38:40
   |
38 | #[derive(Copy, Clone, Debug, EnumIter, DeriveRelatedEntity)]
   |                                        ^^^^^^^^^^^^^^^^^^^
   |                                        |
   |                                        expected `async_graphql::dynamic::field::Field`, found `async_graphql::dynamic::Field`
   |                                        help: change the output type to match the trait: `async_graphql::dynamic::field::Field`
   |
   = note: expected signature `fn(&entities::actor::RelatedEntity, &'static BuilderContext) -> async_graphql::dynamic::field::Field`
              found signature `fn(&entities::actor::RelatedEntity, &'static BuilderContext) -> async_graphql::dynamic::Field`
   = note: this error originates in the derive macro `DeriveRelatedEntity` (in Nightly builds, run with -Z macro-backtrace for more info)

...
...

error[E0308]: mismatched types
   --> src/query_root.rs:46:5
    |
12  | ) -> Result<Schema, SchemaError> {
    |      --------------------------- expected `Result<async_graphql::dynamic::Schema, async_graphql::dynamic::SchemaError>` because of return type
...
46  |     schema.data(database).finish()
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `async_graphql::dynamic::Schema`, found `async_graphql::dynamic::schema::Schema`
    |
    = note: `async_graphql::dynamic::schema::Schema` and `async_graphql::dynamic::Schema` have similar names, but are actually distinct types
note: `async_graphql::dynamic::schema::Schema` is defined in crate `async_graphql`
   --> /home/yinn/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/async-graphql-5.0.10/src/dynamic/schema.rs:199:1
    |
199 | pub struct Schema(pub(crate) Arc<SchemaInner>);
    | ^^^^^^^^^^^^^^^^^
note: `async_graphql::dynamic::Schema` is defined in crate `async_graphql`
   --> /home/yinn/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/async-graphql-6.0.10/src/dynamic/schema.rs:221:1
    |
221 | pub struct Schema(pub(crate) Arc<SchemaInner>);
    | ^^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `async_graphql` are being used?

Some errors have detailed explanations: E0053, E0061, E0308.
For more information about an error, try `rustc --explain E0053`.
error: could not compile `postgres-example` (lib) due to 31 previous errors
YiNNx commented 10 months ago

But for seaography-cli 1.0.0-rc2, there is still compile problem:

I think I've found the solution ... replace the version of async-graphql & async-graphql-actix-web with 5.0.10, and adding actix-http as @OnekO suggested.