From 02873495e1f85ae83e38cf79e52a2122a845986f Mon Sep 17 00:00:00 2001 From: vvakame Date: Fri, 24 Aug 2018 16:23:58 +0900 Subject: [PATCH 1/2] use goroutine about processing each array elements --- codegen/object.go | 31 +- codegen/testserver/generated.go | 335 ++++++++++++++-------- example/chat/generated.go | 267 +++++++++++------- example/config/generated.go | 267 +++++++++++------- example/dataloader/generated.go | 396 ++++++++++++++++---------- example/scalars/generated.go | 267 +++++++++++------- example/selection/generated.go | 335 ++++++++++++++-------- example/starwars/generated.go | 485 +++++++++++++++++++++----------- example/todo/generated.go | 267 +++++++++++------- integration/generated.go | 307 +++++++++++++------- 10 files changed, 1910 insertions(+), 1047 deletions(-) diff --git a/codegen/object.go b/codegen/object.go index 93d1952102..fc0669b4ad 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -212,28 +212,37 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ } var arr = "arr" + strconv.Itoa(depth) var index = "idx" + strconv.Itoa(depth) + var wg = "wg" + strconv.Itoa(depth) var usePtr bool if len(remainingMods) == 1 && !isPtr { usePtr = true } - return tpl(`{{.arr}} := graphql.Array{} + return tpl(` + {{.arr}} := make(graphql.Array, len({{.val}})) + var {{.wg}} sync.WaitGroup + {{.wg}}.Add(len({{.val}})) for {{.index}} := range {{.val}} { - {{- if not .isScalar }} - rctx := &graphql.ResolverContext{ - Index: &{{.index}}, - Result: {{ if .usePtr }}&{{end}}{{.val}}[{{.index}}], - } - ctx := graphql.WithResolverContext(ctx, rctx) - {{- end}} - {{.arr}} = append({{.arr}}, func() graphql.Marshaler { - {{ .next }} - }()) + go func({{.index}} int) { + defer {{.wg}}.Done() + {{- if not .isScalar }} + rctx := &graphql.ResolverContext{ + Index: &{{.index}}, + Result: {{ if .usePtr }}&{{end}}{{.val}}[{{.index}}], + } + ctx := graphql.WithResolverContext(ctx, rctx) + {{- end}} + {{.arr}}[{{.index}}] = func() graphql.Marshaler { + {{ .next }} + }() + }({{.index}}) } + {{.wg}}.Wait() return {{.arr}}`, map[string]interface{}{ "val": val, "arr": arr, "index": index, + "wg": wg, "isScalar": f.IsScalar, "usePtr": usePtr, "next": f.doWriteJson(val+"["+index+"]", remainingMods[1:], astType.Elem, false, depth+1), diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 3402ee3dce..9c423de327 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -872,33 +872,47 @@ func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field grap } res := resTmp.([][]*OuterObject) rctx.Result = res - arr1 := graphql.Array{} - for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { - arr2 := graphql.Array{} - for idx2 := range res[idx1] { - rctx := &graphql.ResolverContext{ - Index: &idx2, - Result: res[idx1][idx2], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr2 = append(arr2, func() graphql.Marshaler { - - if res[idx1][idx2] == nil { - return graphql.Null - } - return ec._OuterObject(ctx, field.Selections, res[idx1][idx2]) - }()) + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) + for idx1 := range res { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: res[idx1], } - return arr2 - }()) + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { + + arr2 := make(graphql.Array, len(res[idx1])) + var wg2 sync.WaitGroup + wg2.Add(len(res[idx1])) + for idx2 := range res[idx1] { + go func(idx2 int) { + defer wg2.Done() + rctx := &graphql.ResolverContext{ + Index: &idx2, + Result: res[idx1][idx2], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr2[idx2] = func() graphql.Marshaler { + + if res[idx1][idx2] == nil { + return graphql.Null + } + + return ec._OuterObject(ctx, field.Selections, res[idx1][idx2]) + }() + }(idx2) + } + wg2.Wait() + return arr2 + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -957,22 +971,29 @@ func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.Col } res := resTmp.([]*Shape) rctx.Result = res - arr1 := graphql.Array{} - for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { - if res[idx1] == nil { - return graphql.Null + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) + for idx1 := range res { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: res[idx1], } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { + + if res[idx1] == nil { + return graphql.Null + } - return ec._Shape(ctx, field.Selections, res[idx1]) - }()) + return ec._Shape(ctx, field.Selections, res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1546,12 +1567,19 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -1574,18 +1602,25 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1819,18 +1854,25 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2101,18 +2143,25 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2213,18 +2262,25 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap } res := resTmp.([]introspection.Directive) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Directive(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2366,18 +2422,25 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co } res := resTmp.([]introspection.Field) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Field(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Field(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2397,18 +2460,25 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2428,18 +2498,25 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2471,18 +2548,25 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq } res := resTmp.([]introspection.EnumValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___EnumValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2502,18 +2586,25 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } diff --git a/example/chat/generated.go b/example/chat/generated.go index b9be4e6d37..2c840e3fe6 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -196,18 +196,25 @@ func (ec *executionContext) _Chatroom_messages(ctx context.Context, field graphq } res := resTmp.([]Message) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Message(ctx, field.Selections, &res[idx1]) - }()) + return ec._Message(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -726,12 +733,19 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -754,18 +768,25 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -999,18 +1020,25 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1281,18 +1309,25 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1393,18 +1428,25 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap } res := resTmp.([]introspection.Directive) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Directive(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1546,18 +1588,25 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co } res := resTmp.([]introspection.Field) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Field(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Field(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1577,18 +1626,25 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1608,18 +1664,25 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1651,18 +1714,25 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq } res := resTmp.([]introspection.EnumValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___EnumValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1682,18 +1752,25 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } diff --git a/example/config/generated.go b/example/config/generated.go index fa61d1c989..60bd6d0387 100644 --- a/example/config/generated.go +++ b/example/config/generated.go @@ -226,18 +226,25 @@ func (ec *executionContext) _Query_todos(ctx context.Context, field graphql.Coll } res := resTmp.([]Todo) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Todo(ctx, field.Selections, &res[idx1]) - }()) + return ec._Todo(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -648,12 +655,19 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -676,18 +690,25 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -921,18 +942,25 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1203,18 +1231,25 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1315,18 +1350,25 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap } res := resTmp.([]introspection.Directive) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Directive(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1468,18 +1510,25 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co } res := resTmp.([]introspection.Field) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Field(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Field(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1499,18 +1548,25 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1530,18 +1586,25 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1573,18 +1636,25 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq } res := resTmp.([]introspection.EnumValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___EnumValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1604,18 +1674,25 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index 278d5f7285..c3718bd577 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -325,18 +325,25 @@ func (ec *executionContext) _Customer_orders(ctx context.Context, field graphql. } res := resTmp.([]Order) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Order(ctx, field.Selections, &res[idx1]) - }()) + return ec._Order(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -521,18 +528,25 @@ func (ec *executionContext) _Order_items(ctx context.Context, field graphql.Coll } res := resTmp.([]Item) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Item(ctx, field.Selections, &res[idx1]) - }()) + return ec._Item(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -604,18 +618,25 @@ func (ec *executionContext) _Query_customers(ctx context.Context, field graphql. } res := resTmp.([]Customer) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Customer(ctx, field.Selections, &res[idx1]) - }()) + return ec._Customer(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -658,18 +679,25 @@ func (ec *executionContext) _Query_torture1d(ctx context.Context, field graphql. } res := resTmp.([]Customer) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Customer(ctx, field.Selections, &res[idx1]) - }()) + return ec._Customer(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -723,29 +751,43 @@ func (ec *executionContext) _Query_torture2d(ctx context.Context, field graphql. } res := resTmp.([][]Customer) rctx.Result = res - arr1 := graphql.Array{} - for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { - arr2 := graphql.Array{} - for idx2 := range res[idx1] { - rctx := &graphql.ResolverContext{ - Index: &idx2, - Result: &res[idx1][idx2], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr2 = append(arr2, func() graphql.Marshaler { - return ec._Customer(ctx, field.Selections, &res[idx1][idx2]) - }()) + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) + for idx1 := range res { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: res[idx1], } - return arr2 - }()) + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { + + arr2 := make(graphql.Array, len(res[idx1])) + var wg2 sync.WaitGroup + wg2.Add(len(res[idx1])) + for idx2 := range res[idx1] { + go func(idx2 int) { + defer wg2.Done() + rctx := &graphql.ResolverContext{ + Index: &idx2, + Result: &res[idx1][idx2], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr2[idx2] = func() graphql.Marshaler { + + return ec._Customer(ctx, field.Selections, &res[idx1][idx2]) + }() + }(idx2) + } + wg2.Wait() + return arr2 + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -911,12 +953,19 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -939,18 +988,25 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1184,18 +1240,25 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1466,18 +1529,25 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1578,18 +1648,25 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap } res := resTmp.([]introspection.Directive) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Directive(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1731,18 +1808,25 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co } res := resTmp.([]introspection.Field) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Field(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Field(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1762,18 +1846,25 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1793,18 +1884,25 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1836,18 +1934,25 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq } res := resTmp.([]introspection.EnumValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___EnumValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1867,18 +1972,25 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } diff --git a/example/scalars/generated.go b/example/scalars/generated.go index b10520bbe0..9d60f27e8c 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -277,18 +277,25 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col } res := resTmp.([]model.User) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._User(ctx, field.Selections, &res[idx1]) - }()) + return ec._User(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -687,12 +694,19 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -715,18 +729,25 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -960,18 +981,25 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1242,18 +1270,25 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1354,18 +1389,25 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap } res := resTmp.([]introspection.Directive) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Directive(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1507,18 +1549,25 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co } res := resTmp.([]introspection.Field) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Field(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Field(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1538,18 +1587,25 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1569,18 +1625,25 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1612,18 +1675,25 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq } res := resTmp.([]introspection.EnumValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___EnumValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1643,18 +1713,25 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } diff --git a/example/selection/generated.go b/example/selection/generated.go index ceaa5d93c6..6d12753108 100644 --- a/example/selection/generated.go +++ b/example/selection/generated.go @@ -176,12 +176,19 @@ func (ec *executionContext) _Like_selection(ctx context.Context, field graphql.C } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -201,12 +208,19 @@ func (ec *executionContext) _Like_collected(ctx context.Context, field graphql.C } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -309,12 +323,19 @@ func (ec *executionContext) _Post_selection(ctx context.Context, field graphql.C } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -334,12 +355,19 @@ func (ec *executionContext) _Post_collected(ctx context.Context, field graphql.C } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -399,18 +427,25 @@ func (ec *executionContext) _Query_events(ctx context.Context, field graphql.Col } res := resTmp.([]Event) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Event(ctx, field.Selections, &res[idx1]) - }()) + return ec._Event(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -576,12 +611,19 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -604,18 +646,25 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -849,18 +898,25 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1131,18 +1187,25 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1243,18 +1306,25 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap } res := resTmp.([]introspection.Directive) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Directive(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1396,18 +1466,25 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co } res := resTmp.([]introspection.Field) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Field(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Field(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1427,18 +1504,25 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1458,18 +1542,25 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1501,18 +1592,25 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq } res := resTmp.([]introspection.EnumValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___EnumValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1532,18 +1630,25 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } diff --git a/example/starwars/generated.go b/example/starwars/generated.go index 8237b1371d..c38bc0db7f 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated.go @@ -238,18 +238,25 @@ func (ec *executionContext) _Droid_friends(ctx context.Context, field graphql.Co } res := resTmp.([]Character) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Character(ctx, field.Selections, &res[idx1]) - }()) + return ec._Character(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -327,12 +334,19 @@ func (ec *executionContext) _Droid_appearsIn(ctx context.Context, field graphql. } res := resTmp.([]Episode) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return res[idx1] - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return res[idx1] + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -441,18 +455,25 @@ func (ec *executionContext) _FriendsConnection_edges(ctx context.Context, field } res := resTmp.([]FriendsEdge) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._FriendsEdge(ctx, field.Selections, &res[idx1]) - }()) + return ec._FriendsEdge(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -472,18 +493,25 @@ func (ec *executionContext) _FriendsConnection_friends(ctx context.Context, fiel } res := resTmp.([]Character) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Character(ctx, field.Selections, &res[idx1]) - }()) + return ec._Character(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -766,18 +794,25 @@ func (ec *executionContext) _Human_friends(ctx context.Context, field graphql.Co } res := resTmp.([]Character) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Character(ctx, field.Selections, &res[idx1]) - }()) + return ec._Character(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -855,12 +890,19 @@ func (ec *executionContext) _Human_appearsIn(ctx context.Context, field graphql. } res := resTmp.([]Episode) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return res[idx1] - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return res[idx1] + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -880,18 +922,25 @@ func (ec *executionContext) _Human_starships(ctx context.Context, field graphql. } res := resTmp.([]Starship) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Starship(ctx, field.Selections, &res[idx1]) - }()) + return ec._Starship(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1238,18 +1287,25 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co } res := resTmp.([]Review) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Review(ctx, field.Selections, &res[idx1]) - }()) + return ec._Review(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1284,18 +1340,25 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col } res := resTmp.([]SearchResult) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._SearchResult(ctx, field.Selections, &res[idx1]) - }()) + return ec._SearchResult(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1744,18 +1807,32 @@ func (ec *executionContext) _Starship_history(ctx context.Context, field graphql } res := resTmp.([][]int) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - arr2 := graphql.Array{} - for idx2 := range res[idx1] { - arr2 = append(arr2, func() graphql.Marshaler { - return graphql.MarshalInt(res[idx1][idx2]) - }()) - } - return arr2 - }()) + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + + arr2 := make(graphql.Array, len(res[idx1])) + var wg2 sync.WaitGroup + wg2.Add(len(res[idx1])) + for idx2 := range res[idx1] { + go func(idx2 int) { + defer wg2.Done() + arr2[idx2] = func() graphql.Marshaler { + return graphql.MarshalInt(res[idx1][idx2]) + }() + }(idx2) + } + wg2.Wait() + return arr2 + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1861,12 +1938,19 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -1889,18 +1973,25 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2134,18 +2225,25 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2416,18 +2514,25 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2528,18 +2633,25 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap } res := resTmp.([]introspection.Directive) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Directive(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2681,18 +2793,25 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co } res := resTmp.([]introspection.Field) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Field(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Field(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2712,18 +2831,25 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2743,18 +2869,25 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2786,18 +2919,25 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq } res := resTmp.([]introspection.EnumValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___EnumValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -2817,18 +2957,25 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } diff --git a/example/todo/generated.go b/example/todo/generated.go index 13164a1e6e..ebe2a66a04 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -346,18 +346,25 @@ func (ec *executionContext) _MyQuery_todos(ctx context.Context, field graphql.Co } res := resTmp.([]Todo) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Todo(ctx, field.Selections, &res[idx1]) - }()) + return ec._Todo(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -629,12 +636,19 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -657,18 +671,25 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -902,18 +923,25 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1184,18 +1212,25 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1296,18 +1331,25 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap } res := resTmp.([]introspection.Directive) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Directive(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1449,18 +1491,25 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co } res := resTmp.([]introspection.Field) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Field(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Field(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1480,18 +1529,25 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1511,18 +1567,25 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1554,18 +1617,25 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq } res := resTmp.([]introspection.EnumValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___EnumValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1585,18 +1655,25 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } diff --git a/integration/generated.go b/integration/generated.go index 1bbad67243..21f86a3cf4 100644 --- a/integration/generated.go +++ b/integration/generated.go @@ -203,12 +203,19 @@ func (ec *executionContext) _Element_mismatched(ctx context.Context, field graph } res := resTmp.([]bool) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalBoolean(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalBoolean(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -301,22 +308,29 @@ func (ec *executionContext) _Query_path(ctx context.Context, field graphql.Colle } res := resTmp.([]*models.Element) rctx.Result = res - arr1 := graphql.Array{} - for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { - if res[idx1] == nil { - return graphql.Null + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) + for idx1 := range res { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: res[idx1], } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec._Element(ctx, field.Selections, res[idx1]) - }()) + if res[idx1] == nil { + return graphql.Null + } + + return ec._Element(ctx, field.Selections, res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -575,12 +589,19 @@ func (ec *executionContext) _User_likes(ctx context.Context, field graphql.Colle } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -737,12 +758,19 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr } res := resTmp.([]string) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - arr1 = append(arr1, func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }()) - } + go func(idx1 int) { + defer wg1.Done() + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() + }(idx1) + } + wg1.Wait() return arr1 } @@ -765,18 +793,25 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1010,18 +1045,25 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1292,18 +1334,25 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1404,18 +1453,25 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap } res := resTmp.([]introspection.Directive) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Directive(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Directive(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1557,18 +1613,25 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co } res := resTmp.([]introspection.Field) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Field(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Field(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1588,18 +1651,25 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1619,18 +1689,25 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra } res := resTmp.([]introspection.Type) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___Type(ctx, field.Selections, &res[idx1]) - }()) + return ec.___Type(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1662,18 +1739,25 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq } res := resTmp.([]introspection.EnumValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___EnumValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___EnumValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } @@ -1693,18 +1777,25 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph } res := resTmp.([]introspection.InputValue) rctx.Result = res - arr1 := graphql.Array{} + + arr1 := make(graphql.Array, len(res)) + var wg1 sync.WaitGroup + wg1.Add(len(res)) for idx1 := range res { - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], - } - ctx := graphql.WithResolverContext(ctx, rctx) - arr1 = append(arr1, func() graphql.Marshaler { + go func(idx1 int) { + defer wg1.Done() + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + arr1[idx1] = func() graphql.Marshaler { - return ec.___InputValue(ctx, field.Selections, &res[idx1]) - }()) + return ec.___InputValue(ctx, field.Selections, &res[idx1]) + }() + }(idx1) } + wg1.Wait() return arr1 } From fce4c722a818665a1b0277693a5123b6f166f4a8 Mon Sep 17 00:00:00 2001 From: vvakame Date: Mon, 27 Aug 2018 13:01:36 +0900 Subject: [PATCH 2/2] address comment --- codegen/object.go | 45 ++- codegen/testserver/generated.go | 421 +++++++++++++++------- example/chat/generated.go | 354 ++++++++++++------ example/config/generated.go | 354 ++++++++++++------ example/dataloader/generated.go | 523 +++++++++++++++++++-------- example/scalars/generated.go | 354 ++++++++++++------ example/selection/generated.go | 410 +++++++++++++-------- example/starwars/generated.go | 620 +++++++++++++++++++++----------- example/todo/generated.go | 354 ++++++++++++------ integration/generated.go | 382 +++++++++++++------- 10 files changed, 2599 insertions(+), 1218 deletions(-) diff --git a/codegen/object.go b/codegen/object.go index fc0669b4ad..041c99c748 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -212,7 +212,6 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ } var arr = "arr" + strconv.Itoa(depth) var index = "idx" + strconv.Itoa(depth) - var wg = "wg" + strconv.Itoa(depth) var usePtr bool if len(remainingMods) == 1 && !isPtr { usePtr = true @@ -220,29 +219,47 @@ func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Typ return tpl(` {{.arr}} := make(graphql.Array, len({{.val}})) - var {{.wg}} sync.WaitGroup - {{.wg}}.Add(len({{.val}})) + {{ if and .top (not .isScalar) }} var wg sync.WaitGroup {{ end }} + {{ if not .isScalar }} + isLen1 := len({{.val}}) == 1 + if !isLen1 { + wg.Add(len({{.val}})) + } + {{ end }} for {{.index}} := range {{.val}} { - go func({{.index}} int) { - defer {{.wg}}.Done() - {{- if not .isScalar }} - rctx := &graphql.ResolverContext{ - Index: &{{.index}}, - Result: {{ if .usePtr }}&{{end}}{{.val}}[{{.index}}], + {{- if not .isScalar }} + {{.index}} := {{.index}} + rctx := &graphql.ResolverContext{ + Index: &{{.index}}, + Result: {{ if .usePtr }}&{{end}}{{.val}}[{{.index}}], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func({{.index}} int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) - {{- end}} + {{.arr}}[{{.index}}] = func() graphql.Marshaler { + {{ .next }} + }() + } + if isLen1 { + f({{.index}}) + } else { + go f({{.index}}) + } + {{ else }} {{.arr}}[{{.index}}] = func() graphql.Marshaler { {{ .next }} }() - }({{.index}}) + {{- end}} } - {{.wg}}.Wait() + {{ if and .top (not .isScalar) }} wg.Wait() {{ end }} return {{.arr}}`, map[string]interface{}{ "val": val, "arr": arr, "index": index, - "wg": wg, + "top": depth == 1, + "arrayLen": len(val), "isScalar": f.IsScalar, "usePtr": usePtr, "next": f.doWriteJson(val+"["+index+"]", remainingMods[1:], astType.Elem, false, depth+1), diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 9c423de327..e300041d2b 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -874,29 +874,44 @@ func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field grap rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { arr2 := make(graphql.Array, len(res[idx1])) - var wg2 sync.WaitGroup - wg2.Add(len(res[idx1])) + + isLen1 := len(res[idx1]) == 1 + if !isLen1 { + wg.Add(len(res[idx1])) + } + for idx2 := range res[idx1] { - go func(idx2 int) { - defer wg2.Done() - rctx := &graphql.ResolverContext{ - Index: &idx2, - Result: res[idx1][idx2], + idx2 := idx2 + rctx := &graphql.ResolverContext{ + Index: &idx2, + Result: res[idx1][idx2], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx2 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr2[idx2] = func() graphql.Marshaler { if res[idx1][idx2] == nil { @@ -905,14 +920,26 @@ func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field grap return ec._OuterObject(ctx, field.Selections, res[idx1][idx2]) }() - }(idx2) + } + if isLen1 { + f(idx2) + } else { + go f(idx2) + } + } - wg2.Wait() + return arr2 }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -973,16 +1000,24 @@ func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { if res[idx1] == nil { @@ -991,9 +1026,15 @@ func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.Col return ec._Shape(ctx, field.Selections, res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1569,17 +1610,13 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -1604,23 +1641,37 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1856,23 +1907,37 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2145,23 +2210,37 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2264,23 +2343,37 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Directive(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2424,23 +2517,37 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Field(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2462,23 +2569,37 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2500,23 +2621,37 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2550,23 +2685,37 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___EnumValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2588,23 +2737,37 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } diff --git a/example/chat/generated.go b/example/chat/generated.go index 2c840e3fe6..588d5f884b 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -198,23 +198,37 @@ func (ec *executionContext) _Chatroom_messages(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Message(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -735,17 +749,13 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -770,23 +780,37 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1022,23 +1046,37 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1311,23 +1349,37 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1430,23 +1482,37 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Directive(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1590,23 +1656,37 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Field(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1628,23 +1708,37 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1666,23 +1760,37 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1716,23 +1824,37 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___EnumValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1754,23 +1876,37 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } diff --git a/example/config/generated.go b/example/config/generated.go index 60bd6d0387..5f6f51403c 100644 --- a/example/config/generated.go +++ b/example/config/generated.go @@ -228,23 +228,37 @@ func (ec *executionContext) _Query_todos(ctx context.Context, field graphql.Coll rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Todo(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -657,17 +671,13 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -692,23 +702,37 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -944,23 +968,37 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1233,23 +1271,37 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1352,23 +1404,37 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Directive(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1512,23 +1578,37 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Field(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1550,23 +1630,37 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1588,23 +1682,37 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1638,23 +1746,37 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___EnumValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1676,23 +1798,37 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index c3718bd577..8ad2fc63ed 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -327,23 +327,37 @@ func (ec *executionContext) _Customer_orders(ctx context.Context, field graphql. rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Order(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -530,23 +544,37 @@ func (ec *executionContext) _Order_items(ctx context.Context, field graphql.Coll rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Item(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -620,23 +648,37 @@ func (ec *executionContext) _Query_customers(ctx context.Context, field graphql. rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Customer(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -681,23 +723,37 @@ func (ec *executionContext) _Query_torture1d(ctx context.Context, field graphql. rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Customer(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -753,41 +809,68 @@ func (ec *executionContext) _Query_torture2d(ctx context.Context, field graphql. rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { arr2 := make(graphql.Array, len(res[idx1])) - var wg2 sync.WaitGroup - wg2.Add(len(res[idx1])) + + isLen1 := len(res[idx1]) == 1 + if !isLen1 { + wg.Add(len(res[idx1])) + } + for idx2 := range res[idx1] { - go func(idx2 int) { - defer wg2.Done() - rctx := &graphql.ResolverContext{ - Index: &idx2, - Result: &res[idx1][idx2], + idx2 := idx2 + rctx := &graphql.ResolverContext{ + Index: &idx2, + Result: &res[idx1][idx2], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx2 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr2[idx2] = func() graphql.Marshaler { return ec._Customer(ctx, field.Selections, &res[idx1][idx2]) }() - }(idx2) + } + if isLen1 { + f(idx2) + } else { + go f(idx2) + } + } - wg2.Wait() + return arr2 }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -955,17 +1038,13 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -990,23 +1069,37 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1242,23 +1335,37 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1531,23 +1638,37 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1650,23 +1771,37 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Directive(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1810,23 +1945,37 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Field(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1848,23 +1997,37 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1886,23 +2049,37 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1936,23 +2113,37 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___EnumValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1974,23 +2165,37 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } diff --git a/example/scalars/generated.go b/example/scalars/generated.go index 9d60f27e8c..b44bc68e07 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -279,23 +279,37 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._User(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -696,17 +710,13 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -731,23 +741,37 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -983,23 +1007,37 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1272,23 +1310,37 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1391,23 +1443,37 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Directive(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1551,23 +1617,37 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Field(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1589,23 +1669,37 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1627,23 +1721,37 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1677,23 +1785,37 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___EnumValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1715,23 +1837,37 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } diff --git a/example/selection/generated.go b/example/selection/generated.go index 6d12753108..f49b0a6e02 100644 --- a/example/selection/generated.go +++ b/example/selection/generated.go @@ -178,17 +178,13 @@ func (ec *executionContext) _Like_selection(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -210,17 +206,13 @@ func (ec *executionContext) _Like_collected(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -325,17 +317,13 @@ func (ec *executionContext) _Post_selection(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -357,17 +345,13 @@ func (ec *executionContext) _Post_collected(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -429,23 +413,37 @@ func (ec *executionContext) _Query_events(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Event(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -613,17 +611,13 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -648,23 +642,37 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -900,23 +908,37 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1189,23 +1211,37 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1308,23 +1344,37 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Directive(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1468,23 +1518,37 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Field(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1506,23 +1570,37 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1544,23 +1622,37 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1594,23 +1686,37 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___EnumValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1632,23 +1738,37 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } diff --git a/example/starwars/generated.go b/example/starwars/generated.go index c38bc0db7f..9213b5753f 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated.go @@ -240,23 +240,37 @@ func (ec *executionContext) _Droid_friends(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Character(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -336,17 +350,13 @@ func (ec *executionContext) _Droid_appearsIn(ctx context.Context, field graphql. rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return res[idx1] - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return res[idx1] + }() } - wg1.Wait() + return arr1 } @@ -457,23 +467,37 @@ func (ec *executionContext) _FriendsConnection_edges(ctx context.Context, field rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._FriendsEdge(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -495,23 +519,37 @@ func (ec *executionContext) _FriendsConnection_friends(ctx context.Context, fiel rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Character(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -796,23 +834,37 @@ func (ec *executionContext) _Human_friends(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Character(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -892,17 +944,13 @@ func (ec *executionContext) _Human_appearsIn(ctx context.Context, field graphql. rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return res[idx1] - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return res[idx1] + }() } - wg1.Wait() + return arr1 } @@ -924,23 +972,37 @@ func (ec *executionContext) _Human_starships(ctx context.Context, field graphql. rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Starship(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1289,23 +1351,37 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Review(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1342,23 +1418,37 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._SearchResult(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1809,30 +1899,22 @@ func (ec *executionContext) _Starship_history(ctx context.Context, field graphql rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { + arr1[idx1] = func() graphql.Marshaler { - arr2 := make(graphql.Array, len(res[idx1])) - var wg2 sync.WaitGroup - wg2.Add(len(res[idx1])) - for idx2 := range res[idx1] { - go func(idx2 int) { - defer wg2.Done() - arr2[idx2] = func() graphql.Marshaler { - return graphql.MarshalInt(res[idx1][idx2]) - }() - }(idx2) - } - wg2.Wait() - return arr2 - }() - }(idx1) + arr2 := make(graphql.Array, len(res[idx1])) + + for idx2 := range res[idx1] { + arr2[idx2] = func() graphql.Marshaler { + return graphql.MarshalInt(res[idx1][idx2]) + }() + } + + return arr2 + }() } - wg1.Wait() + return arr1 } @@ -1940,17 +2022,13 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -1975,23 +2053,37 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2227,23 +2319,37 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2516,23 +2622,37 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2635,23 +2755,37 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Directive(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2795,23 +2929,37 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Field(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2833,23 +2981,37 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2871,23 +3033,37 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2921,23 +3097,37 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___EnumValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -2959,23 +3149,37 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } diff --git a/example/todo/generated.go b/example/todo/generated.go index ebe2a66a04..49485cb0e4 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -348,23 +348,37 @@ func (ec *executionContext) _MyQuery_todos(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec._Todo(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -638,17 +652,13 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -673,23 +683,37 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -925,23 +949,37 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1214,23 +1252,37 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1333,23 +1385,37 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Directive(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1493,23 +1559,37 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Field(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1531,23 +1611,37 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1569,23 +1663,37 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1619,23 +1727,37 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___EnumValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1657,23 +1779,37 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } diff --git a/integration/generated.go b/integration/generated.go index 21f86a3cf4..bf648ad6f6 100644 --- a/integration/generated.go +++ b/integration/generated.go @@ -205,17 +205,13 @@ func (ec *executionContext) _Element_mismatched(ctx context.Context, field graph rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalBoolean(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalBoolean(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -310,16 +306,24 @@ func (ec *executionContext) _Query_path(ctx context.Context, field graphql.Colle rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { if res[idx1] == nil { @@ -328,9 +332,15 @@ func (ec *executionContext) _Query_path(ctx context.Context, field graphql.Colle return ec._Element(ctx, field.Selections, res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -591,17 +601,13 @@ func (ec *executionContext) _User_likes(ctx context.Context, field graphql.Colle rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -760,17 +766,13 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - arr1[idx1] = func() graphql.Marshaler { - return graphql.MarshalString(res[idx1]) - }() - }(idx1) + arr1[idx1] = func() graphql.Marshaler { + return graphql.MarshalString(res[idx1]) + }() } - wg1.Wait() + return arr1 } @@ -795,23 +797,37 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1047,23 +1063,37 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1336,23 +1366,37 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1455,23 +1499,37 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Directive(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1615,23 +1673,37 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Field(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1653,23 +1725,37 @@ func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1691,23 +1777,37 @@ func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field gra rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___Type(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1741,23 +1841,37 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___EnumValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 } @@ -1779,23 +1893,37 @@ func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graph rctx.Result = res arr1 := make(graphql.Array, len(res)) - var wg1 sync.WaitGroup - wg1.Add(len(res)) + var wg sync.WaitGroup + + isLen1 := len(res) == 1 + if !isLen1 { + wg.Add(len(res)) + } + for idx1 := range res { - go func(idx1 int) { - defer wg1.Done() - rctx := &graphql.ResolverContext{ - Index: &idx1, - Result: &res[idx1], + idx1 := idx1 + rctx := &graphql.ResolverContext{ + Index: &idx1, + Result: &res[idx1], + } + ctx := graphql.WithResolverContext(ctx, rctx) + f := func(idx1 int) { + if !isLen1 { + defer wg.Done() } - ctx := graphql.WithResolverContext(ctx, rctx) arr1[idx1] = func() graphql.Marshaler { return ec.___InputValue(ctx, field.Selections, &res[idx1]) }() - }(idx1) + } + if isLen1 { + f(idx1) + } else { + go f(idx1) + } + } - wg1.Wait() + wg.Wait() return arr1 }