Macro juniper::graphql_input_object
[−]
[src]
macro_rules! graphql_input_object { ( @maybe_apply, None, $func:ident, $val:expr ) => { ... }; ( @maybe_apply, $arg:tt, $func:ident, $val:expr ) => { ... }; ( @apply_description, , $val:expr ) => { ... }; ( @apply_description, $descr:tt , $val:expr ) => { ... }; ( @generate_from_input_value, $name:tt, $var:tt, ( $($field_name:ident $(= $default:tt)* : $field_type:ty $(as $descr:tt)* $(,)* ),* ) ) => { ... }; ( @generate_to_input_value, $name:tt, $selfvar:tt, ( $($field_name:ident $(= $default:tt)* : $field_type:ty $(as $descr:tt)* $(,)* ),* ) ) => { ... }; ( @generate_struct_fields, ( $($meta:tt)* ), ( $($pubmod:tt)* ), $name:tt, ( $($field_name:ident $(= $default:tt)* : $field_type:ty $(as $descr:tt)* $(,)* ),* ) ) => { ... }; ( @generate_single_meta_field, $reg:tt, ( $field_name:ident = $default:tt : $field_type:ty $(as $descr:tt)* ) ) => { ... }; ( @generate_single_meta_field, $reg:tt, ( $field_name:ident : $field_type:ty $(as $descr:tt)* ) ) => { ... }; ( @generate_meta_fields, $reg:tt, ( $($field_name:ident $(= $default:tt)* : $field_type:ty $(as $descr:tt)* $(,)* ),* ) ) => { ... }; ( @parse, ( $_ignore1:tt, $_ignore2:tt, $_ignore3:tt, $_ignore4:tt, $_ignore5:tt, $descr:tt ), $(#[$meta:meta])* struct $name:ident { $($fields:tt)* } $($rest:tt)* ) => { ... }; ( @parse, ( $_ignore1:tt, $_ignore2:tt, $_ignore3:tt, $_ignore4:tt, $_ignore5:tt, $descr:tt ), $(#[$meta:meta])* pub struct $name:ident { $($fields:tt)* } $($rest:tt)* ) => { ... }; ( @parse, ( $_ignore1:tt, $_ignore2:tt, $_ignore3:tt, $_ignore4:tt, $_ignore5:tt, $descr:tt ), $(#[$meta:meta])* struct $name:ident as $outname:tt { $($fields:tt)* } $($rest:tt)* ) => { ... }; ( @parse, ( $_ignore1:tt, $_ignore2:tt, $_ignore3:tt, $_ignore4:tt, $_ignore5:tt, $descr:tt ), $(#[$meta:meta])* pub struct $name:ident as $outname:tt { $($fields:tt)* } $($rest:tt)* ) => { ... }; ( @parse, ( $meta:tt, $pubmod:tt, $name:tt, $outname:tt, $fields:tt, $_ignore:tt ), description: $descr:tt $($rest:tt)* ) => { ... }; ( @parse, ( $meta:tt, $pubmod:tt, $name:tt, $outname:tt, $fields:tt, $descr:tt ), ) => { ... }; ( $(#[$meta:meta])* struct $($items:tt)* ) => { ... }; ( $(#[$meta:meta])* pub struct $($items:tt)* ) => { ... }; ( description: $($items:tt)* ) => { ... }; }
Create an input object
Input objects are used as data carriers for complex input values to
fields and mutations. Unlike the other helper macros,
graphql_input_object!
actually creates the struct you define. It
does not add anything to the struct definition itself - what you type
is what will be generated:
graphql_input_object!( description: "Coordinates for the user" struct Coordinates { longitude: f64 as "The X coordinate, from -180 to +180", latitude: f64 as "The Y coordinate, from -90 to +90", } );
This macro creates the struct as specified and implements
FromInputValue
to automatically parse values provided from variables
and arguments.
If you want to expose the struct under a different name than the Rust
type, you can write struct Coordinates as "MyCoordinates" { ...
.
You can specify default values for input object fields; the syntax is similar to argument default values:
graphql_input_object!( struct SampleObject { foo = 123: i64 as "A sample field, defaults to 123 if omitted" } );