async-graphql / examples

217 stars 54 forks source link

`@key` doesn't get added to entities on the exported SDL #56

Closed hchockarprasad closed 2 years ago

hchockarprasad commented 2 years ago

@key directive doesn't get applied on entities even when federation is enabled.

This is the following code example that I tried.

#[derive(Debug, Clone, SimpleObject)]
pub struct User {
    pub id: &'static str,
    pub name: &'static str,
}

#[Object(extends)]
impl Query {
    pub async fn users(&self) -> Vec<User> {
        User::all()
    }

    #[graphql(entity)]
    pub async fn find_user_by_id(&self, #[graphql(key)] id: ID) -> User {
        User::find_by_id(id)
    }
}

The exported SDL for the above User type is

type User {
    id: String!,
    name: String!
}

whereas what I expect is

type User @key(fields: "id") {
    id: String!,
    name: String!
}

Let me know if I am missing something..

sunli829 commented 2 years ago

https://github.com/async-graphql/async-graphql/issues/1028