1package ast
2
3import (
4 "github.com/graphql-go/graphql/language/kinds"
5)
6
7type Selection interface {
8 GetSelectionSet() *SelectionSet
9}
10
11// Ensure that all definition types implements Selection interface
12var _ Selection = (*Field)(nil)
13var _ Selection = (*FragmentSpread)(nil)
14var _ Selection = (*InlineFragment)(nil)
15
16// Field implements Node, Selection
17type Field struct {
18 Kind string
19 Loc *Location
20 Alias *Name
21 Name *Name
22 Arguments []*Argument
23 Directives []*Directive
24 SelectionSet *SelectionSet
25}
26
27func NewField(f *Field) *Field {
28 if f == nil {
29 f = &Field{}
30 }
31 return &Field{
32 Kind: kinds.Field,
33 Loc: f.Loc,
34 Alias: f.Alias,
35 Name: f.Name,
36 Arguments: f.Arguments,
37 Directives: f.Directives,
38 SelectionSet: f.SelectionSet,
39 }
40}
41
42func (f *Field) GetKind() string {
43 return f.Kind
44}
45
46func (f *Field) GetLoc() *Location {
47 return f.Loc
48}
49
50func (f *Field) GetSelectionSet() *SelectionSet {
51 return f.SelectionSet
52}
53
54// FragmentSpread implements Node, Selection
55type FragmentSpread struct {
56 Kind string
57 Loc *Location
58 Name *Name
59 Directives []*Directive
60}
61
62func NewFragmentSpread(fs *FragmentSpread) *FragmentSpread {
63 if fs == nil {
64 fs = &FragmentSpread{}
65 }
66 return &FragmentSpread{
67 Kind: kinds.FragmentSpread,
68 Loc: fs.Loc,
69 Name: fs.Name,
70 Directives: fs.Directives,
71 }
72}
73
74func (fs *FragmentSpread) GetKind() string {
75 return fs.Kind
76}
77
78func (fs *FragmentSpread) GetLoc() *Location {
79 return fs.Loc
80}
81
82func (fs *FragmentSpread) GetSelectionSet() *SelectionSet {
83 return nil
84}
85
86// InlineFragment implements Node, Selection
87type InlineFragment struct {
88 Kind string
89 Loc *Location
90 TypeCondition *Named
91 Directives []*Directive
92 SelectionSet *SelectionSet
93}
94
95func NewInlineFragment(f *InlineFragment) *InlineFragment {
96 if f == nil {
97 f = &InlineFragment{}
98 }
99 return &InlineFragment{
100 Kind: kinds.InlineFragment,
101 Loc: f.Loc,
102 TypeCondition: f.TypeCondition,
103 Directives: f.Directives,
104 SelectionSet: f.SelectionSet,
105 }
106}
107
108func (f *InlineFragment) GetKind() string {
109 return f.Kind
110}
111
112func (f *InlineFragment) GetLoc() *Location {
113 return f.Loc
114}
115
116func (f *InlineFragment) GetSelectionSet() *SelectionSet {
117 return f.SelectionSet
118}
119
120// SelectionSet implements Node
121type SelectionSet struct {
122 Kind string
123 Loc *Location
124 Selections []Selection
125}
126
127func NewSelectionSet(ss *SelectionSet) *SelectionSet {
128 if ss == nil {
129 ss = &SelectionSet{}
130 }
131 return &SelectionSet{
132 Kind: kinds.SelectionSet,
133 Loc: ss.Loc,
134 Selections: ss.Selections,
135 }
136}
137
138func (ss *SelectionSet) GetKind() string {
139 return ss.Kind
140}
141
142func (ss *SelectionSet) GetLoc() *Location {
143 return ss.Loc
144}