-
Notifications
You must be signed in to change notification settings - Fork 0
/
gql_types.go
100 lines (91 loc) · 1.9 KB
/
gql_types.go
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
package eywa
// type Type interface {
// Type() string
// }
//
// type Boolean interface {
// ~bool
// }
// type NullableBoolean interface {
// ~*bool
// }
// type Int interface {
// ~int
// }
// type NullableInt interface {
// ~*int
// }
// type Float interface {
// ~float32 | ~float64
// }
// type NullableFloat interface {
// ~*float32 | ~*float64
// }
// type String interface {
// ~string
// }
// type NullableBoolean interface {
// ~*string
// }
type TypedValue interface {
Type() string
Value() interface{}
}
type scalarValue struct {
name string
value interface{}
}
func (tv scalarValue) Type() string {
return tv.name
}
func (tv scalarValue) Value() interface{} {
return tv.value
}
func BooleanVar[T ~bool](val T) TypedValue {
return scalarValue{"Boolean!", val}
}
func NullableBooleanVar[T ~*bool](val T) TypedValue {
return scalarValue{"Boolean", val}
}
func IntVar[T ~int | ~int8 | ~int16 | ~int32 | ~int64](val T) TypedValue {
return scalarValue{"Int!", val}
}
func NullableIntVar[T ~*int | ~*int8 | ~*int16 | ~*int32 | ~*int64](val T) TypedValue {
return scalarValue{"Int", val}
}
func FloatVar[T ~float64 | ~float32](val T) TypedValue {
return scalarValue{"Float!", val}
}
func NullableFloat[T ~*float64 | ~*float32](val T) TypedValue {
return scalarValue{"Float", val}
}
func StringVar[T ~string](val T) TypedValue {
return scalarValue{"String!", val}
}
func NullableStringVar[T ~*string](val T) TypedValue {
return scalarValue{"String", val}
}
func JSONVar(val interface{}) TypedValue {
return JSONValue{val}
}
func JSONBVar(val interface{}) TypedValue {
return JSONBValue{val}
}
type JSONValue struct {
Val interface{}
}
func (jv JSONValue) Type() string {
return "json"
}
func (jv JSONValue) Value() interface{} {
return jv.Val
}
type JSONBValue struct {
Val interface{}
}
func (jv JSONBValue) Type() string {
return "jsonb"
}
func (jv JSONBValue) Value() interface{} {
return jv.Val
}