cubefs

Форк
0
235 строк · 5.4 Кб
1
package ast
2

3
import (
4
	"github.com/graphql-go/graphql/language/kinds"
5
)
6

7
type Definition interface {
8
	GetOperation() string
9
	GetVariableDefinitions() []*VariableDefinition
10
	GetSelectionSet() *SelectionSet
11
	GetKind() string
12
	GetLoc() *Location
13
}
14

15
// Ensure that all definition types implements Definition interface
16
var _ Definition = (*OperationDefinition)(nil)
17
var _ Definition = (*FragmentDefinition)(nil)
18
var _ Definition = (TypeSystemDefinition)(nil) // experimental non-spec addition.
19

20
// Note: subscription is an experimental non-spec addition.
21
const (
22
	OperationTypeQuery        = "query"
23
	OperationTypeMutation     = "mutation"
24
	OperationTypeSubscription = "subscription"
25
)
26

27
// OperationDefinition implements Node, Definition
28
type OperationDefinition struct {
29
	Kind                string
30
	Loc                 *Location
31
	Operation           string
32
	Name                *Name
33
	VariableDefinitions []*VariableDefinition
34
	Directives          []*Directive
35
	SelectionSet        *SelectionSet
36
}
37

38
func NewOperationDefinition(op *OperationDefinition) *OperationDefinition {
39
	if op == nil {
40
		op = &OperationDefinition{}
41
	}
42
	op.Kind = kinds.OperationDefinition
43
	return op
44
}
45

46
func (op *OperationDefinition) GetKind() string {
47
	return op.Kind
48
}
49

50
func (op *OperationDefinition) GetLoc() *Location {
51
	return op.Loc
52
}
53

54
func (op *OperationDefinition) GetOperation() string {
55
	return op.Operation
56
}
57

58
func (op *OperationDefinition) GetName() *Name {
59
	return op.Name
60
}
61

62
func (op *OperationDefinition) GetVariableDefinitions() []*VariableDefinition {
63
	return op.VariableDefinitions
64
}
65

66
func (op *OperationDefinition) GetDirectives() []*Directive {
67
	return op.Directives
68
}
69

70
func (op *OperationDefinition) GetSelectionSet() *SelectionSet {
71
	return op.SelectionSet
72
}
73

74
// FragmentDefinition implements Node, Definition
75
type FragmentDefinition struct {
76
	Kind                string
77
	Loc                 *Location
78
	Operation           string
79
	Name                *Name
80
	VariableDefinitions []*VariableDefinition
81
	TypeCondition       *Named
82
	Directives          []*Directive
83
	SelectionSet        *SelectionSet
84
}
85

86
func NewFragmentDefinition(fd *FragmentDefinition) *FragmentDefinition {
87
	if fd == nil {
88
		fd = &FragmentDefinition{}
89
	}
90
	return &FragmentDefinition{
91
		Kind:                kinds.FragmentDefinition,
92
		Loc:                 fd.Loc,
93
		Operation:           fd.Operation,
94
		Name:                fd.Name,
95
		VariableDefinitions: fd.VariableDefinitions,
96
		TypeCondition:       fd.TypeCondition,
97
		Directives:          fd.Directives,
98
		SelectionSet:        fd.SelectionSet,
99
	}
100
}
101

102
func (fd *FragmentDefinition) GetKind() string {
103
	return fd.Kind
104
}
105

106
func (fd *FragmentDefinition) GetLoc() *Location {
107
	return fd.Loc
108
}
109

110
func (fd *FragmentDefinition) GetOperation() string {
111
	return fd.Operation
112
}
113

114
func (fd *FragmentDefinition) GetName() *Name {
115
	return fd.Name
116
}
117

118
func (fd *FragmentDefinition) GetVariableDefinitions() []*VariableDefinition {
119
	return fd.VariableDefinitions
120
}
121

122
func (fd *FragmentDefinition) GetSelectionSet() *SelectionSet {
123
	return fd.SelectionSet
124
}
125

126
// VariableDefinition implements Node
127
type VariableDefinition struct {
128
	Kind         string
129
	Loc          *Location
130
	Variable     *Variable
131
	Type         Type
132
	DefaultValue Value
133
}
134

135
func NewVariableDefinition(vd *VariableDefinition) *VariableDefinition {
136
	if vd == nil {
137
		vd = &VariableDefinition{}
138
	}
139
	vd.Kind = kinds.VariableDefinition
140
	return vd
141
}
142

143
func (vd *VariableDefinition) GetKind() string {
144
	return vd.Kind
145
}
146

147
func (vd *VariableDefinition) GetLoc() *Location {
148
	return vd.Loc
149
}
150

151
// TypeExtensionDefinition implements Node, Definition
152
type TypeExtensionDefinition struct {
153
	Kind       string
154
	Loc        *Location
155
	Definition *ObjectDefinition
156
}
157

158
func NewTypeExtensionDefinition(def *TypeExtensionDefinition) *TypeExtensionDefinition {
159
	if def == nil {
160
		def = &TypeExtensionDefinition{}
161
	}
162
	return &TypeExtensionDefinition{
163
		Kind:       kinds.TypeExtensionDefinition,
164
		Loc:        def.Loc,
165
		Definition: def.Definition,
166
	}
167
}
168

169
func (def *TypeExtensionDefinition) GetKind() string {
170
	return def.Kind
171
}
172

173
func (def *TypeExtensionDefinition) GetLoc() *Location {
174
	return def.Loc
175
}
176

177
func (def *TypeExtensionDefinition) GetVariableDefinitions() []*VariableDefinition {
178
	return []*VariableDefinition{}
179
}
180

181
func (def *TypeExtensionDefinition) GetSelectionSet() *SelectionSet {
182
	return &SelectionSet{}
183
}
184

185
func (def *TypeExtensionDefinition) GetOperation() string {
186
	return ""
187
}
188

189
// DirectiveDefinition implements Node, Definition
190
type DirectiveDefinition struct {
191
	Kind        string
192
	Loc         *Location
193
	Name        *Name
194
	Description *StringValue
195
	Arguments   []*InputValueDefinition
196
	Locations   []*Name
197
}
198

199
func NewDirectiveDefinition(def *DirectiveDefinition) *DirectiveDefinition {
200
	if def == nil {
201
		def = &DirectiveDefinition{}
202
	}
203
	return &DirectiveDefinition{
204
		Kind:        kinds.DirectiveDefinition,
205
		Loc:         def.Loc,
206
		Name:        def.Name,
207
		Description: def.Description,
208
		Arguments:   def.Arguments,
209
		Locations:   def.Locations,
210
	}
211
}
212

213
func (def *DirectiveDefinition) GetKind() string {
214
	return def.Kind
215
}
216

217
func (def *DirectiveDefinition) GetLoc() *Location {
218
	return def.Loc
219
}
220

221
func (def *DirectiveDefinition) GetVariableDefinitions() []*VariableDefinition {
222
	return []*VariableDefinition{}
223
}
224

225
func (def *DirectiveDefinition) GetSelectionSet() *SelectionSet {
226
	return &SelectionSet{}
227
}
228

229
func (def *DirectiveDefinition) GetOperation() string {
230
	return ""
231
}
232

233
func (def *DirectiveDefinition) GetDescription() *StringValue {
234
	return def.Description
235
}
236

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.