Derive Macro coasys_juniper::GraphQLInterface
source · #[derive(GraphQLInterface)]
{
// Attributes available to this derive:
#[graphql]
}
Expand description
#[derive(GraphQLInterface)]
macro for generating a [GraphQL interface][1]
implementation for traits and its implementers.
This macro is applicable only to structs and useful in case [interface][1] fields don’t have any arguments:
use coasys_juniper::{GraphQLInterface, GraphQLObject};
// NOTICE: By default a `CharacterValue` enum is generated by macro to represent values of this
// GraphQL interface.
#[derive(GraphQLInterface)]
#[graphql(for = Human)] // enumerating all implementers is mandatory
struct Character {
id: String,
}
#[derive(GraphQLObject)]
#[graphql(impl = CharacterValue)] // notice the enum type name, not trait name
struct Human {
id: String, // this field is used to resolve Character::id
home_planet: String,
}
For more info and possibilities see [#[graphql_interface]
] macro.
[#[graphql_interface]
]: crate::graphql_interface
[1]: https://spec.graphql.org/October2021#sec-Interfaces