Skip to content
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

feat: add a new named node interface #639

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions language/ast/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions language/ast/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 24 additions & 0 deletions language/ast/named_node.go
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions language/ast/selections.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions language/ast/type_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion language/ast/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}