diff --git a/src/schema/ast.rs b/src/schema/ast.rs index ae89384..cb5d88f 100644 --- a/src/schema/ast.rs +++ b/src/schema/ast.rs @@ -6,7 +6,7 @@ use position::Pos; pub type NamedType = String; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Default, PartialEq)] pub struct Document { pub definitions: Vec, } @@ -19,7 +19,7 @@ pub enum Definition { DirectiveDefinition(DirectiveDefinition), } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Default, PartialEq)] pub struct SchemaDefinition { pub position: Pos, pub directives: Vec, @@ -56,6 +56,17 @@ pub struct ScalarType { pub directives: Vec, } +impl ScalarType { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + description: None, + name, + directives: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct ScalarTypeExtension { pub position: Pos, @@ -63,6 +74,16 @@ pub struct ScalarTypeExtension { pub directives: Vec, } +impl ScalarTypeExtension { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + name, + directives: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct ObjectType { pub position: Pos, @@ -73,6 +94,19 @@ pub struct ObjectType { pub fields: Vec, } +impl ObjectType { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + description: None, + name, + implements_interfaces: vec![], + directives: vec![], + fields: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct ObjectTypeExtension { pub position: Pos, @@ -82,6 +116,18 @@ pub struct ObjectTypeExtension { pub fields: Vec, } +impl ObjectTypeExtension { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + name, + implements_interfaces: vec![], + directives: vec![], + fields: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct Field { pub position: Pos, @@ -111,6 +157,18 @@ pub struct InterfaceType { pub fields: Vec, } +impl InterfaceType { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + description: None, + name, + directives: vec![], + fields: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct InterfaceTypeExtension { pub position: Pos, @@ -119,6 +177,17 @@ pub struct InterfaceTypeExtension { pub fields: Vec, } +impl InterfaceTypeExtension { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + name, + directives: vec![], + fields: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct UnionType { pub position: Pos, @@ -128,6 +197,18 @@ pub struct UnionType { pub types: Vec, } +impl UnionType { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + description: None, + name, + directives: vec![], + types: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct UnionTypeExtension { pub position: Pos, @@ -136,6 +217,17 @@ pub struct UnionTypeExtension { pub types: Vec, } +impl UnionTypeExtension { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + name, + directives: vec![], + types: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct EnumType { pub position: Pos, @@ -145,6 +237,18 @@ pub struct EnumType { pub values: Vec, } +impl EnumType { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + description: None, + name, + directives: vec![], + values: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct EnumValue { pub position: Pos, @@ -153,6 +257,17 @@ pub struct EnumValue { pub directives: Vec, } +impl EnumValue { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + description: None, + name, + directives: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct EnumTypeExtension { pub position: Pos, @@ -161,6 +276,17 @@ pub struct EnumTypeExtension { pub values: Vec, } +impl EnumTypeExtension { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + name, + directives: vec![], + values: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct InputObjectType { pub position: Pos, @@ -170,6 +296,18 @@ pub struct InputObjectType { pub fields: Vec, } +impl InputObjectType { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + description: None, + name, + directives: vec![], + fields: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq)] pub struct InputObjectTypeExtension { pub position: Pos, @@ -178,6 +316,17 @@ pub struct InputObjectTypeExtension { pub fields: Vec, } +impl InputObjectTypeExtension { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + name, + directives: vec![], + fields: vec![], + } + } +} + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum DirectiveLocation { // executable @@ -212,6 +361,18 @@ pub struct DirectiveDefinition { pub locations: Vec, } +impl DirectiveDefinition { + pub fn new(name: Name) -> Self { + Self { + position: Pos::default(), + description: None, + name, + arguments: vec![], + locations: vec![], + } + } +} + impl DirectiveLocation { /// Returns GraphQL syntax compatible name of the directive pub fn as_str(&self) -> &'static str {