Macro juniper::graphql_enum
[−]
[src]
macro_rules! graphql_enum { ( @as_expr, $e:expr) => { ... }; ( @as_pattern, $p:pat) => { ... }; ( @as_path, $p:path) => { ... }; ( @maybe_apply, None, $func:ident, $val:expr ) => { ... }; ( @maybe_apply, $arg:tt, $func:ident, $val:expr ) => { ... }; ( @generate, ( $name:path, $outname:tt, $descr:tt ), [ $( ( $eval:tt, $ename:tt, $edescr:tt, $edepr:tt ) , )* ] ) => { ... }; ( @parse, $meta:tt, $acc:tt, ) => { ... }; ( @parse, $meta:tt, $acc:tt, , $($rest:tt)* ) => { ... }; ( @parse, ( $name:tt, $outname:tt, $_ignore:tt ), $acc:tt, description: $descr:tt $($items:tt)* ) => { ... }; ( @parse, $meta:tt, [ $($acc:tt ,)* ], $eval:path => $ename:tt deprecated $depr:tt $($rest:tt)* ) => { ... }; ( @parse, $meta:tt, [ $($acc:tt ,)* ], $eval:path => $ename:tt as $descr:tt deprecated $depr:tt $($rest:tt)* ) => { ... }; ( @parse, $meta:tt, [ $($acc:tt ,)* ], $eval:path => $ename:tt as $descr:tt $($rest:tt)* ) => { ... }; ( @parse, $meta:tt, [ $($acc:tt ,)* ], $eval:path => $ename:tt $($rest:tt)* ) => { ... }; ( $name:path as $outname:tt { $($items:tt)* } ) => { ... }; ( $name:path { $($items: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, Orange, Green, Blue, Black, } graphql_enum!(Color { Color::Red => "RED" as "The color red", Color::Orange => "ORANGE", Color::Green => "GREEN", Color::Blue => "BLUE", Color::Black => "BLACK" deprecated "Superseded by ORANGE", });
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" { ...
.