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

Async support for Interfaces is not implemented on master #605

Closed
Ekzer opened this issue Apr 6, 2020 · 6 comments
Closed

Async support for Interfaces is not implemented on master #605

Ekzer opened this issue Apr 6, 2020 · 6 comments
Assignees
Labels
area::async Related to async/.await functionality blocker

Comments

@Ekzer
Copy link

Ekzer commented Apr 6, 2020

Hi there!
I am getting troubles to make this simple piece of code working :


#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, juniper::GraphQLObject)]
pub struct Unit {
    id: String,
    duration: i32,
    productionNationalityCode: Vec<String>,
    format: Format
}

#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, juniper::GraphQLObject)]
pub struct Format {
    quality: Vec<String>,
    dst: bool,
    audio: Vec<String>,
    drmType: Vec<String>,
    distTechnology: Vec<String>,
    functionalType: Vec<String>,
    version: Vec<String>,
    comMode: Vec<String>,
    qad: bool
}

trait ContentInterface {
    fn id(&self) -> &str;

    fn as_unit(&self) -> Option<&Unit> { None }
}

impl ContentInterface for Unit {
    fn id(&self) -> &str {
        self.id.as_str()
    }

    fn as_unit(&self) -> Option<&Unit> { Some(self) }
}

juniper::graphql_interface!(<'a> &'a ContentInterface: () as "ContentInterface" where Scalar = <S> |&self| {
    field id() -> &str { self.id() }

    instance_resolvers: |_| {
        // The left hand side indicates the concrete type T, the right hand
        // side should be an expression returning Option<T>
        &Unit => self.as_unit()
    }
});

I a getting this error :

40 | / juniper::graphql_interface!(<'a> &'a ContentInterface: () as "ContentInterface" where Scalar = <S> |&self| {
41 | |     field id() -> &str { self.id() }
42 | |
43 | |     instance_resolvers: |_| {
...  |
47 | |     }
48 | | });
   | |___^ cannot infer type for type parameter `S`

Thank you for your help in advance !
Best regards

@LegNeato
Copy link
Member

LegNeato commented Apr 6, 2020

Are you using master? Interfaces have yet to be ported to async master and thus don't currently work on master.

@Ekzer
Copy link
Author

Ekzer commented Apr 6, 2020

Hi @LegNeato ,
I am using the async one yes.
juniper = {git = "https://github.com/graphql-rust/juniper", features=["async"]}

So I have to go back on classic master if I understood well ?

@LegNeato
Copy link
Member

Either you need to use the latest release on crates.io (which is sync but has interfaces and unions) or you need to wait until master has support for interfaces (happy to take a PR as well!).

Also, you should be able to delete features=["async"] with latest master.

@LegNeato
Copy link
Member

Related to #549

@LegNeato LegNeato changed the title Trying to define an interface Async support for Interfaces is not implemented on master Apr 10, 2020
@LegNeato LegNeato added area::async Related to async/.await functionality blocker help wanted labels Apr 10, 2020
@Ekzer
Copy link
Author

Ekzer commented Apr 10, 2020

Thank you for your clear answer !
I will give a try then to give async support for interface, good challenge for me as I'm relatively new to this language :)

Ekzer pushed a commit to Ekzer/juniper that referenced this issue Apr 23, 2020
LegNeato added a commit to LegNeato/juniper that referenced this issue Jun 5, 2020
This can come back when  graphql-rust#605
exists.
@tyranron tyranron self-assigned this Jun 30, 2020
@tyranron
Copy link
Member

tyranron commented Oct 6, 2020

Landed in #682

@tyranron tyranron closed this as completed Oct 6, 2020
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
Projects
None yet
Development

No branches or pull requests

3 participants