-
Notifications
You must be signed in to change notification settings - Fork 12
/
models-gen.go
317 lines (253 loc) · 5.9 KB
/
models-gen.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
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
306
307
308
309
310
311
312
313
314
315
316
317
// Code generated by github.com/vmware-tanzu/graph-framework-for-microservices/gqlgen, DO NOT EDIT.
package singlefile
import (
"fmt"
"io"
"strconv"
"time"
)
type Animal interface {
IsAnimal()
GetSpecies() string
}
type ContentChild interface {
IsContentChild()
}
type TestUnion interface {
IsTestUnion()
}
type A struct {
ID string `json:"id"`
}
func (A) IsTestUnion() {}
type AIt struct {
ID string `json:"id"`
}
type AbIt struct {
ID string `json:"id"`
}
type B struct {
ID string `json:"id"`
}
func (B) IsTestUnion() {}
type Cat struct {
Species string `json:"species"`
CatBreed string `json:"catBreed"`
}
func (Cat) IsAnimal() {}
func (this Cat) GetSpecies() string { return this.Species }
type CheckIssue896 struct {
ID *int `json:"id"`
}
type ContentPost struct {
Foo *string `json:"foo"`
}
func (ContentPost) IsContentChild() {}
type ContentUser struct {
Foo *string `json:"foo"`
}
func (ContentUser) IsContentChild() {}
type Coordinates struct {
X float64 `json:"x"`
Y float64 `json:"y"`
}
type DefaultInput struct {
FalsyBoolean *bool `json:"falsyBoolean"`
TruthyBoolean *bool `json:"truthyBoolean"`
}
type DefaultParametersMirror struct {
FalsyBoolean *bool `json:"falsyBoolean"`
TruthyBoolean *bool `json:"truthyBoolean"`
}
type Dog struct {
Species string `json:"species"`
DogBreed string `json:"dogBreed"`
}
func (Dog) IsAnimal() {}
func (this Dog) GetSpecies() string { return this.Species }
type EmbeddedDefaultScalar struct {
Value *string `json:"value"`
}
type FieldsOrderPayload struct {
FirstFieldValue *string `json:"firstFieldValue"`
}
type InnerDirectives struct {
Message string `json:"message"`
}
type InnerInput struct {
ID int `json:"id"`
}
type InnerObject struct {
ID int `json:"id"`
}
type InputDirectives struct {
Text string `json:"text"`
NullableText *string `json:"nullableText"`
Inner *InnerDirectives `json:"inner"`
InnerNullable *InnerDirectives `json:"innerNullable"`
ThirdParty *ThirdParty `json:"thirdParty"`
}
type InputWithEnumValue struct {
Enum EnumTest `json:"enum"`
}
type LoopA struct {
B *LoopB `json:"b"`
}
type LoopB struct {
A *LoopA `json:"a"`
}
// Since gqlgen defines default implementation for a Map scalar, this tests that the builtin is _not_
// added to the TypeMap
type Map struct {
ID string `json:"id"`
}
type NestedInput struct {
Field Email `json:"field"`
}
type NestedMapInput struct {
Map map[string]interface{} `json:"map"`
}
type ObjectDirectives struct {
Text string `json:"text"`
NullableText *string `json:"nullableText"`
Order []string `json:"order"`
}
type OuterInput struct {
Inner *InnerInput `json:"inner"`
}
type OuterObject struct {
Inner *InnerObject `json:"inner"`
}
type Pet struct {
ID int `json:"id"`
Friends []*Pet `json:"friends"`
}
type Slices struct {
Test1 []*string `json:"test1"`
Test2 []string `json:"test2"`
Test3 []*string `json:"test3"`
Test4 []string `json:"test4"`
}
type SpecialInput struct {
Nesting *NestedInput `json:"nesting"`
}
type User struct {
ID int `json:"id"`
Friends []*User `json:"friends"`
Created time.Time `json:"created"`
Updated *time.Time `json:"updated"`
Pets []*Pet `json:"pets"`
}
type ValidInput struct {
Break string `json:"break"`
Default string `json:"default"`
Func string `json:"func"`
Interface string `json:"interface"`
Select string `json:"select"`
Case string `json:"case"`
Defer string `json:"defer"`
Go string `json:"go"`
Map string `json:"map"`
Struct string `json:"struct"`
Chan string `json:"chan"`
Else string `json:"else"`
Goto string `json:"goto"`
Package string `json:"package"`
Switch string `json:"switch"`
Const string `json:"const"`
Fallthrough string `json:"fallthrough"`
If string `json:"if"`
Range string `json:"range"`
Type string `json:"type"`
Continue string `json:"continue"`
For string `json:"for"`
Import string `json:"import"`
Return string `json:"return"`
Var string `json:"var"`
Underscore string `json:"_"`
}
// These things are all valid, but without care generate invalid go code
type ValidType struct {
DifferentCase string `json:"differentCase"`
DifferentCaseOld string `json:"different_case"`
ValidInputKeywords bool `json:"validInputKeywords"`
ValidArgs bool `json:"validArgs"`
}
type XXIt struct {
ID string `json:"id"`
}
type XxIt struct {
ID string `json:"id"`
}
type AsdfIt struct {
ID string `json:"id"`
}
type IIt struct {
ID string `json:"id"`
}
type EnumTest string
const (
EnumTestOk EnumTest = "OK"
EnumTestNg EnumTest = "NG"
)
var AllEnumTest = []EnumTest{
EnumTestOk,
EnumTestNg,
}
func (e EnumTest) IsValid() bool {
switch e {
case EnumTestOk, EnumTestNg:
return true
}
return false
}
func (e EnumTest) String() string {
return string(e)
}
func (e *EnumTest) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = EnumTest(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid EnumTest", str)
}
return nil
}
func (e EnumTest) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}
type Status string
const (
StatusOk Status = "OK"
StatusError Status = "ERROR"
)
var AllStatus = []Status{
StatusOk,
StatusError,
}
func (e Status) IsValid() bool {
switch e {
case StatusOk, StatusError:
return true
}
return false
}
func (e Status) String() string {
return string(e)
}
func (e *Status) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = Status(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid Status", str)
}
return nil
}
func (e Status) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}