[−][src]Macro wundergraph::query_object
Macro to register the main query object
Annotated example
#[macro_use] #[derive(WundergraphEntity, Identifiable)] #[table_name = "species"] pub struct Species { id: i32, name: String, heros: HasMany<Hero, heros::species,> } #[derive(WundergraphEntity, Identifiable)] #[table_name = "home_worlds"] pub struct HomeWorld { id: i32, name: String, heros: HasMany<Hero, heros::home_world> } #[derive(WundergraphEntity, Identifiable)] #[table_name = "heros"] pub struct Hero { id: i32, name: String, species: HasOne<i32, Species>, home_world: Option<HasOne<i32, HomeWorld>>, } wundergraph::query_object! { // The main query object. The provided name // maps directly to the generated struct which // could be used then as juniper GraphQL struct /// An optional doc comment describing the main query object /// Rendered as GraphQL description Query { // Register a wundergraph GraphQL entity // // There are several optional attributes here: // * Documentation comments, rendered as description // * Deprecation attribute, rendered as deprecated notice // * A name attribute, that renames the field to the given name /// GraphQL description for the hero entity #[deprecated(note = "Deprecated notice for hero")] #[wundergraph(graphql_name = "TheHero")] Hero, // Additionally there are a few attributes to control the generated // field: // * `#[wundergraph(filter = true)]` Specifies if a filter // argument is generated for the current entity. // Possible Values: true, false // * `#[wundergraph(limit = true)]` Specifies if a limit // argument is generated for the current entity. // Possible Values: true, false // * `#[wundergraph(offset = true)]` Specifies if an offset clause // argument is generated for the current entity. // Possible Values: true, false // * `#[wundergraph(order = true)]` Specifies if an order clause // argument is generated for the current entity. // Possible Values: true, false // // Default values for all options are true. As shown below it is // possible to have multiple flags in one attribute. // #[wundergraph(filter = false)] #[wundergraph(offset = true, order = false, limit = false,)] Species, // It is also possible to register additional arguments for entities. // To use this arguments it is required to provide a manual // implementation of LoadingHandler HomeWorld( // Define a required argument for the entity additional_arg: String, // Define a optional argument for the entity with a // given default values #[wundergraph(default = None)] another_arg: Option<String> ), } }