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