From 519a178b3a0b32ec37d4af6eac5d57823371fa90 Mon Sep 17 00:00:00 2001 From: Hiram Chirino Date: Tue, 26 Jul 2022 09:52:16 -0400 Subject: [PATCH] feat: add a new named node interface --- language/ast/arguments.go | 4 ++++ language/ast/definitions.go | 4 ++++ language/ast/named_node.go | 24 ++++++++++++++++++++++++ language/ast/selections.go | 8 ++++++++ language/ast/type_definitions.go | 12 ++++++++++++ language/ast/values.go | 6 +++++- 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 language/ast/named_node.go diff --git a/language/ast/arguments.go b/language/ast/arguments.go index 2ebd0fa7..b6f774a3 100644 --- a/language/ast/arguments.go +++ b/language/ast/arguments.go @@ -27,3 +27,7 @@ func (arg *Argument) GetKind() string { func (arg *Argument) GetLoc() *Location { return arg.Loc } + +func (arg *Argument) GetName() *Name { + return arg.Name +} diff --git a/language/ast/definitions.go b/language/ast/definitions.go index e16cf18d..d348e8b6 100644 --- a/language/ast/definitions.go +++ b/language/ast/definitions.go @@ -233,3 +233,7 @@ func (def *DirectiveDefinition) GetOperation() string { func (def *DirectiveDefinition) GetDescription() *StringValue { return def.Description } + +func (def *DirectiveDefinition) GetName() *Name { + return def.Name +} diff --git a/language/ast/named_node.go b/language/ast/named_node.go new file mode 100644 index 00000000..476b1696 --- /dev/null +++ b/language/ast/named_node.go @@ -0,0 +1,24 @@ +package ast + +type NamedNode interface { + GetName() *Name +} + +// Ensure that the following types implement the NamedNode interface +var _ NamedNode = (*Argument)(nil) +var _ NamedNode = (*DirectiveDefinition)(nil) +var _ NamedNode = (*FragmentDefinition)(nil) +var _ NamedNode = (*OperationDefinition)(nil) +var _ NamedNode = (*Field)(nil) +var _ NamedNode = (*FragmentSpread)(nil) +var _ NamedNode = (*EnumDefinition)(nil) +var _ NamedNode = (*EnumValueDefinition)(nil) +var _ NamedNode = (*FieldDefinition)(nil) +var _ NamedNode = (*InputObjectDefinition)(nil) +var _ NamedNode = (*InputValueDefinition)(nil) +var _ NamedNode = (*InterfaceDefinition)(nil) +var _ NamedNode = (*ObjectDefinition)(nil) +var _ NamedNode = (*ScalarDefinition)(nil) +var _ NamedNode = (*UnionDefinition)(nil) +var _ NamedNode = (*ObjectField)(nil) +var _ NamedNode = (*Variable)(nil) diff --git a/language/ast/selections.go b/language/ast/selections.go index 55df71a3..5bfda5cd 100644 --- a/language/ast/selections.go +++ b/language/ast/selections.go @@ -44,6 +44,10 @@ func (f *Field) GetSelectionSet() *SelectionSet { return f.SelectionSet } +func (f *Field) GetName() *Name { + return f.Name +} + // FragmentSpread implements Node, Selection type FragmentSpread struct { Kind string @@ -76,6 +80,10 @@ func (fs *FragmentSpread) GetSelectionSet() *SelectionSet { return nil } +func (fs *FragmentSpread) GetName() *Name { + return fs.Name +} + // InlineFragment implements Node, Selection type InlineFragment struct { Kind string diff --git a/language/ast/type_definitions.go b/language/ast/type_definitions.go index aefa70ed..8c9fdea5 100644 --- a/language/ast/type_definitions.go +++ b/language/ast/type_definitions.go @@ -248,6 +248,10 @@ func (def *FieldDefinition) GetDescription() *StringValue { return def.Description } +func (def *FieldDefinition) GetName() *Name { + return def.Name +} + // InputValueDefinition implements Node type InputValueDefinition struct { Kind string @@ -286,6 +290,10 @@ func (def *InputValueDefinition) GetDescription() *StringValue { return def.Description } +func (def *InputValueDefinition) GetName() *Name { + return def.Name +} + // InterfaceDefinition implements Node, Definition type InterfaceDefinition struct { Kind string @@ -476,6 +484,10 @@ func (def *EnumValueDefinition) GetDescription() *StringValue { return def.Description } +func (def *EnumValueDefinition) GetName() *Name { + return def.Name +} + // InputObjectDefinition implements Node, Definition type InputObjectDefinition struct { Kind string diff --git a/language/ast/values.go b/language/ast/values.go index 6c3c8864..718eac08 100644 --- a/language/ast/values.go +++ b/language/ast/values.go @@ -48,7 +48,7 @@ func (v *Variable) GetValue() interface{} { return v.GetName() } -func (v *Variable) GetName() interface{} { +func (v *Variable) GetName() *Name { return v.Name } @@ -297,6 +297,10 @@ func (f *ObjectField) GetLoc() *Location { return f.Loc } +func (f *ObjectField) GetName() *Name { + return f.Name +} + func (f *ObjectField) GetValue() interface{} { return f.Value }