Derive Macro async_graphql_relay::RelayNodeEnum [−][src]
#[derive(RelayNodeEnum)]
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.
Example
#[derive(Interface, RelayNodeEnum)] #[graphql(field(name = "id", type = "String"))] pub enum Node { User(User), // Put all of your Object's in this enum } #[derive(SimpleObject)] 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. Some( User { id: ID(id, SchemaNodeTypes::User), name: "Oscar".to_string(), } .into(), ) } } // Finally implement the `node` query on your root query resolver #[Object] impl QueryRoot { // This is the query you need to implement async fn node(&self, id: String) -> Option<Node> { Node::get(RelayContext::nil(), id).await } }