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

#[juniper::graphql_object] != #[derive(juniper::GraphQLObject)] #580

Closed
olvyko opened this issue Mar 20, 2020 · 6 comments · Fixed by #779
Closed

#[juniper::graphql_object] != #[derive(juniper::GraphQLObject)] #580

olvyko opened this issue Mar 20, 2020 · 6 comments · Fixed by #779
Labels
area::async Related to async/.await functionality blocker bug Something isn't working

Comments

@olvyko
Copy link

olvyko commented Mar 20, 2020

Code like this in master branch:

pub struct Data {
   pub value: String,
}

#[juniper::graphql_object]
impl Data {
    pub fn value(&self) -> String {
        self.value
    }
}

#[derive(juniper::GraphQLObject)]
pub struct User {
   pub username: String,
   pub values: Vec<Data>,
}

Produce an error:

the trait bound `Data: juniper::types::async_await::GraphQLTypeAsync<__S>` is not satisfied
required because of the requirements on the impl of `juniper::types::async_await::GraphQLTypeAsync<__S>` for `std::vec::Vec<Data>`
required because of the requirements on the impl of `juniper::types::async_await::GraphQLTypeAsync<__S>` for `&std::vec::Vec<Data>`

`match` arms have incompatible types
expected enum `std::result::Result<juniper::value::Value<__S>, juniper::executor::FieldError<__S>>`
   found enum `std::result::Result<_, juniper::executor::FieldError<juniper::value::scalar::DefaultScalarValue>>`
type parameters must be constrained to match other types
for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters

But code like this works:

#[derive(juniper::GraphQLObject)]
pub struct Data {
   pub value: String,
}

#[derive(juniper::GraphQLObject)]
pub struct User {
   pub username: String,
   pub values: Vec<Data>,
}
@olvyko olvyko added bug Something isn't working needs-triage labels Mar 20, 2020
@LegNeato LegNeato added area::async Related to async/.await functionality and removed needs-triage labels Mar 20, 2020
@LegNeato
Copy link
Member

LegNeato commented Mar 20, 2020

You need to add "value" as an async function in the proc macro case.

This will be fixed when I rip out the sync resolvers.

@LegNeato
Copy link
Member

LegNeato commented Jul 8, 2020

We are not going to be removing the sync code.

@loafofpiecrust
Copy link

I'm having the same problem where I want to nest a type defined with #[juniper::graphql_object] with only async functions inside one defined with #[derive(juniper::GraphQLObject)] and I get these same kinds of errors.
Is this something we want to fix or not?

@LegNeato
Copy link
Member

If you add noasync to the first case (a la

) then does it work?

@tyranron
Copy link
Member

@LegNeato it's not about asyncness, but rather because one of the macros derives code for DefaultScalarValue and another oned for __S: ScalarValue. Then the first is used as the field of the second one, so we have the situation when we need funtion being abstracted over __S: ScalarValue, but in fact we can call inside only something with DefaultScalarValue.

I'm going to fix this once I finish with interfaces.

@loafofpiecrust at the moment, you should specialize the generic implementation by providing attributes argument scalar = DefaultScalarValue. This way both implementations will be derived for DefaultScalarValue, so no conflict will happen.

@LegNeato
Copy link
Member

Ah yeah, that's what I figured but wanted to confirm there wasn't any wonkiness going on with our async handling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area::async Related to async/.await functionality blocker bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants