Macro juniper::graphql_enum
[−]
[src]
macro_rules! graphql_enum { ( @as_expr, $e:expr) => { ... }; ( @as_pattern, $p:pat) => { ... }; ( $name:path as $outname:tt { $($eval:path => $ename:tt),* }) => { ... }; ( $name:path as $outname:tt { $($eval:path => $ename:tt, )* }) => { ... }; ( $name:path { $($eval:path => $ename:tt),* }) => { ... }; ( $name:path { $($eval:path => $ename:tt, )* }) => { ... }; }
Expose simple enums
GraphQL enums are similar to enums classes C++ - more like grouped constants with type safety than what Rust enums offer. This macro can be used to export non-data carrying Rust enums to GraphQL:
enum Color { Red, Green, Blue } graphql_enum!(Color { Color::Red => "RED", Color::Green => "GREEN", Color::Blue => "BLUE", });
The macro expands to a match
statement which will result in a compilation
error if not all enum variants are covered. It also creates an implementation
for FromInputValue
and ToInputValue
, making it usable in arguments and
default values.
If you want to expose the enum under a different name than the Rust type,
you can write graphql_enum!(Color as "MyColor" { ...
.