values.go

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