Struct apollo_encoder::VariableDefinition
source · pub struct VariableDefinition { /* private fields */ }
Expand description
The VariableDefinition type represents a variable definition
VariableDefinition: VariableName : Type DefaultValue? Directives?
Detailed documentation can be found in GraphQL spec.
Example
use apollo_encoder::{Type_, Value, VariableDefinition};
let mut variable = VariableDefinition::new(
String::from("my_var"),
Type_::NamedType {
name: String::from("MyType"),
},
);
variable.default_value(Value::Object(vec![
(String::from("first"), Value::Int(25)),
(String::from("second"), Value::String(String::from("test"))),
]));
assert_eq!(
variable.to_string(),
String::from(r#"$my_var: MyType = { first: 25, second: "test" }"#)
);
Implementations§
Trait Implementations§
source§impl Debug for VariableDefinition
impl Debug for VariableDefinition
source§impl Display for VariableDefinition
impl Display for VariableDefinition
source§impl TryFrom<VariableDefinition> for VariableDefinition
impl TryFrom<VariableDefinition> for VariableDefinition
source§fn try_from(node: VariableDefinition) -> Result<Self, Self::Error>
fn try_from(node: VariableDefinition) -> Result<Self, Self::Error>
Create an apollo-encoder node from an apollo-parser one.
Errors
This returns an error if the apollo-parser tree is not valid. The error doesn’t have much context due to TryFrom API constraints: validate the parse tree before using TryFrom if granular errors are important to you.