1
2
3 package followschema
4
5 import (
6 "context"
7 "errors"
8 "strconv"
9 "sync"
10 "sync/atomic"
11
12 "github.com/99designs/gqlgen/graphql"
13 "github.com/vektah/gqlparser/v2/ast"
14 )
15
16
17
18 type PrimitiveResolver interface {
19 Value(ctx context.Context, obj *Primitive) (int, error)
20 }
21 type PrimitiveStringResolver interface {
22 Value(ctx context.Context, obj *PrimitiveString) (string, error)
23
24 Len(ctx context.Context, obj *PrimitiveString) (int, error)
25 }
26
27
28
29
30
31
32
33
34
35
36
37
38
39 func (ec *executionContext) _Primitive_value(ctx context.Context, field graphql.CollectedField, obj *Primitive) (ret graphql.Marshaler) {
40 fc, err := ec.fieldContext_Primitive_value(ctx, field)
41 if err != nil {
42 return graphql.Null
43 }
44 ctx = graphql.WithFieldContext(ctx, fc)
45 defer func() {
46 if r := recover(); r != nil {
47 ec.Error(ctx, ec.Recover(ctx, r))
48 ret = graphql.Null
49 }
50 }()
51 resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
52 ctx = rctx
53 return ec.resolvers.Primitive().Value(rctx, obj)
54 })
55
56 if resTmp == nil {
57 if !graphql.HasFieldError(ctx, fc) {
58 ec.Errorf(ctx, "must not be null")
59 }
60 return graphql.Null
61 }
62 res := resTmp.(int)
63 fc.Result = res
64 return ec.marshalNInt2int(ctx, field.Selections, res)
65 }
66
67 func (ec *executionContext) fieldContext_Primitive_value(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
68 fc = &graphql.FieldContext{
69 Object: "Primitive",
70 Field: field,
71 IsMethod: true,
72 IsResolver: true,
73 Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
74 return nil, errors.New("field of type Int does not have child fields")
75 },
76 }
77 return fc, nil
78 }
79
80 func (ec *executionContext) _Primitive_squared(ctx context.Context, field graphql.CollectedField, obj *Primitive) (ret graphql.Marshaler) {
81 fc, err := ec.fieldContext_Primitive_squared(ctx, field)
82 if err != nil {
83 return graphql.Null
84 }
85 ctx = graphql.WithFieldContext(ctx, fc)
86 defer func() {
87 if r := recover(); r != nil {
88 ec.Error(ctx, ec.Recover(ctx, r))
89 ret = graphql.Null
90 }
91 }()
92 resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
93 ctx = rctx
94 return obj.Squared(), nil
95 })
96
97 if resTmp == nil {
98 if !graphql.HasFieldError(ctx, fc) {
99 ec.Errorf(ctx, "must not be null")
100 }
101 return graphql.Null
102 }
103 res := resTmp.(int)
104 fc.Result = res
105 return ec.marshalNInt2int(ctx, field.Selections, res)
106 }
107
108 func (ec *executionContext) fieldContext_Primitive_squared(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
109 fc = &graphql.FieldContext{
110 Object: "Primitive",
111 Field: field,
112 IsMethod: true,
113 IsResolver: false,
114 Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
115 return nil, errors.New("field of type Int does not have child fields")
116 },
117 }
118 return fc, nil
119 }
120
121 func (ec *executionContext) _PrimitiveString_value(ctx context.Context, field graphql.CollectedField, obj *PrimitiveString) (ret graphql.Marshaler) {
122 fc, err := ec.fieldContext_PrimitiveString_value(ctx, field)
123 if err != nil {
124 return graphql.Null
125 }
126 ctx = graphql.WithFieldContext(ctx, fc)
127 defer func() {
128 if r := recover(); r != nil {
129 ec.Error(ctx, ec.Recover(ctx, r))
130 ret = graphql.Null
131 }
132 }()
133 resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
134 ctx = rctx
135 return ec.resolvers.PrimitiveString().Value(rctx, obj)
136 })
137
138 if resTmp == nil {
139 if !graphql.HasFieldError(ctx, fc) {
140 ec.Errorf(ctx, "must not be null")
141 }
142 return graphql.Null
143 }
144 res := resTmp.(string)
145 fc.Result = res
146 return ec.marshalNString2string(ctx, field.Selections, res)
147 }
148
149 func (ec *executionContext) fieldContext_PrimitiveString_value(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
150 fc = &graphql.FieldContext{
151 Object: "PrimitiveString",
152 Field: field,
153 IsMethod: true,
154 IsResolver: true,
155 Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
156 return nil, errors.New("field of type String does not have child fields")
157 },
158 }
159 return fc, nil
160 }
161
162 func (ec *executionContext) _PrimitiveString_doubled(ctx context.Context, field graphql.CollectedField, obj *PrimitiveString) (ret graphql.Marshaler) {
163 fc, err := ec.fieldContext_PrimitiveString_doubled(ctx, field)
164 if err != nil {
165 return graphql.Null
166 }
167 ctx = graphql.WithFieldContext(ctx, fc)
168 defer func() {
169 if r := recover(); r != nil {
170 ec.Error(ctx, ec.Recover(ctx, r))
171 ret = graphql.Null
172 }
173 }()
174 resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
175 ctx = rctx
176 return obj.Doubled(), nil
177 })
178
179 if resTmp == nil {
180 if !graphql.HasFieldError(ctx, fc) {
181 ec.Errorf(ctx, "must not be null")
182 }
183 return graphql.Null
184 }
185 res := resTmp.(string)
186 fc.Result = res
187 return ec.marshalNString2string(ctx, field.Selections, res)
188 }
189
190 func (ec *executionContext) fieldContext_PrimitiveString_doubled(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
191 fc = &graphql.FieldContext{
192 Object: "PrimitiveString",
193 Field: field,
194 IsMethod: true,
195 IsResolver: false,
196 Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
197 return nil, errors.New("field of type String does not have child fields")
198 },
199 }
200 return fc, nil
201 }
202
203 func (ec *executionContext) _PrimitiveString_len(ctx context.Context, field graphql.CollectedField, obj *PrimitiveString) (ret graphql.Marshaler) {
204 fc, err := ec.fieldContext_PrimitiveString_len(ctx, field)
205 if err != nil {
206 return graphql.Null
207 }
208 ctx = graphql.WithFieldContext(ctx, fc)
209 defer func() {
210 if r := recover(); r != nil {
211 ec.Error(ctx, ec.Recover(ctx, r))
212 ret = graphql.Null
213 }
214 }()
215 resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
216 ctx = rctx
217 return ec.resolvers.PrimitiveString().Len(rctx, obj)
218 })
219
220 if resTmp == nil {
221 if !graphql.HasFieldError(ctx, fc) {
222 ec.Errorf(ctx, "must not be null")
223 }
224 return graphql.Null
225 }
226 res := resTmp.(int)
227 fc.Result = res
228 return ec.marshalNInt2int(ctx, field.Selections, res)
229 }
230
231 func (ec *executionContext) fieldContext_PrimitiveString_len(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
232 fc = &graphql.FieldContext{
233 Object: "PrimitiveString",
234 Field: field,
235 IsMethod: true,
236 IsResolver: true,
237 Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
238 return nil, errors.New("field of type Int does not have child fields")
239 },
240 }
241 return fc, nil
242 }
243
244
245
246
247
248
249
250
251
252
253
254
255
256 var primitiveImplementors = []string{"Primitive"}
257
258 func (ec *executionContext) _Primitive(ctx context.Context, sel ast.SelectionSet, obj *Primitive) graphql.Marshaler {
259 fields := graphql.CollectFields(ec.OperationContext, sel, primitiveImplementors)
260
261 out := graphql.NewFieldSet(fields)
262 deferred := make(map[string]*graphql.FieldSet)
263 for i, field := range fields {
264 switch field.Name {
265 case "__typename":
266 out.Values[i] = graphql.MarshalString("Primitive")
267 case "value":
268 field := field
269
270 innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
271 defer func() {
272 if r := recover(); r != nil {
273 ec.Error(ctx, ec.Recover(ctx, r))
274 }
275 }()
276 res = ec._Primitive_value(ctx, field, obj)
277 if res == graphql.Null {
278 atomic.AddUint32(&fs.Invalids, 1)
279 }
280 return res
281 }
282
283 if field.Deferrable != nil {
284 dfs, ok := deferred[field.Deferrable.Label]
285 di := 0
286 if ok {
287 dfs.AddField(field)
288 di = len(dfs.Values) - 1
289 } else {
290 dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
291 deferred[field.Deferrable.Label] = dfs
292 }
293 dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
294 return innerFunc(ctx, dfs)
295 })
296
297
298 out.Values[i] = graphql.Null
299 continue
300 }
301
302 out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
303 case "squared":
304 out.Values[i] = ec._Primitive_squared(ctx, field, obj)
305 if out.Values[i] == graphql.Null {
306 atomic.AddUint32(&out.Invalids, 1)
307 }
308 default:
309 panic("unknown field " + strconv.Quote(field.Name))
310 }
311 }
312 out.Dispatch(ctx)
313 if out.Invalids > 0 {
314 return graphql.Null
315 }
316
317 atomic.AddInt32(&ec.deferred, int32(len(deferred)))
318
319 for label, dfs := range deferred {
320 ec.processDeferredGroup(graphql.DeferredGroup{
321 Label: label,
322 Path: graphql.GetPath(ctx),
323 FieldSet: dfs,
324 Context: ctx,
325 })
326 }
327
328 return out
329 }
330
331 var primitiveStringImplementors = []string{"PrimitiveString"}
332
333 func (ec *executionContext) _PrimitiveString(ctx context.Context, sel ast.SelectionSet, obj *PrimitiveString) graphql.Marshaler {
334 fields := graphql.CollectFields(ec.OperationContext, sel, primitiveStringImplementors)
335
336 out := graphql.NewFieldSet(fields)
337 deferred := make(map[string]*graphql.FieldSet)
338 for i, field := range fields {
339 switch field.Name {
340 case "__typename":
341 out.Values[i] = graphql.MarshalString("PrimitiveString")
342 case "value":
343 field := field
344
345 innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
346 defer func() {
347 if r := recover(); r != nil {
348 ec.Error(ctx, ec.Recover(ctx, r))
349 }
350 }()
351 res = ec._PrimitiveString_value(ctx, field, obj)
352 if res == graphql.Null {
353 atomic.AddUint32(&fs.Invalids, 1)
354 }
355 return res
356 }
357
358 if field.Deferrable != nil {
359 dfs, ok := deferred[field.Deferrable.Label]
360 di := 0
361 if ok {
362 dfs.AddField(field)
363 di = len(dfs.Values) - 1
364 } else {
365 dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
366 deferred[field.Deferrable.Label] = dfs
367 }
368 dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
369 return innerFunc(ctx, dfs)
370 })
371
372
373 out.Values[i] = graphql.Null
374 continue
375 }
376
377 out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
378 case "doubled":
379 out.Values[i] = ec._PrimitiveString_doubled(ctx, field, obj)
380 if out.Values[i] == graphql.Null {
381 atomic.AddUint32(&out.Invalids, 1)
382 }
383 case "len":
384 field := field
385
386 innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) {
387 defer func() {
388 if r := recover(); r != nil {
389 ec.Error(ctx, ec.Recover(ctx, r))
390 }
391 }()
392 res = ec._PrimitiveString_len(ctx, field, obj)
393 if res == graphql.Null {
394 atomic.AddUint32(&fs.Invalids, 1)
395 }
396 return res
397 }
398
399 if field.Deferrable != nil {
400 dfs, ok := deferred[field.Deferrable.Label]
401 di := 0
402 if ok {
403 dfs.AddField(field)
404 di = len(dfs.Values) - 1
405 } else {
406 dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
407 deferred[field.Deferrable.Label] = dfs
408 }
409 dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
410 return innerFunc(ctx, dfs)
411 })
412
413
414 out.Values[i] = graphql.Null
415 continue
416 }
417
418 out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
419 default:
420 panic("unknown field " + strconv.Quote(field.Name))
421 }
422 }
423 out.Dispatch(ctx)
424 if out.Invalids > 0 {
425 return graphql.Null
426 }
427
428 atomic.AddInt32(&ec.deferred, int32(len(deferred)))
429
430 for label, dfs := range deferred {
431 ec.processDeferredGroup(graphql.DeferredGroup{
432 Label: label,
433 Path: graphql.GetPath(ctx),
434 FieldSet: dfs,
435 Context: ctx,
436 })
437 }
438
439 return out
440 }
441
442
443
444
445
446 func (ec *executionContext) marshalNPrimitive2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitive(ctx context.Context, sel ast.SelectionSet, v Primitive) graphql.Marshaler {
447 return ec._Primitive(ctx, sel, &v)
448 }
449
450 func (ec *executionContext) marshalNPrimitive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitiveᚄ(ctx context.Context, sel ast.SelectionSet, v []Primitive) graphql.Marshaler {
451 ret := make(graphql.Array, len(v))
452 var wg sync.WaitGroup
453 isLen1 := len(v) == 1
454 if !isLen1 {
455 wg.Add(len(v))
456 }
457 for i := range v {
458 i := i
459 fc := &graphql.FieldContext{
460 Index: &i,
461 Result: &v[i],
462 }
463 ctx := graphql.WithFieldContext(ctx, fc)
464 f := func(i int) {
465 defer func() {
466 if r := recover(); r != nil {
467 ec.Error(ctx, ec.Recover(ctx, r))
468 ret = nil
469 }
470 }()
471 if !isLen1 {
472 defer wg.Done()
473 }
474 ret[i] = ec.marshalNPrimitive2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitive(ctx, sel, v[i])
475 }
476 if isLen1 {
477 f(i)
478 } else {
479 go f(i)
480 }
481
482 }
483 wg.Wait()
484
485 for _, e := range ret {
486 if e == graphql.Null {
487 return graphql.Null
488 }
489 }
490
491 return ret
492 }
493
494 func (ec *executionContext) marshalNPrimitiveString2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitiveString(ctx context.Context, sel ast.SelectionSet, v PrimitiveString) graphql.Marshaler {
495 return ec._PrimitiveString(ctx, sel, &v)
496 }
497
498 func (ec *executionContext) marshalNPrimitiveString2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitiveStringᚄ(ctx context.Context, sel ast.SelectionSet, v []PrimitiveString) graphql.Marshaler {
499 ret := make(graphql.Array, len(v))
500 var wg sync.WaitGroup
501 isLen1 := len(v) == 1
502 if !isLen1 {
503 wg.Add(len(v))
504 }
505 for i := range v {
506 i := i
507 fc := &graphql.FieldContext{
508 Index: &i,
509 Result: &v[i],
510 }
511 ctx := graphql.WithFieldContext(ctx, fc)
512 f := func(i int) {
513 defer func() {
514 if r := recover(); r != nil {
515 ec.Error(ctx, ec.Recover(ctx, r))
516 ret = nil
517 }
518 }()
519 if !isLen1 {
520 defer wg.Done()
521 }
522 ret[i] = ec.marshalNPrimitiveString2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚋfollowschemaᚐPrimitiveString(ctx, sel, v[i])
523 }
524 if isLen1 {
525 f(i)
526 } else {
527 go f(i)
528 }
529
530 }
531 wg.Wait()
532
533 for _, e := range ret {
534 if e == graphql.Null {
535 return graphql.Null
536 }
537 }
538
539 return ret
540 }
541
542
543
View as plain text