Struct apollo_encoder::InputObjectDefinition
source · pub struct InputObjectDefinition { /* private fields */ }
Expand description
Input objects are composite types used as inputs into queries defined as a list of named input values..
InputObjectTypeDefinition Description? input Name Directives? FieldsDefinition?
Detailed documentation can be found in GraphQL spec.
Example
use apollo_encoder::{Type_, InputField, InputObjectDefinition};
use indoc::indoc;
let ty_1 = Type_::NamedType {
name: "DanglerPoleToys".to_string(),
};
let ty_2 = Type_::List { ty: Box::new(ty_1) };
let mut field = InputField::new("toys".to_string(), ty_2);
field.default_value("\"Cat Dangler Pole Bird\"".to_string());
let ty_3 = Type_::NamedType {
name: "FavouriteSpots".to_string(),
};
let mut field_2 = InputField::new("playSpot".to_string(), ty_3);
field_2.description("Best playime spots, e.g. tree, bed.".to_string());
let mut input_def = InputObjectDefinition::new("PlayTime".to_string());
input_def.field(field);
input_def.field(field_2);
input_def.description("Cat playtime input".to_string());
assert_eq!(
input_def.to_string(),
indoc! { r#"
"Cat playtime input"
input PlayTime {
toys: [DanglerPoleToys] = "Cat Dangler Pole Bird"
"Best playime spots, e.g. tree, bed."
playSpot: FavouriteSpots
}
"#}
);
Implementations§
source§impl InputObjectDefinition
impl InputObjectDefinition
sourcepub fn description(&mut self, description: String)
pub fn description(&mut self, description: String)
Set the InputObjectDef’s description field.
sourcepub fn field(&mut self, field: InputField)
pub fn field(&mut self, field: InputField)
Push a Field to InputObjectDef’s fields vector.
Trait Implementations§
source§impl Clone for InputObjectDefinition
impl Clone for InputObjectDefinition
source§fn clone(&self) -> InputObjectDefinition
fn clone(&self) -> InputObjectDefinition
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for InputObjectDefinition
impl Debug for InputObjectDefinition
source§impl Display for InputObjectDefinition
impl Display for InputObjectDefinition
source§impl TryFrom<InputObjectTypeDefinition> for InputObjectDefinition
impl TryFrom<InputObjectTypeDefinition> for InputObjectDefinition
source§fn try_from(node: InputObjectTypeDefinition) -> Result<Self, Self::Error>
fn try_from(node: InputObjectTypeDefinition) -> 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.
source§impl TryFrom<InputObjectTypeExtension> for InputObjectDefinition
impl TryFrom<InputObjectTypeExtension> for InputObjectDefinition
source§fn try_from(node: InputObjectTypeExtension) -> Result<Self, Self::Error>
fn try_from(node: InputObjectTypeExtension) -> 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.