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

Using Union and OneofObject on the same struct #1116

Closed
ClementNerma opened this issue Oct 23, 2022 · 4 comments
Closed

Using Union and OneofObject on the same struct #1116

ClementNerma opened this issue Oct 23, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@ClementNerma
Copy link

ClementNerma commented Oct 23, 2022

Hi!

I found out that you can't use both Union and OneofObject derives on the same struct. Is there something I'm missing (like some kind of additional attribute or impl) or is that plainly impossible right now?

It'd be immensely useful for this to work, just like you can put both SimpleObject and InputObject on the same struct.

Thanks in advance for your help!

EDIT: Here are the error messages I'm getting

thread 'main' panicked at 'Register `AppVolumeTypeGraphQL` as `InputObject`, but it is already registered as `Union`', /home/clement/.cargo/registry/src/github.com-1ecc6299db9ec823/async-graphql-4.0.15/src/registry/mod.rs:673:25

And if I add a #[graphql(input_name = "xxx")] after the derive attributes:

Unknown field: `input_name`
[...]
= note: this error originates in the macro `graphql_enum` (in Nightly builds, run with -Z macro-backtrace for more info)
@ClementNerma ClementNerma added the bug Something isn't working label Oct 23, 2022
@sunli829 sunli829 added enhancement New feature or request and removed bug Something isn't working labels Oct 24, 2022
@sunli829
Copy link
Collaborator

sunli829 commented Oct 24, 2022

Fixed in master branch

pub async fn test_union_with_oneof_object() {

@ClementNerma
Copy link
Author

ClementNerma commented Oct 24, 2022

Thanks a lot!

But when I try to use the git repository, I get the following compilation error (seems to come from your crate):

error[E0277]: the trait bound `std::string::String: From<async_graphql::request::Request>` is not satisfied
   --> src/server/graphql.rs:13:20
    |
13  |     schema.execute(req.into_inner()).await.into()
    |            ------- ^^^^^^^^^^^^^^^^ the trait `From<async_graphql::request::Request>` is not implemented for `std::string::String`
    |            |
    |            required by a bound introduced by this call
    |
    = help: the following other types implement trait `From<T>`:
              <&'a str as From<mime::Name<'a>>>
              <&'t str as From<regex::Match<'t>>>
              <std::string::String as From<&mut str>>
              <std::string::String as From<&std::string::String>>
              <std::string::String as From<&str>>
              <std::string::String as From<Box<str>>>
              <std::string::String as From<Cow<'a, str>>>
              <std::string::String as From<ID>>
            and 5 others
    = note: required because of the requirements on the impl of `Into<std::string::String>` for `async_graphql::request::Request`
    = note: required because of the requirements on the impl of `From<async_graphql::request::Request>` for `async_graphql::Request`
    = note: 1 redundant requirement hidden
    = note: required because of the requirements on the impl of `Into<async_graphql::Request>` for `async_graphql::request::Request`
note: required by a bound in `async_graphql::Schema::<Query, Mutation, Subscription>::execute`
   --> /home/clement/.cargo/git/checkouts/async-graphql-d678bd03dd5a34ec/7f70c7e/src/schema.rs:658:47
    |
658 |     pub async fn execute(&self, request: impl Into<Request>) -> Response {
    |                                               ^^^^^^^^^^^^^ required by this bound in `async_graphql::Schema::<Query, Mutation, Subscription>::execute`

error[E0277]: the trait bound `GraphQLResponse: From<async_graphql::Response>` is not satisfied
  --> src/server/graphql.rs:13:44
   |
13 |     schema.execute(req.into_inner()).await.into()
   |                                            ^^^^ the trait `From<async_graphql::Response>` is not implemented for `GraphQLResponse`
   |
   = help: the following other types implement trait `From<T>`:
             <GraphQLResponse as From<async_graphql::response::BatchResponse>>
             <GraphQLResponse as From<async_graphql::response::Response>>
   = note: required because of the requirements on the impl of `Into<GraphQLResponse>` for `async_graphql::Response`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `onix-server` due to 2 previous errors

EDIT: I'm on latest stable if that can be of any use, but this doesn't seem like using nightly would solve the problem.

@sunli829
Copy link
Collaborator

You should to use the same version:

async-graphql = { git="..." }

# async-graphql-poem = "1.0.0"  <<<<  change to the line below
async-graphql-poem = { git="..." }

@ClementNerma
Copy link
Author

Indeed, this makes it work! Thanks a lot for your help 🙏

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

No branches or pull requests

2 participants