1
2
3 package out_nullable_input_omittable
4
5 import (
6 "fmt"
7 "io"
8 "strconv"
9
10 "github.com/99designs/gqlgen/graphql"
11 )
12
13 type A interface {
14 IsA()
15 GetA() string
16 }
17
18 type ArrayOfA interface {
19 IsArrayOfA()
20 GetTrickyField() []A
21 GetTrickyFieldPointer() []A
22 }
23
24 type B interface {
25 IsB()
26 GetB() int
27 }
28
29 type C interface {
30 IsA()
31 IsC()
32 GetA() string
33 GetC() bool
34 }
35
36 type D interface {
37 IsA()
38 IsB()
39 IsD()
40 GetA() string
41 GetB() int
42 GetD() *string
43 }
44
45 type FooBarer interface {
46 IsFooBarer()
47 GetName() string
48 }
49
50
51 type InterfaceWithDescription interface {
52 IsInterfaceWithDescription()
53 GetName() *string
54 }
55
56 type MissingInterface interface {
57 IsMissingInterface()
58 GetName() *string
59 }
60
61 type MissingUnion interface {
62 IsMissingUnion()
63 }
64
65
66 type UnionWithDescription interface {
67 IsUnionWithDescription()
68 }
69
70 type X interface {
71 IsX()
72 GetId() string
73 }
74
75 type CDImplemented struct {
76 A string `json:"a" database:"CDImplementeda"`
77 B int `json:"b" database:"CDImplementedb"`
78 C bool `json:"c" database:"CDImplementedc"`
79 D *string `json:"d,omitempty" database:"CDImplementedd"`
80 }
81
82 func (CDImplemented) IsC() {}
83 func (this CDImplemented) GetA() string { return this.A }
84 func (this CDImplemented) GetC() bool { return this.C }
85
86 func (CDImplemented) IsA() {}
87
88 func (CDImplemented) IsD() {}
89
90 func (this CDImplemented) GetB() int { return this.B }
91 func (this CDImplemented) GetD() *string { return this.D }
92
93 func (CDImplemented) IsB() {}
94
95 type CyclicalA struct {
96 FieldOne *CyclicalB `json:"field_one,omitempty" database:"CyclicalAfield_one"`
97 FieldTwo *CyclicalB `json:"field_two,omitempty" database:"CyclicalAfield_two"`
98 FieldThree *CyclicalB `json:"field_three,omitempty" database:"CyclicalAfield_three"`
99 FieldFour string `json:"field_four" database:"CyclicalAfield_four"`
100 }
101
102 type CyclicalB struct {
103 FieldOne *CyclicalA `json:"field_one,omitempty" database:"CyclicalBfield_one"`
104 FieldTwo *CyclicalA `json:"field_two,omitempty" database:"CyclicalBfield_two"`
105 FieldThree *CyclicalA `json:"field_three,omitempty" database:"CyclicalBfield_three"`
106 FieldFour *CyclicalA `json:"field_four,omitempty" database:"CyclicalBfield_four"`
107 FieldFive string `json:"field_five" database:"CyclicalBfield_five"`
108 }
109
110 type ExtraFieldsTest struct {
111 SchemaField string `json:"SchemaField" database:"ExtraFieldsTestSchemaField"`
112 }
113
114 type FieldMutationHook struct {
115 Name *string `json:"name,omitempty" anotherTag:"tag" database:"FieldMutationHookname"`
116 Enum *ExistingEnum `json:"enum,omitempty" yetAnotherTag:"12" database:"FieldMutationHookenum"`
117 NoVal *string `json:"noVal,omitempty" yaml:"noVal" repeated:"true" database:"FieldMutationHooknoVal"`
118 Repeated *string `json:"repeated,omitempty" someTag:"value" repeated:"true" database:"FieldMutationHookrepeated"`
119 }
120
121 type ImplArrayOfA struct {
122 TrickyField []*CDImplemented `json:"trickyField" database:"ImplArrayOfAtrickyField"`
123 TrickyFieldPointer []*CDImplemented `json:"trickyFieldPointer,omitempty" database:"ImplArrayOfAtrickyFieldPointer"`
124 }
125
126 func (ImplArrayOfA) IsArrayOfA() {}
127 func (this ImplArrayOfA) GetTrickyField() []A {
128 if this.TrickyField == nil {
129 return nil
130 }
131 interfaceSlice := make([]A, 0, len(this.TrickyField))
132 for _, concrete := range this.TrickyField {
133 interfaceSlice = append(interfaceSlice, concrete)
134 }
135 return interfaceSlice
136 }
137 func (this ImplArrayOfA) GetTrickyFieldPointer() []A {
138 if this.TrickyFieldPointer == nil {
139 return nil
140 }
141 interfaceSlice := make([]A, 0, len(this.TrickyFieldPointer))
142 for _, concrete := range this.TrickyFieldPointer {
143 interfaceSlice = append(interfaceSlice, concrete)
144 }
145 return interfaceSlice
146 }
147
148 type MissingInput struct {
149 Name graphql.Omittable[*string] `json:"name,omitempty" database:"MissingInputname"`
150 Enum graphql.Omittable[*MissingEnum] `json:"enum,omitempty" database:"MissingInputenum"`
151 NonNullString string `json:"nonNullString" database:"MissingInputnonNullString"`
152 NullString graphql.Omittable[*string] `json:"nullString,omitempty" database:"MissingInputnullString"`
153 NullEnum graphql.Omittable[*MissingEnum] `json:"nullEnum,omitempty" database:"MissingInputnullEnum"`
154 NullObject graphql.Omittable[*ExistingInput] `json:"nullObject,omitempty" database:"MissingInputnullObject"`
155 }
156
157 type MissingTypeNotNull struct {
158 Name string `json:"name" database:"MissingTypeNotNullname"`
159 Enum MissingEnum `json:"enum" database:"MissingTypeNotNullenum"`
160 Int MissingInterface `json:"int" database:"MissingTypeNotNullint"`
161 Existing *ExistingType `json:"existing" database:"MissingTypeNotNullexisting"`
162 Missing2 *MissingTypeNullable `json:"missing2" database:"MissingTypeNotNullmissing2"`
163 }
164
165 func (MissingTypeNotNull) IsMissingInterface() {}
166 func (this MissingTypeNotNull) GetName() *string { return &this.Name }
167
168 func (MissingTypeNotNull) IsExistingInterface() {}
169
170 func (MissingTypeNotNull) IsMissingUnion() {}
171
172 func (MissingTypeNotNull) IsExistingUnion() {}
173
174 type MissingTypeNullable struct {
175 Name *string `json:"name,omitempty" database:"MissingTypeNullablename"`
176 Enum *MissingEnum `json:"enum,omitempty" database:"MissingTypeNullableenum"`
177 Int MissingInterface `json:"int,omitempty" database:"MissingTypeNullableint"`
178 Existing *ExistingType `json:"existing,omitempty" database:"MissingTypeNullableexisting"`
179 Missing2 *MissingTypeNotNull `json:"missing2,omitempty" database:"MissingTypeNullablemissing2"`
180 }
181
182 func (MissingTypeNullable) IsMissingInterface() {}
183 func (this MissingTypeNullable) GetName() *string { return this.Name }
184
185 func (MissingTypeNullable) IsExistingInterface() {}
186
187 func (MissingTypeNullable) IsMissingUnion() {}
188
189 func (MissingTypeNullable) IsExistingUnion() {}
190
191 type Mutation struct {
192 }
193
194 type NotCyclicalA struct {
195 FieldOne string `json:"FieldOne" database:"NotCyclicalAFieldOne"`
196 FieldTwo int `json:"FieldTwo" database:"NotCyclicalAFieldTwo"`
197 }
198
199 type NotCyclicalB struct {
200 FieldOne string `json:"FieldOne" database:"NotCyclicalBFieldOne"`
201 FieldTwo *NotCyclicalA `json:"FieldTwo" database:"NotCyclicalBFieldTwo"`
202 }
203
204 type OmitEmptyJSONTagTest struct {
205 ValueNonNil string `json:"ValueNonNil" database:"OmitEmptyJsonTagTestValueNonNil"`
206 Value *string `json:"Value,omitempty" database:"OmitEmptyJsonTagTestValue"`
207 }
208
209 type Query struct {
210 }
211
212 type Recursive struct {
213 FieldOne *Recursive `json:"FieldOne" database:"RecursiveFieldOne"`
214 FieldTwo *Recursive `json:"FieldTwo" database:"RecursiveFieldTwo"`
215 FieldThree *Recursive `json:"FieldThree" database:"RecursiveFieldThree"`
216 FieldFour string `json:"FieldFour" database:"RecursiveFieldFour"`
217 }
218
219 type RenameFieldTest struct {
220 BadName string `json:"badName" database:"RenameFieldTestbadName"`
221 OtherField string `json:"otherField" database:"RenameFieldTestotherField"`
222 }
223
224 type Subscription struct {
225 }
226
227
228 type TypeWithDescription struct {
229 Name *string `json:"name,omitempty" database:"TypeWithDescriptionname"`
230 }
231
232 func (TypeWithDescription) IsUnionWithDescription() {}
233
234 type Xer struct {
235 Id string `json:"Id" database:"XerId"`
236 Name string `json:"Name" database:"XerName"`
237 }
238
239 func (Xer) IsX() {}
240 func (this Xer) GetId() string { return this.Id }
241
242 type FooBarr struct {
243 Name string `json:"name" database:"_Foo_Barrname"`
244 }
245
246 func (FooBarr) IsFooBarer() {}
247 func (this FooBarr) GetName() string { return this.Name }
248
249
250 type EnumWithDescription string
251
252 const (
253 EnumWithDescriptionCat EnumWithDescription = "CAT"
254 EnumWithDescriptionDog EnumWithDescription = "DOG"
255 )
256
257 var AllEnumWithDescription = []EnumWithDescription{
258 EnumWithDescriptionCat,
259 EnumWithDescriptionDog,
260 }
261
262 func (e EnumWithDescription) IsValid() bool {
263 switch e {
264 case EnumWithDescriptionCat, EnumWithDescriptionDog:
265 return true
266 }
267 return false
268 }
269
270 func (e EnumWithDescription) String() string {
271 return string(e)
272 }
273
274 func (e *EnumWithDescription) UnmarshalGQL(v interface{}) error {
275 str, ok := v.(string)
276 if !ok {
277 return fmt.Errorf("enums must be strings")
278 }
279
280 *e = EnumWithDescription(str)
281 if !e.IsValid() {
282 return fmt.Errorf("%s is not a valid EnumWithDescription", str)
283 }
284 return nil
285 }
286
287 func (e EnumWithDescription) MarshalGQL(w io.Writer) {
288 fmt.Fprint(w, strconv.Quote(e.String()))
289 }
290
291 type MissingEnum string
292
293 const (
294 MissingEnumHello MissingEnum = "Hello"
295 MissingEnumGoodbye MissingEnum = "Goodbye"
296 )
297
298 var AllMissingEnum = []MissingEnum{
299 MissingEnumHello,
300 MissingEnumGoodbye,
301 }
302
303 func (e MissingEnum) IsValid() bool {
304 switch e {
305 case MissingEnumHello, MissingEnumGoodbye:
306 return true
307 }
308 return false
309 }
310
311 func (e MissingEnum) String() string {
312 return string(e)
313 }
314
315 func (e *MissingEnum) UnmarshalGQL(v interface{}) error {
316 str, ok := v.(string)
317 if !ok {
318 return fmt.Errorf("enums must be strings")
319 }
320
321 *e = MissingEnum(str)
322 if !e.IsValid() {
323 return fmt.Errorf("%s is not a valid MissingEnum", str)
324 }
325 return nil
326 }
327
328 func (e MissingEnum) MarshalGQL(w io.Writer) {
329 fmt.Fprint(w, strconv.Quote(e.String()))
330 }
331
View as plain text