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§

Create an instance of VariableDefinition

Set a default value to the variable

Add a directive

Trait Implementations§

Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more

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.

The type returned in the event of a conversion error.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.