Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
fixed marshal array and types
Browse files Browse the repository at this point in the history
  • Loading branch information
Code-Hex committed Apr 2, 2021
1 parent 9068a84 commit 9cfca7e
Showing 1 changed file with 44 additions and 230 deletions.
274 changes: 44 additions & 230 deletions internal/gqlgen/gqlgen2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package gqlgen
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"reflect"
"strconv"
"sync"

Expand Down Expand Up @@ -124,7 +126,7 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col
}

res := ec.introspectType(args["name"].(string))
return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res)
return ec.marshalType(ctx, field.Selections, res)
}

func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
Expand All @@ -144,18 +146,12 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field

func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) {
res := obj.Locations
if res == nil {
return graphql.Null
}
return ec.marshalN__DirectiveLocation2ᚕstringᚄ(ctx, field.Selections, res)
return ec.marshalArray(ctx, field.Selections, res)
}

func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) {
res := obj.Args
if res == nil {
return graphql.Null
}
return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res)
return ec.marshalArray(ctx, field.Selections, res)
}

func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) {
Expand Down Expand Up @@ -193,7 +189,7 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap

func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) {
res := obj.Args
return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res)
return ec.marshalArray(ctx, field.Selections, res)
}

func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) {
Expand Down Expand Up @@ -245,7 +241,7 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel

func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) {
res := obj.Types()
return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res)
return ec.marshalArray(ctx, field.Selections, res)
}

func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) {
Expand All @@ -258,23 +254,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph

func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) {
res := obj.MutationType()
if res == nil {
return graphql.Null
}
return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res)
return ec.marshalType(ctx, field.Selections, res)
}

func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) {
res := obj.SubscriptionType()
if res == nil {
return graphql.Null
}
return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res)
return ec.marshalType(ctx, field.Selections, res)
}

func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) {
res := obj.Directives()
return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirectiveᚄ(ctx, field.Selections, res)
return ec.marshalArray(ctx, field.Selections, res)
}

func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) {
Expand Down Expand Up @@ -304,17 +294,17 @@ func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.Co
}

res := obj.Fields(args["includeDeprecated"].(bool))
return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐFieldᚄ(ctx, field.Selections, res)
return ec.marshalArray(ctx, field.Selections, res)
}

func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) {
res := obj.Interfaces()
return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res)
return ec.marshalArray(ctx, field.Selections, res)
}

func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) {
res := obj.PossibleTypes()
return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res)
return ec.marshalArray(ctx, field.Selections, res)
}

func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) {
Expand All @@ -326,20 +316,17 @@ func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphq
}

res := obj.EnumValues(args["includeDeprecated"].(bool))
return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValueᚄ(ctx, field.Selections, res)
return ec.marshalArray(ctx, field.Selections, res)
}

func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) {
res := obj.InputFields()
return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res)
return ec.marshalArray(ctx, field.Selections, res)
}

func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) {
res := obj.OfType()
if res == nil {
return graphql.Null
}
return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res)
return ec.marshalType(ctx, field.Selections, res)
}

func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler {
Expand Down Expand Up @@ -599,219 +586,46 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o
return out
}

func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirectiveᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler {
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
if !isLen1 {
wg.Add(len(v))
}
for i := range v {
i := i
f := func(i int) {
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.___Directive(ctx, sel, &v[i])
}
if isLen1 {
f(i)
} else {
go f(i)
}

}
wg.Wait()
return ret
}

func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) {
res, err := graphql.UnmarshalString(v)
return res, graphql.ErrorOnPath(ctx, err)
}

func (ec *executionContext) marshalN__DirectiveLocation2ᚕstringᚄ(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler {
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
if !isLen1 {
wg.Add(len(v))
}
for i := range v {
i := i
f := func(i int) {
if !isLen1 {
defer wg.Done()
}
ret[i] = graphql.MarshalString(v[i])
}
if isLen1 {
f(i)
} else {
go f(i)
}

}
wg.Wait()
return ret
}

func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler {
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
if !isLen1 {
wg.Add(len(v))
}
for i := range v {
i := i
f := func(i int) {
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.___InputValue(ctx, sel, &v[i])
}
if isLen1 {
f(i)
} else {
go f(i)
}

}
wg.Wait()
return ret
}

func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler {
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
if !isLen1 {
wg.Add(len(v))
}
for i := range v {
i := i
f := func(i int) {
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.___Type(ctx, sel, &v[i])
}
if isLen1 {
f(i)
} else {
go f(i)
}

}
wg.Wait()
return ret
}

func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler {
if v == nil {
return graphql.Null
}
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
if !isLen1 {
wg.Add(len(v))
}
for i := range v {
i := i
f := func(i int) {
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.___EnumValue(ctx, sel, &v[i])
}
if isLen1 {
f(i)
} else {
go f(i)
}

}
wg.Wait()
return ret
}

func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐFieldᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler {
if v == nil {
return graphql.Null
}
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
if !isLen1 {
wg.Add(len(v))
func (ec *executionContext) marshalArray(ctx context.Context, sel ast.SelectionSet, v interface{}) graphql.Marshaler {
if reflect.TypeOf(v).Kind() != reflect.Slice {
panic("expected slice type")
}
for i := range v {
i := i
f := func(i int) {
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.___Field(ctx, sel, &v[i])
}
if isLen1 {
f(i)
} else {
go f(i)
}

slice := reflect.ValueOf(v)
len := slice.Len()
if len == 0 {
return graphql.Array{}
}
wg.Wait()
return ret
}

func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler {
if v == nil {
return graphql.Null
}
ret := make(graphql.Array, len(v))
ret := make(graphql.Array, len)
var wg sync.WaitGroup
isLen1 := len(v) == 1
isLen1 := len == 1
if !isLen1 {
wg.Add(len(v))
wg.Add(len)
}
for i := range v {
for i := 0; i < len; i++ {
i := i
v := slice.Index(i).Interface()
f := func(i int) {
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.___InputValue(ctx, sel, &v[i])
}
if isLen1 {
f(i)
} else {
go f(i)
}

}
wg.Wait()
return ret
}

func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler {
if v == nil {
return graphql.Null
}
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
if !isLen1 {
wg.Add(len(v))
}
for i := range v {
i := i
f := func(i int) {
if !isLen1 {
defer wg.Done()
switch typ := v.(type) {
case introspection.Type:
ret[i] = ec.___Type(ctx, sel, &typ)
case introspection.Directive:
ret[i] = ec.___Directive(ctx, sel, &typ)
case introspection.InputValue:
ret[i] = ec.___InputValue(ctx, sel, &typ)
case introspection.Field:
ret[i] = ec.___Field(ctx, sel, &typ)
case introspection.EnumValue:
ret[i] = ec.___EnumValue(ctx, sel, &typ)
case string:
ret[i] = graphql.MarshalString(typ)
default:
panic(fmt.Sprintf("unknown type %T", typ))
}
ret[i] = ec.___Type(ctx, sel, &v[i])
}
if isLen1 {
f(i)
Expand All @@ -824,7 +638,7 @@ func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgen
return ret
}

func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler {
func (ec *executionContext) marshalType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler {
if v == nil {
return graphql.Null
}
Expand Down

0 comments on commit 9cfca7e

Please sign in to comment.