aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/graphql-go/graphql/language/ast/values.go
blob: 67912bdc38cea03f791e393e374ca50539302be5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
package ast

import (
	"github.com/graphql-go/graphql/language/kinds"
)

type Value interface {
	GetValue() interface{}
	GetKind() string
	GetLoc() *Location
}

// Ensure that all value types implements Value interface
var _ Value = (*Variable)(nil)
var _ Value = (*IntValue)(nil)
var _ Value = (*FloatValue)(nil)
var _ Value = (*StringValue)(nil)
var _ Value = (*BooleanValue)(nil)
var _ Value = (*EnumValue)(nil)
var _ Value = (*ListValue)(nil)
var _ Value = (*ObjectValue)(nil)

// Variable implements Node, Value
type Variable struct {
	Kind string
	Loc  *Location
	Name *Name
}

func NewVariable(v *Variable) *Variable {
	if v == nil {
		v = &Variable{}
	}
	return &Variable{
		Kind: kinds.Variable,
		Loc:  v.Loc,
		Name: v.Name,
	}
}

func (v *Variable) GetKind() string {
	return v.Kind
}

func (v *Variable) GetLoc() *Location {
	return v.Loc
}

// GetValue alias to Variable.GetName()
func (v *Variable) GetValue() interface{} {
	return v.GetName()
}

func (v *Variable) GetName() interface{} {
	return v.Name
}

// IntValue implements Node, Value
type IntValue struct {
	Kind  string
	Loc   *Location
	Value string
}

func NewIntValue(v *IntValue) *IntValue {
	if v == nil {
		v = &IntValue{}
	}
	return &IntValue{
		Kind:  kinds.IntValue,
		Loc:   v.Loc,
		Value: v.Value,
	}
}

func (v *IntValue) GetKind() string {
	return v.Kind
}

func (v *IntValue) GetLoc() *Location {
	return v.Loc
}

func (v *IntValue) GetValue() interface{} {
	return v.Value
}

// FloatValue implements Node, Value
type FloatValue struct {
	Kind  string
	Loc   *Location
	Value string
}

func NewFloatValue(v *FloatValue) *FloatValue {
	if v == nil {
		v = &FloatValue{}
	}
	return &FloatValue{
		Kind:  kinds.FloatValue,
		Loc:   v.Loc,
		Value: v.Value,
	}
}

func (v *FloatValue) GetKind() string {
	return v.Kind
}

func (v *FloatValue) GetLoc() *Location {
	return v.Loc
}

func (v *FloatValue) GetValue() interface{} {
	return v.Value
}

// StringValue implements Node, Value
type StringValue struct {
	Kind  string
	Loc   *Location
	Value string
}

func NewStringValue(v *StringValue) *StringValue {
	if v == nil {
		v = &StringValue{}
	}
	return &StringValue{
		Kind:  kinds.StringValue,
		Loc:   v.Loc,
		Value: v.Value,
	}
}

func (v *StringValue) GetKind() string {
	return v.Kind
}

func (v *StringValue) GetLoc() *Location {
	return v.Loc
}

func (v *StringValue) GetValue() interface{} {
	return v.Value
}

// BooleanValue implements Node, Value
type BooleanValue struct {
	Kind  string
	Loc   *Location
	Value bool
}

func NewBooleanValue(v *BooleanValue) *BooleanValue {
	if v == nil {
		v = &BooleanValue{}
	}
	return &BooleanValue{
		Kind:  kinds.BooleanValue,
		Loc:   v.Loc,
		Value: v.Value,
	}
}

func (v *BooleanValue) GetKind() string {
	return v.Kind
}

func (v *BooleanValue) GetLoc() *Location {
	return v.Loc
}

func (v *BooleanValue) GetValue() interface{} {
	return v.Value
}

// EnumValue implements Node, Value
type EnumValue struct {
	Kind  string
	Loc   *Location
	Value string
}

func NewEnumValue(v *EnumValue) *EnumValue {
	if v == nil {
		v = &EnumValue{}
	}
	return &EnumValue{
		Kind:  kinds.EnumValue,
		Loc:   v.Loc,
		Value: v.Value,
	}
}

func (v *EnumValue) GetKind() string {
	return v.Kind
}

func (v *EnumValue) GetLoc() *Location {
	return v.Loc
}

func (v *EnumValue) GetValue() interface{} {
	return v.Value
}

// ListValue implements Node, Value
type ListValue struct {
	Kind   string
	Loc    *Location
	Values []Value
}

func NewListValue(v *ListValue) *ListValue {
	if v == nil {
		v = &ListValue{}
	}
	return &ListValue{
		Kind:   kinds.ListValue,
		Loc:    v.Loc,
		Values: v.Values,
	}
}

func (v *ListValue) GetKind() string {
	return v.Kind
}

func (v *ListValue) GetLoc() *Location {
	return v.Loc
}

// GetValue alias to ListValue.GetValues()
func (v *ListValue) GetValue() interface{} {
	return v.GetValues()
}

func (v *ListValue) GetValues() interface{} {
	// TODO: verify ObjectValue.GetValue()
	return v.Values
}

// ObjectValue implements Node, Value
type ObjectValue struct {
	Kind   string
	Loc    *Location
	Fields []*ObjectField
}

func NewObjectValue(v *ObjectValue) *ObjectValue {
	if v == nil {
		v = &ObjectValue{}
	}
	return &ObjectValue{
		Kind:   kinds.ObjectValue,
		Loc:    v.Loc,
		Fields: v.Fields,
	}
}

func (v *ObjectValue) GetKind() string {
	return v.Kind
}

func (v *ObjectValue) GetLoc() *Location {
	return v.Loc
}

func (v *ObjectValue) GetValue() interface{} {
	// TODO: verify ObjectValue.GetValue()
	return v.Fields
}

// ObjectField implements Node, Value
type ObjectField struct {
	Kind  string
	Name  *Name
	Loc   *Location
	Value Value
}

func NewObjectField(f *ObjectField) *ObjectField {
	if f == nil {
		f = &ObjectField{}
	}
	return &ObjectField{
		Kind:  kinds.ObjectField,
		Loc:   f.Loc,
		Name:  f.Name,
		Value: f.Value,
	}
}

func (f *ObjectField) GetKind() string {
	return f.Kind
}

func (f *ObjectField) GetLoc() *Location {
	return f.Loc
}

func (f *ObjectField) GetValue() interface{} {
	return f.Value
}