/
generated.go
184 lines (147 loc) · 4.39 KB
/
generated.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
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
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
package out
import (
"fmt"
"io"
"strconv"
)
type A interface {
IsA()
}
type B interface {
IsB()
}
type C interface {
A
IsC()
}
type D interface {
A
B
IsD()
}
type FooBarer interface {
IsFooBarer()
}
// InterfaceWithDescription is an interface with a description
type InterfaceWithDescription interface {
IsInterfaceWithDescription()
}
type MissingInterface interface {
IsMissingInterface()
}
type MissingUnion interface {
IsMissingUnion()
}
// UnionWithDescription is an union with a description
type UnionWithDescription interface {
IsUnionWithDescription()
}
type FieldMutationHook struct {
Name *string `json:"name" anotherTag:"tag" database:"FieldMutationHookname"`
Enum *ExistingEnum `json:"enum" yetAnotherTag:"12" database:"FieldMutationHookenum"`
NoVal *string `json:"noVal" yaml:"noVal" repeated:"true" database:"FieldMutationHooknoVal"`
Repeated *string `json:"repeated" someTag:"value" repeated:"true" database:"FieldMutationHookrepeated"`
}
type MissingInput struct {
Name *string `json:"name" database:"MissingInputname"`
Enum *MissingEnum `json:"enum" database:"MissingInputenum"`
}
type MissingTypeNotNull struct {
Name string `json:"name" database:"MissingTypeNotNullname"`
Enum MissingEnum `json:"enum" database:"MissingTypeNotNullenum"`
Int MissingInterface `json:"int" database:"MissingTypeNotNullint"`
Existing *ExistingType `json:"existing" database:"MissingTypeNotNullexisting"`
Missing2 *MissingTypeNullable `json:"missing2" database:"MissingTypeNotNullmissing2"`
}
func (MissingTypeNotNull) IsMissingInterface() {}
func (MissingTypeNotNull) IsExistingInterface() {}
func (MissingTypeNotNull) IsMissingUnion() {}
func (MissingTypeNotNull) IsExistingUnion() {}
type MissingTypeNullable struct {
Name *string `json:"name" database:"MissingTypeNullablename"`
Enum *MissingEnum `json:"enum" database:"MissingTypeNullableenum"`
Int MissingInterface `json:"int" database:"MissingTypeNullableint"`
Existing *ExistingType `json:"existing" database:"MissingTypeNullableexisting"`
Missing2 *MissingTypeNotNull `json:"missing2" database:"MissingTypeNullablemissing2"`
}
func (MissingTypeNullable) IsMissingInterface() {}
func (MissingTypeNullable) IsExistingInterface() {}
func (MissingTypeNullable) IsMissingUnion() {}
func (MissingTypeNullable) IsExistingUnion() {}
// TypeWithDescription is a type with a description
type TypeWithDescription struct {
Name *string `json:"name" database:"TypeWithDescriptionname"`
}
func (TypeWithDescription) IsUnionWithDescription() {}
type FooBarr struct {
Name string `json:"name" database:"_Foo_Barrname"`
}
func (FooBarr) IsFooBarer() {}
// EnumWithDescription is an enum with a description
type EnumWithDescription string
const (
EnumWithDescriptionCat EnumWithDescription = "CAT"
EnumWithDescriptionDog EnumWithDescription = "DOG"
)
var AllEnumWithDescription = []EnumWithDescription{
EnumWithDescriptionCat,
EnumWithDescriptionDog,
}
func (e EnumWithDescription) IsValid() bool {
switch e {
case EnumWithDescriptionCat, EnumWithDescriptionDog:
return true
}
return false
}
func (e EnumWithDescription) String() string {
return string(e)
}
func (e *EnumWithDescription) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = EnumWithDescription(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid EnumWithDescription", str)
}
return nil
}
func (e EnumWithDescription) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}
type MissingEnum string
const (
MissingEnumHello MissingEnum = "Hello"
MissingEnumGoodbye MissingEnum = "Goodbye"
)
var AllMissingEnum = []MissingEnum{
MissingEnumHello,
MissingEnumGoodbye,
}
func (e MissingEnum) IsValid() bool {
switch e {
case MissingEnumHello, MissingEnumGoodbye:
return true
}
return false
}
func (e MissingEnum) String() string {
return string(e)
}
func (e *MissingEnum) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = MissingEnum(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid MissingEnum", str)
}
return nil
}
func (e MissingEnum) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}