Skip to content

Derive Default for schema ast types #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 163 additions & 2 deletions src/schema/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Definition>,
}
Expand All @@ -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<Directive>,
Expand Down Expand Up @@ -56,13 +56,34 @@ pub struct ScalarType {
pub directives: Vec<Directive>,
}

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,
pub name: Name,
pub directives: Vec<Directive>,
}

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,
Expand All @@ -73,6 +94,19 @@ pub struct ObjectType {
pub fields: Vec<Field>,
}

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,
Expand All @@ -82,6 +116,18 @@ pub struct ObjectTypeExtension {
pub fields: Vec<Field>,
}

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,
Expand Down Expand Up @@ -111,6 +157,18 @@ pub struct InterfaceType {
pub fields: Vec<Field>,
}

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,
Expand All @@ -119,6 +177,17 @@ pub struct InterfaceTypeExtension {
pub fields: Vec<Field>,
}

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,
Expand All @@ -128,6 +197,18 @@ pub struct UnionType {
pub types: Vec<NamedType>,
}

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,
Expand All @@ -136,6 +217,17 @@ pub struct UnionTypeExtension {
pub types: Vec<NamedType>,
}

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,
Expand All @@ -145,6 +237,18 @@ pub struct EnumType {
pub values: Vec<EnumValue>,
}

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,
Expand All @@ -153,6 +257,17 @@ pub struct EnumValue {
pub directives: Vec<Directive>,
}

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,
Expand All @@ -161,6 +276,17 @@ pub struct EnumTypeExtension {
pub values: Vec<EnumValue>,
}

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,
Expand All @@ -170,6 +296,18 @@ pub struct InputObjectType {
pub fields: Vec<InputValue>,
}

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,
Expand All @@ -178,6 +316,17 @@ pub struct InputObjectTypeExtension {
pub fields: Vec<InputValue>,
}

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
Expand Down Expand Up @@ -212,6 +361,18 @@ pub struct DirectiveDefinition {
pub locations: Vec<DirectiveLocation>,
}

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 {
Expand Down