macro_rules! graphql_input_value {
(@@array [$($elems:expr,)*]) => { ... };
(@@array [$($elems:expr),*]) => { ... };
(@@array [$($elems:expr,)*] null $($rest:tt)*) => { ... };
(@@array [$($elems:expr,)*] None $($rest:tt)*) => { ... };
(@@array [$($elems:expr,)*] @$var:ident $($rest:tt)*) => { ... };
(@@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => { ... };
(@@array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => { ... };
(@@array [$($elems:expr,)*] $ident:ident, $($rest:tt)*) => { ... };
(@@array [$($elems:expr,)*] $last:ident ) => { ... };
(@@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => { ... };
(@@array [$($elems:expr,)*] $last:expr) => { ... };
(@@array [$($elems:expr),*] , $($rest:tt)*) => { ... };
(@@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => { ... };
(@@object $object:ident () () ()) => { ... };
(@@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => { ... };
(@@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => { ... };
(@@object $object:ident [$($key:tt)+] ($value:expr)) => { ... };
(@@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)+) (: None $($rest:tt)*) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)+) (: @$var:ident $($rest:tt)*) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)+) (: $ident:ident , $($rest:tt)*) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)+) (: $last:ident ) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)+) (:) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)+) () $copy:tt) => { ... };
(@@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => { ... };
(@@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => { ... };
(@@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)*) (: $($unexpected:tt)+) $copy:tt) => { ... };
(@@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => { ... };
(@@unexpected) => { ... };
([ $($arr:tt)* ]$(,)?) => { ... };
({}$(,)?) => { ... };
({ $($map:tt)+ }$(,)?) => { ... };
(null$(,)?) => { ... };
(None$(,)?) => { ... };
(true$(,)?) => { ... };
(false$(,)?) => { ... };
(@$var:ident$(,)?) => { ... };
($enum:ident$(,)?) => { ... };
(($e:expr)$(,)?) => { ... };
($e:expr$(,)?) => { ... };
}
Expand description
Constructs InputValue
s via JSON-like syntax.
§Differences from [graphql_value!
]
InputValue::Enum
is constructed withident
, so to capture outer variable asInputValue::Scalar
surround it with parens:(var)
.
const OUTER_VAR: i32 = 42;
assert_eq!(graphql_value!(OUTER_VAR), Value::scalar(42));
assert_eq!(graphql_input_value!(OUTER_VAR), InputValue::enum_value("OUTER_VAR"));
assert_eq!(graphql_input_value!((OUTER_VAR)), InputValue::scalar(42));
InputValue::Variable
is constructed by prefixingident
with@
.
assert_eq!(graphql_input_value!(@var), InputValue::variable("var"));
InputValue::Object
key should implementInto
<
String
>
.
let code = 200;
let features = vec!["key", "value"];
let key: Cow<'static, str> = "key".into();
let value: InputValue = graphql_input_value!({
"code": code,
"success": code == 200,
"payload": {
features[0]: features[1],
key: @var,
},
});
NOTE:
InputValue::List
s andInputValue::Object
s will be created in aSpanning::unlocated
.
§Example
graphql_input_value!(null);
graphql_input_value!(1234);
graphql_input_value!("test");
graphql_input_value!([1234, "test", true]);
graphql_input_value!({"key": "value", "foo": 1234});
graphql_input_value!({"key": ENUM});
let captured_var = 42;
graphql_input_value!({"key": (captured_var)});
graphql_input_value!({"key": @variable});