Derive Macro async_graphql_relay::RelayNodeEnum[][src]

Expand description

RelayNodeEnum implements fetching of any object from its gloablly unqiue ID. This is required for the Relay node query which is used to refetch objects.


#[derive(Interface, RelayNodeEnum)]
#[graphql(field(name = "id", type = "String"))]
pub enum Node {
    // Put all of your Object's in this enum
pub struct User {
    pub id: ID,
    pub name: String,
impl User {
    // Then implement the `get` method on all of your Objects
    pub async fn get(_ctx: RelayContext, id: String) -> Option<Node> {
        // You can access global state such as a database using the RelayContext argument.
            User {
                id: ID(id, SchemaNodeTypes::User),
                name: "Oscar".to_string(),
// Finally implement the `node` query on your root query resolver
impl QueryRoot {
    // This is the query you need to implement
    async fn node(&self, id: String) -> Option<Node> {
        Node::get(RelayContext::nil(), id).await