diff --git a/codegen/templates/data.go b/codegen/templates/data.go index 2702e85a6a4..9c86ba32539 100644 --- a/codegen/templates/data.go +++ b/codegen/templates/data.go @@ -2,9 +2,10 @@ package templates var data = map[string]string{ "args.gotpl": "\t{{- range $i, $arg := . }}\n\t\tvar arg{{$i}} {{$arg.Signature }}\n\t\tif tmp, ok := field.Args[{{$arg.GQLName|quote}}]; ok {\n\t\t\tvar err error\n\t\t\t{{$arg.Unmarshal (print \"arg\" $i) \"tmp\" }}\n\t\t\tif err != nil {\n\t\t\t\tec.Error(err)\n\t\t\t\t{{- if $arg.Object.Stream }}\n\t\t\t\t\treturn nil\n\t\t\t\t{{- else }}\n\t\t\t\t\treturn graphql.Null\n\t\t\t\t{{- end }}\n\t\t\t}\n\t\t}\n\t{{- end -}}\n", - "file.gotpl": "// This file was generated by github.com/vektah/gqlgen, DO NOT EDIT\n\npackage {{ .PackageName }}\n\nimport (\n{{- range $import := .Imports }}\n\t{{- $import.Write }}\n{{ end }}\n)\n\nfunc MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema {\n\treturn &executableSchema{resolvers}\n}\n\ntype Resolvers interface {\n{{- range $object := .Objects -}}\n\t{{ range $field := $object.Fields -}}\n\t\t{{ $field.ResolverDeclaration }}\n\t{{ end }}\n{{- end }}\n}\n\n{{ range $model := .Models }}\n\t{{ template \"model.gotpl\" $model }}\n{{- end}}\n\ntype executableSchema struct {\n\tresolvers Resolvers\n}\n\nfunc (e *executableSchema) Schema() *schema.Schema {\n\treturn parsedSchema\n}\n\nfunc (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response {\n\t{{- if .QueryRoot }}\n\t\tec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx}\n\n\t\tdata := ec._{{.QueryRoot.GQLType|lcFirst}}(op.Selections)\n\t\tec.wg.Wait()\n\n\t\treturn &graphql.Response{\n\t\t\tData: data,\n\t\t\tErrors: ec.Errors,\n\t\t}\n\t{{- else }}\n\t\treturn &graphql.Response{Errors: []*errors.QueryError{ {Message: \"queries are not supported\"} }}\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response {\n\t{{- if .MutationRoot }}\n\t\tec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx}\n\n\t\tdata := ec._{{.MutationRoot.GQLType|lcFirst}}(op.Selections)\n\t\tec.wg.Wait()\n\n\t\treturn &graphql.Response{\n\t\t\tData: data,\n\t\t\tErrors: ec.Errors,\n\t\t}\n\t{{- else }}\n\t\treturn &graphql.Response{Errors: []*errors.QueryError{ {Message: \"mutations are not supported\"} }}\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) <-chan *graphql.Response {\n\t{{- if .SubscriptionRoot }}\n\t\tevents := make(chan *graphql.Response, 10)\n\n\t\tec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx}\n\n\t\teventData := ec._{{.SubscriptionRoot.GQLType|lcFirst}}(op.Selections)\n\t\tif ec.Errors != nil {\n\t\t\tevents<-&graphql.Response{\n\t\t\t\tData: graphql.Null,\n\t\t\t\tErrors: ec.Errors,\n\t\t\t}\n\t\t\tclose(events)\n\t\t} else {\n\t\t\tgo func() {\n\t\t\t\tfor data := range eventData {\n\t\t\t\t\tec.wg.Wait()\n\t\t\t\t\tevents <- &graphql.Response{\n\t\t\t\t\t\tData: data,\n\t\t\t\t\t\tErrors: ec.Errors,\n\t\t\t\t\t}\n\t\t\t\t\ttime.Sleep(20 * time.Millisecond)\n\t\t\t\t}\n\t\t\t}()\n\t\t}\n\t\treturn events\n\t{{- else }}\n\t\tevents := make(chan *graphql.Response, 1)\n\t\tevents<-&graphql.Response{Errors: []*errors.QueryError{ {Message: \"subscriptions are not supported\"} }}\n\t\treturn events\n\t{{- end }}\n}\n\ntype executionContext struct {\n\terrors.Builder\n\tresolvers Resolvers\n\tvariables map[string]interface{}\n\tdoc *query.Document\n\tctx context.Context\n\twg sync.WaitGroup\n}\n\n{{- range $object := .Objects }}\n\t{{ template \"object.gotpl\" $object }}\n{{- end}}\n\n{{- range $interface := .Interfaces }}\n\t{{ template \"interface.gotpl\" $interface }}\n{{- end }}\n\n{{- range $input := .Inputs }}\n\t{{ template \"input.gotpl\" $input }}\n{{- end }}\n\nvar parsedSchema = schema.MustParse({{.SchemaRaw|quote}})\n\nfunc (ec *executionContext) introspectSchema() *introspection.Schema {\n\treturn introspection.WrapSchema(parsedSchema)\n}\n\nfunc (ec *executionContext) introspectType(name string) *introspection.Type {\n\tt := parsedSchema.Resolve(name)\n\tif t == nil {\n\t\treturn nil\n\t}\n\treturn introspection.WrapType(t)\n}\n", + "field.gotpl": "{{ $field := . }}\n{{ $object := $field.Object }}\n\n{{- if $object.Stream }}\n\tfunc (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(field graphql.CollectedField) func() graphql.Marshaler {\n\t\t{{- template \"args.gotpl\" $field.Args }}\n\t\tresults, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }})\n\t\tif err != nil {\n\t\t\tec.Error(err)\n\t\t\treturn nil\n\t\t}\n\t\treturn func() graphql.Marshaler {\n\t\t\tres, ok := <-results\n\t\t\tif !ok {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tvar out graphql.OrderedMap\n\t\t\tout.Add(field.Alias, func() graphql.Marshaler { {{ $field.WriteJson }} }())\n\t\t\treturn &out\n\t\t}\n\t}\n{{ else }}\n\tfunc (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.FullName}}{{end}}) graphql.Marshaler {\n\t\t{{- template \"args.gotpl\" $field.Args }}\n\n\t\t{{- if $field.IsConcurrent }}\n\t\t\treturn graphql.Defer(func() graphql.Marshaler {\n\t\t{{- end }}\n\n\t\t\t{{- if $field.GoVarName }}\n\t\t\t\tres := obj.{{$field.GoVarName}}\n\t\t\t{{- else if $field.GoMethodName }}\n\t\t\t\t{{- if $field.NoErr }}\n\t\t\t\t\tres := {{$field.GoMethodName}}({{ $field.CallArgs }})\n\t\t\t\t{{- else }}\n\t\t\t\t\tres, err := {{$field.GoMethodName}}({{ $field.CallArgs }})\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tec.Error(err)\n\t\t\t\t\t\treturn graphql.Null\n\t\t\t\t\t}\n\t\t\t\t{{- end }}\n\t\t\t{{- else }}\n\t\t\t\tres, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }})\n\t\t\t\tif err != nil {\n\t\t\t\t\tec.Error(err)\n\t\t\t\t\treturn graphql.Null\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t\t{{ $field.WriteJson }}\n\t\t{{- if $field.IsConcurrent }}\n\t\t\t})\n\t\t{{- end }}\n\t}\n{{ end }}\n", + "file.gotpl": "// This file was generated by github.com/vektah/gqlgen, DO NOT EDIT\n\npackage {{ .PackageName }}\n\nimport (\n{{- range $import := .Imports }}\n\t{{- $import.Write }}\n{{ end }}\n)\n\nfunc MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema {\n\treturn &executableSchema{resolvers}\n}\n\ntype Resolvers interface {\n{{- range $object := .Objects -}}\n\t{{ range $field := $object.Fields -}}\n\t\t{{ $field.ResolverDeclaration }}\n\t{{ end }}\n{{- end }}\n}\n\n{{ range $model := .Models }}\n\t{{ template \"model.gotpl\" $model }}\n{{- end}}\n\ntype executableSchema struct {\n\tresolvers Resolvers\n}\n\nfunc (e *executableSchema) Schema() *schema.Schema {\n\treturn parsedSchema\n}\n\nfunc (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response {\n\t{{- if .QueryRoot }}\n\t\tec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx}\n\n\t\tdata := ec._{{.QueryRoot.GQLType}}(op.Selections)\n\t\tvar buf bytes.Buffer\n\t\tdata.MarshalGQL(&buf)\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf.Bytes(),\n\t\t\tErrors: ec.Errors,\n\t\t}\n\t{{- else }}\n\t\treturn &graphql.Response{Errors: []*errors.QueryError{ {Message: \"queries are not supported\"} }}\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response {\n\t{{- if .MutationRoot }}\n\t\tec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx}\n\n\t\tdata := ec._{{.MutationRoot.GQLType}}(op.Selections)\n\t\tvar buf bytes.Buffer\n\t\tdata.MarshalGQL(&buf)\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf.Bytes(),\n\t\t\tErrors: ec.Errors,\n\t\t}\n\t{{- else }}\n\t\treturn &graphql.Response{Errors: []*errors.QueryError{ {Message: \"mutations are not supported\"} }}\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) func() *graphql.Response {\n\t{{- if .SubscriptionRoot }}\n\t\tec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx}\n\n\t\tnext := ec._{{.SubscriptionRoot.GQLType}}(op.Selections)\n\t\tif ec.Errors != nil {\n\t\t\treturn graphql.OneShot(&graphql.Response{Data: []byte(\"null\"), Errors: ec.Errors})\n\t\t}\n\n\t\tvar buf bytes.Buffer\n\t\treturn func() *graphql.Response {\n\t\t\tbuf.Reset()\n\t\t\tdata := next()\n\t\t\tif data == nil {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tdata.MarshalGQL(&buf)\n\n\t\t\terrs := ec.Errors\n\t\t\tec.Errors = nil\n\t\t\treturn &graphql.Response{\n\t\t\t\tData: buf.Bytes(),\n\t\t\t\tErrors: errs,\n\t\t\t}\n\t\t}\n\t{{- else }}\n\t\treturn graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{ {Message: \"subscriptions are not supported\"} }})\n\t{{- end }}\n}\n\ntype executionContext struct {\n\terrors.Builder\n\tresolvers Resolvers\n\tvariables map[string]interface{}\n\tdoc *query.Document\n\tctx context.Context\n}\n\n{{- range $object := .Objects }}\n\t{{ template \"object.gotpl\" $object }}\n\n\t{{- range $field := $object.Fields }}\n\t\t{{ template \"field.gotpl\" $field }}\n\t{{ end }}\n{{- end}}\n\n{{- range $interface := .Interfaces }}\n\t{{ template \"interface.gotpl\" $interface }}\n{{- end }}\n\n{{- range $input := .Inputs }}\n\t{{ template \"input.gotpl\" $input }}\n{{- end }}\n\nvar parsedSchema = schema.MustParse({{.SchemaRaw|quote}})\n\nfunc (ec *executionContext) introspectSchema() *introspection.Schema {\n\treturn introspection.WrapSchema(parsedSchema)\n}\n\nfunc (ec *executionContext) introspectType(name string) *introspection.Type {\n\tt := parsedSchema.Resolve(name)\n\tif t == nil {\n\t\treturn nil\n\t}\n\treturn introspection.WrapType(t)\n}\n", "input.gotpl": "\t{{- if .IsMarshaled }}\n\tfunc Unmarshal{{ .GQLType }}(v interface{}) ({{.FullName}}, error) {\n\t\tvar it {{.FullName}}\n\n\t\tfor k, v := range v.(map[string]interface{}) {\n\t\t\tswitch k {\n\t\t\t{{- range $field := .Fields }}\n\t\t\tcase {{$field.GQLName|quote}}:\n\t\t\t\tvar err error\n\t\t\t\t{{ $field.Unmarshal (print \"it.\" $field.GoVarName) \"v\" }}\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn it, err\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t\t}\n\t\t}\n\n\t\treturn it, nil\n\t}\n\t{{- end }}\n", - "interface.gotpl": "{{- $interface := . }}\n\nfunc (ec *executionContext) _{{$interface.GQLType|lcFirst}}(sel []query.Selection, it *{{$interface.FullName}}) graphql.Marshaler {\n\tswitch it := (*it).(type) {\n\tcase nil:\n\t\treturn graphql.Null\n\t{{- range $implementor := $interface.Implementors }}\n\tcase {{$implementor.FullName}}:\n\t\treturn ec._{{$implementor.GQLType|lcFirst}}(sel, &it)\n\n\tcase *{{$implementor.FullName}}:\n\t\treturn ec._{{$implementor.GQLType|lcFirst}}(sel, it)\n\n\t{{- end }}\n\tdefault:\n\t\tpanic(fmt.Errorf(\"unexpected type %T\", it))\n\t}\n}\n", + "interface.gotpl": "{{- $interface := . }}\n\nfunc (ec *executionContext) _{{$interface.GQLType}}(sel []query.Selection, obj *{{$interface.FullName}}) graphql.Marshaler {\n\tswitch obj := (*obj).(type) {\n\tcase nil:\n\t\treturn graphql.Null\n\t{{- range $implementor := $interface.Implementors }}\n\tcase {{$implementor.FullName}}:\n\t\treturn ec._{{$implementor.GQLType}}(sel, &obj)\n\n\tcase *{{$implementor.FullName}}:\n\t\treturn ec._{{$implementor.GQLType}}(sel, obj)\n\n\t{{- end }}\n\tdefault:\n\t\tpanic(fmt.Errorf(\"unexpected type %T\", obj))\n\t}\n}\n", "model.gotpl": "\ttype {{.GoType}} struct {\n\t\t{{- range $field := .Fields }}\n\t\t\t{{- if $field.GoVarName }}\n\t\t\t\t{{ $field.GoVarName }} {{$field.Signature}}\n\t\t\t{{- else }}\n\t\t\t\t{{ $field.GoFKName }} {{$field.GoFKType}}\n\t\t\t{{- end }}\n\t\t{{- end }}\n\t}\n", - "object.gotpl": "{{ $object := . }}\n\nvar {{ $object.GQLType|lcFirst}}Implementors = {{$object.Implementors}}\n\n// nolint: gocyclo, errcheck, gas, goconst\n{{- if .Stream }}\nfunc (ec *executionContext) _{{$object.GQLType|lcFirst}}(sel []query.Selection{{if not $object.Root}}, it *{{$object.FullName}}{{end}}) <-chan graphql.Marshaler {\n\tfields := graphql.CollectFields(ec.doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.variables)\n\n\tif len(fields) != 1 {\n\t\tec.Errorf(\"must subscribe to exactly one stream\")\n\t\treturn nil\n\t}\n\n\tvar field = fields[0]\n\tchannel := make(chan graphql.Marshaler, 1)\n\tswitch field.Name {\n\t{{- range $field := $object.Fields }}\n\tcase \"{{$field.GQLName}}\":\n\t\t{{- template \"args.gotpl\" $field.Args }}\n\n\t\t{{- if $field.GoVarName }}\n\t\t\tresults := it.{{$field.GoVarName}}\n\t\t{{- else if $field.GoMethodName }}\n\t\t\t{{- if $field.NoErr }}\n\t\t\t\tresults := {{$field.GoMethodName}}({{ $field.CallArgs }})\n\t\t\t{{- else }}\n\t\t\t\tresults, err := {{$field.GoMethodName}}({{ $field.CallArgs }})\n\t\t\t\tif err != nil {\n\t\t\t\t\tec.Error(err)\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t{{- else }}\n\t\t\tresults, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }})\n\t\t\tif err != nil {\n\t\t\t\tec.Error(err)\n\t\t\t\treturn nil\n\t\t\t}\n\t\t{{- end }}\n\n\t\tgo func() {\n\t\t\tfor res := range results {\n\t\t\t\tvar out graphql.OrderedMap\n\t\t\t\tvar messageRes graphql.Marshaler\n\t\t\t\t{{ $field.WriteJson \"messageRes\" }}\n\t\t\t\tout.Add(field.Alias, messageRes)\n\t\t\t\tchannel <- &out\n\t\t\t}\n\t\t}()\n\n\t{{- end }}\n\tdefault:\n\t\tpanic(\"unknown field \" + strconv.Quote(field.Name))\n\t}\n\n\treturn channel\n}\n{{- else }}\nfunc (ec *executionContext) _{{$object.GQLType|lcFirst}}(sel []query.Selection{{if not $object.Root}}, it *{{$object.FullName}} {{end}}) graphql.Marshaler {\n\tfields := graphql.CollectFields(ec.doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.variables)\n\tout := graphql.NewOrderedMap(len(fields))\n\tfor i, field := range fields {\n\t\tout.Keys[i] = field.Alias\n\t\tout.Values[i] = graphql.Null\n\n\t\tswitch field.Name {\n\t\tcase \"__typename\":\n\t\t\tout.Values[i] = graphql.MarshalString({{$object.GQLType|quote}})\n\t\t{{- range $field := $object.Fields }}\n\t\tcase \"{{$field.GQLName}}\":\n\t\t\t{{- template \"args.gotpl\" $field.Args }}\n\n\t\t\t{{- if $field.IsConcurrent }}\n\t\t\t\tec.wg.Add(1)\n\t\t\t\tgo func(i int, field graphql.CollectedField) {\n\t\t\t\t\tdefer ec.wg.Done()\n\t\t\t{{- end }}\n\n\t\t\t{{- if $field.GoVarName }}\n\t\t\t\tres := it.{{$field.GoVarName}}\n\t\t\t{{- else if $field.GoMethodName }}\n\t\t\t\t{{- if $field.NoErr }}\n\t\t\t\t\tres := {{$field.GoMethodName}}({{ $field.CallArgs }})\n\t\t\t\t{{- else }}\n\t\t\t\t\tres, err := {{$field.GoMethodName}}({{ $field.CallArgs }})\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tec.Error(err)\n\t\t\t\t\t\t{{ if $field.IsConcurrent }}return{{ else }}continue{{end}}\n\t\t\t\t\t}\n\t\t\t\t{{- end }}\n\t\t\t{{- else }}\n\t\t\t\tres, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }})\n\t\t\t\tif err != nil {\n\t\t\t\t\tec.Error(err)\n\t\t\t\t\t{{ if $field.IsConcurrent }}return{{ else }}continue{{end}}\n\t\t\t\t}\n\t\t\t{{- end }}\n\n\t\t\t{{ $field.WriteJson \"out.Values[i]\" }}\n\n\t\t\t{{- if $field.IsConcurrent }}\n\t\t\t\t}(i, field)\n\t\t\t{{- end }}\n\t\t{{- end }}\n\t\tdefault:\n\t\t\tpanic(\"unknown field \" + strconv.Quote(field.Name))\n\t\t}\n\t}\n\n\treturn out\n}\n{{- end }}\n", + "object.gotpl": "{{ $object := . }}\n\nvar {{ $object.GQLType|lcFirst}}Implementors = {{$object.Implementors}}\n\n// nolint: gocyclo, errcheck, gas, goconst\n{{- if .Stream }}\nfunc (ec *executionContext) _{{$object.GQLType}}(sel []query.Selection) func() graphql.Marshaler {\n\tfields := graphql.CollectFields(ec.doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.variables)\n\n\tif len(fields) != 1 {\n\t\tec.Errorf(\"must subscribe to exactly one stream\")\n\t\treturn nil\n\t}\n\n\tswitch fields[0].Name {\n\t{{- range $field := $object.Fields }}\n\tcase \"{{$field.GQLName}}\":\n\t\treturn ec._{{$object.GQLType}}_{{$field.GQLName}}(fields[0])\n\t{{- end }}\n\tdefault:\n\t\tpanic(\"unknown field \" + strconv.Quote(fields[0].Name))\n\t}\n}\n{{- else }}\nfunc (ec *executionContext) _{{$object.GQLType}}(sel []query.Selection{{if not $object.Root}}, obj *{{$object.FullName}} {{end}}) graphql.Marshaler {\n\tfields := graphql.CollectFields(ec.doc, sel, {{$object.GQLType|lcFirst}}Implementors, ec.variables)\n\tout := graphql.NewOrderedMap(len(fields))\n\tfor i, field := range fields {\n\t\tout.Keys[i] = field.Alias\n\n\t\tswitch field.Name {\n\t\tcase \"__typename\":\n\t\t\tout.Values[i] = graphql.MarshalString({{$object.GQLType|quote}})\n\t\t{{- range $field := $object.Fields }}\n\t\tcase \"{{$field.GQLName}}\":\n\t\t\tout.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(field{{if not $object.Root}}, obj{{end}})\n\t\t{{- end }}\n\t\tdefault:\n\t\t\tpanic(\"unknown field \" + strconv.Quote(field.Name))\n\t\t}\n\t}\n\n\treturn out\n}\n{{- end }}\n", } diff --git a/example/chat/generated.go b/example/chat/generated.go index 9394de35045..960419eaa72 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -3,9 +3,9 @@ package chat import ( + "bytes" context "context" strconv "strconv" - sync "sync" time "time" graphql "github.com/vektah/gqlgen/graphql" @@ -44,11 +44,12 @@ func (e *executableSchema) Schema() *schema.Schema { func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response { ec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx} - data := ec._query(op.Selections) - ec.wg.Wait() + data := ec._Query(op.Selections) + var buf bytes.Buffer + data.MarshalGQL(&buf) return &graphql.Response{ - Data: data, + Data: buf.Bytes(), Errors: ec.Errors, } } @@ -56,40 +57,40 @@ func (e *executableSchema) Query(ctx context.Context, doc *query.Document, varia func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response { ec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx} - data := ec._mutation(op.Selections) - ec.wg.Wait() + data := ec._Mutation(op.Selections) + var buf bytes.Buffer + data.MarshalGQL(&buf) return &graphql.Response{ - Data: data, + Data: buf.Bytes(), Errors: ec.Errors, } } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) <-chan *graphql.Response { - events := make(chan *graphql.Response, 10) - +func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) func() *graphql.Response { ec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx} - eventData := ec._subscription(op.Selections) + next := ec._Subscription(op.Selections) if ec.Errors != nil { - events <- &graphql.Response{ - Data: graphql.Null, - Errors: ec.Errors, + return graphql.OneShot(&graphql.Response{Data: []byte("null"), Errors: ec.Errors}) + } + + var buf bytes.Buffer + return func() *graphql.Response { + buf.Reset() + data := next() + if data == nil { + return nil + } + data.MarshalGQL(&buf) + + errs := ec.Errors + ec.Errors = nil + return &graphql.Response{ + Data: buf.Bytes(), + Errors: errs, } - close(events) - } else { - go func() { - for data := range eventData { - ec.wg.Wait() - events <- &graphql.Response{ - Data: data, - Errors: ec.Errors, - } - time.Sleep(20 * time.Millisecond) - } - }() } - return events } type executionContext struct { @@ -98,36 +99,24 @@ type executionContext struct { variables map[string]interface{} doc *query.Document ctx context.Context - wg sync.WaitGroup } var chatroomImplementors = []string{"Chatroom"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _chatroom(sel []query.Selection, it *Chatroom) graphql.Marshaler { +func (ec *executionContext) _Chatroom(sel []query.Selection, obj *Chatroom) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, chatroomImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Chatroom") case "name": - res := it.Name - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Chatroom_name(field, obj) case "messages": - res := it.Messages - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._message(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec._Chatroom_messages(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -136,35 +125,40 @@ func (ec *executionContext) _chatroom(sel []query.Selection, it *Chatroom) graph return out } +func (ec *executionContext) _Chatroom_name(field graphql.CollectedField, obj *Chatroom) graphql.Marshaler { + res := obj.Name + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Chatroom_messages(field graphql.CollectedField, obj *Chatroom) graphql.Marshaler { + res := obj.Messages + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._Message(field.Selections, &res[idx1]) }()) + } + return arr1 +} + var messageImplementors = []string{"Message"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _message(sel []query.Selection, it *Message) graphql.Marshaler { +func (ec *executionContext) _Message(sel []query.Selection, obj *Message) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, messageImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Message") case "id": - res := it.ID - - out.Values[i] = graphql.MarshalID(res) + out.Values[i] = ec._Message_id(field, obj) case "text": - res := it.Text - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Message_text(field, obj) case "createdBy": - res := it.CreatedBy - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Message_createdBy(field, obj) case "createdAt": - res := it.CreatedAt - - out.Values[i] = graphql.MarshalTime(res) + out.Values[i] = ec._Message_createdAt(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -173,57 +167,40 @@ func (ec *executionContext) _message(sel []query.Selection, it *Message) graphql return out } +func (ec *executionContext) _Message_id(field graphql.CollectedField, obj *Message) graphql.Marshaler { + res := obj.ID + return graphql.MarshalID(res) +} + +func (ec *executionContext) _Message_text(field graphql.CollectedField, obj *Message) graphql.Marshaler { + res := obj.Text + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Message_createdBy(field graphql.CollectedField, obj *Message) graphql.Marshaler { + res := obj.CreatedBy + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Message_createdAt(field graphql.CollectedField, obj *Message) graphql.Marshaler { + res := obj.CreatedAt + return graphql.MarshalTime(res) +} + var mutationImplementors = []string{"Mutation"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _mutation(sel []query.Selection) graphql.Marshaler { +func (ec *executionContext) _Mutation(sel []query.Selection) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, mutationImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Mutation") case "post": - var arg0 string - if tmp, ok := field.Args["text"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - var arg1 string - if tmp, ok := field.Args["username"]; ok { - var err error - - arg1, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - var arg2 string - if tmp, ok := field.Args["roomName"]; ok { - var err error - - arg2, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res, err := ec.resolvers.Mutation_post(ec.ctx, arg0, arg1, arg2) - if err != nil { - ec.Error(err) - continue - } - - out.Values[i] = ec._message(field.Selections, &res) + out.Values[i] = ec._Mutation_post(field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -232,71 +209,63 @@ func (ec *executionContext) _mutation(sel []query.Selection) graphql.Marshaler { return out } +func (ec *executionContext) _Mutation_post(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["text"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + var arg1 string + if tmp, ok := field.Args["username"]; ok { + var err error + + arg1, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + var arg2 string + if tmp, ok := field.Args["roomName"]; ok { + var err error + + arg2, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res, err := ec.resolvers.Mutation_post(ec.ctx, arg0, arg1, arg2) + if err != nil { + ec.Error(err) + return graphql.Null + } + return ec._Message(field.Selections, &res) +} + var queryImplementors = []string{"Query"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _query(sel []query.Selection) graphql.Marshaler { +func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, queryImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Query") case "room": - var arg0 string - if tmp, ok := field.Args["name"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_room(ec.ctx, arg0) - if err != nil { - ec.Error(err) - return - } - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec._chatroom(field.Selections, res) - } - }(i, field) + out.Values[i] = ec._Query_room(field) case "__schema": - res := ec.introspectSchema() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Schema(field.Selections, res) - } + out.Values[i] = ec._Query___schema(field) case "__type": - var arg0 string - if tmp, ok := field.Args["name"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := ec.introspectType(arg0) - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec._Query___type(field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -305,10 +274,60 @@ func (ec *executionContext) _query(sel []query.Selection) graphql.Marshaler { return out } +func (ec *executionContext) _Query_room(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["name"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_room(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + if res == nil { + return graphql.Null + } + return ec._Chatroom(field.Selections, res) + }) +} + +func (ec *executionContext) _Query___schema(field graphql.CollectedField) graphql.Marshaler { + res := ec.introspectSchema() + if res == nil { + return graphql.Null + } + return ec.___Schema(field.Selections, res) +} + +func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["name"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := ec.introspectType(arg0) + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + var subscriptionImplementors = []string{"Subscription"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _subscription(sel []query.Selection) <-chan graphql.Marshaler { +func (ec *executionContext) _Subscription(sel []query.Selection) func() graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, subscriptionImplementors, ec.variables) if len(fields) != 1 { @@ -316,92 +335,61 @@ func (ec *executionContext) _subscription(sel []query.Selection) <-chan graphql. return nil } - var field = fields[0] - channel := make(chan graphql.Marshaler, 1) - switch field.Name { + switch fields[0].Name { case "messageAdded": - var arg0 string - if tmp, ok := field.Args["roomName"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return nil - } - } - results, err := ec.resolvers.Subscription_messageAdded(ec.ctx, arg0) + return ec._Subscription_messageAdded(fields[0]) + default: + panic("unknown field " + strconv.Quote(fields[0].Name)) + } +} + +func (ec *executionContext) _Subscription_messageAdded(field graphql.CollectedField) func() graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["roomName"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) if err != nil { ec.Error(err) return nil } - - go func() { - for res := range results { - var out graphql.OrderedMap - var messageRes graphql.Marshaler - messageRes = ec._message(field.Selections, &res) - out.Add(field.Alias, messageRes) - channel <- &out - } - }() - default: - panic("unknown field " + strconv.Quote(field.Name)) } - - return channel + results, err := ec.resolvers.Subscription_messageAdded(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return nil + } + return func() graphql.Marshaler { + res, ok := <-results + if !ok { + return nil + } + var out graphql.OrderedMap + out.Add(field.Alias, func() graphql.Marshaler { return ec._Message(field.Selections, &res) }()) + return &out + } } var __DirectiveImplementors = []string{"__Directive"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(sel []query.Selection, it *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __DirectiveImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Directive_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Directive_description(field, obj) case "locations": - res := it.Locations() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = graphql.MarshalString(res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Directive_locations(field, obj) case "args": - res := it.Args() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Directive_args(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -410,43 +398,62 @@ func (ec *executionContext) ___Directive(sel []query.Selection, it *introspectio return out } +func (ec *executionContext) ___Directive_name(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Directive_description(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Locations() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + var __EnumValueImplementors = []string{"__EnumValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __EnumValueImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___EnumValue_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___EnumValue_description(field, obj) case "isDeprecated": - res := it.IsDeprecated() - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec.___EnumValue_isDeprecated(field, obj) case "deprecationReason": - res := it.DeprecationReason() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___EnumValue_deprecationReason(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -455,66 +462,56 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspectio return out } +func (ec *executionContext) ___EnumValue_name(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___EnumValue_description(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___EnumValue_isDeprecated(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __FieldImplementors = []string{"__Field"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.Field) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __FieldImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Field_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Field_description(field, obj) case "args": - res := it.Args() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Field_args(field, obj) case "type": - res := it.Type() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Field_type(field, obj) case "isDeprecated": - res := it.IsDeprecated() - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec.___Field_isDeprecated(field, obj) case "deprecationReason": - res := it.DeprecationReason() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Field_deprecationReason(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -523,47 +520,74 @@ func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Fi return out } +func (ec *executionContext) ___Field_name(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Field_description(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Field_type(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Field_isDeprecated(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __InputValueImplementors = []string{"__InputValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __InputValueImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___InputValue_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___InputValue_description(field, obj) case "type": - res := it.Type() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___InputValue_type(field, obj) case "defaultValue": - res := it.DefaultValue() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___InputValue_defaultValue(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -572,73 +596,57 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspecti return out } +func (ec *executionContext) ___InputValue_name(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___InputValue_description(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___InputValue_type(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.DefaultValue() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __SchemaImplementors = []string{"__Schema"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __SchemaImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Schema") case "types": - res := it.Types() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Schema_types(field, obj) case "queryType": - res := it.QueryType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_queryType(field, obj) case "mutationType": - res := it.MutationType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_mutationType(field, obj) case "subscriptionType": - res := it.SubscriptionType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_subscriptionType(field, obj) case "directives": - res := it.Directives() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Directive(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Schema_directives(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -647,142 +655,88 @@ func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.S return out } +func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Types() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Schema_queryType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.QueryType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_mutationType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.MutationType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_subscriptionType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.SubscriptionType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Directives() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Directive(field.Selections, res[idx1]) + }()) + } + return arr1 +} + var __TypeImplementors = []string{"__Type"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(sel []query.Selection, it *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Type) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __TypeImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - res := it.Kind() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Type_kind(field, obj) case "name": - res := it.Name() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Type_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Type_description(field, obj) case "fields": - var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { - var err error - - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := it.Fields(arg0) - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Field(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_fields(field, obj) case "interfaces": - res := it.Interfaces() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_interfaces(field, obj) case "possibleTypes": - res := it.PossibleTypes() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_possibleTypes(field, obj) case "enumValues": - var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { - var err error - - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := it.EnumValues(arg0) - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___EnumValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_enumValues(field, obj) case "inputFields": - res := it.InputFields() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_inputFields(field, obj) case "ofType": - res := it.OfType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Type_ofType(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -791,6 +745,125 @@ func (ec *executionContext) ___Type(sel []query.Selection, it *introspection.Typ return out } +func (ec *executionContext) ___Type_kind(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Kind() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Name() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Type_description(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error + + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.Fields(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Field(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Interfaces() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.PossibleTypes() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error + + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.EnumValues(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___EnumValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.InputFields() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_ofType(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.OfType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + var parsedSchema = schema.MustParse("type Chatroom {\n name: String!\n messages: [Message!]!\n}\n\ntype Message {\n id: ID!\n text: String!\n createdBy: String!\n createdAt: Time!\n}\n\ntype Query {\n room(name:String!): Chatroom\n}\n\ntype Mutation {\n post(text: String!, username: String!, roomName: String!): Message!\n}\n\ntype Subscription {\n messageAdded(roomName: String!): Message!\n}\n\nschema {\n query: Query\n mutation: Mutation\n subscription: Subscription\n}\n\nscalar Time\n") func (ec *executionContext) introspectSchema() *introspection.Schema { diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index afa17e8332f..026116ad9bd 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -3,9 +3,9 @@ package dataloader import ( + "bytes" context "context" strconv "strconv" - sync "sync" time "time" graphql "github.com/vektah/gqlgen/graphql" @@ -20,10 +20,10 @@ func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema { } type Resolvers interface { - Customer_address(ctx context.Context, it *Customer) (*Address, error) - Customer_orders(ctx context.Context, it *Customer) ([]Order, error) + Customer_address(ctx context.Context, obj *Customer) (*Address, error) + Customer_orders(ctx context.Context, obj *Customer) ([]Order, error) - Order_items(ctx context.Context, it *Order) ([]Item, error) + Order_items(ctx context.Context, obj *Order) ([]Item, error) Query_customers(ctx context.Context) ([]Customer, error) Query_torture(ctx context.Context, customerIds [][]int) ([][]Customer, error) } @@ -63,11 +63,12 @@ func (e *executableSchema) Schema() *schema.Schema { func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response { ec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx} - data := ec._query(op.Selections) - ec.wg.Wait() + data := ec._Query(op.Selections) + var buf bytes.Buffer + data.MarshalGQL(&buf) return &graphql.Response{ - Data: data, + Data: buf.Bytes(), Errors: ec.Errors, } } @@ -76,10 +77,8 @@ func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, va return &graphql.Response{Errors: []*errors.QueryError{{Message: "mutations are not supported"}}} } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) <-chan *graphql.Response { - events := make(chan *graphql.Response, 1) - events <- &graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}} - return events +func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) func() *graphql.Response { + return graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}}) } type executionContext struct { @@ -88,34 +87,26 @@ type executionContext struct { variables map[string]interface{} doc *query.Document ctx context.Context - wg sync.WaitGroup } var addressImplementors = []string{"Address"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _address(sel []query.Selection, it *Address) graphql.Marshaler { +func (ec *executionContext) _Address(sel []query.Selection, obj *Address) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, addressImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Address") case "id": - res := it.ID - - out.Values[i] = graphql.MarshalInt(res) + out.Values[i] = ec._Address_id(field, obj) case "street": - res := it.Street - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Address_street(field, obj) case "country": - res := it.Country - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Address_country(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -124,61 +115,41 @@ func (ec *executionContext) _address(sel []query.Selection, it *Address) graphql return out } +func (ec *executionContext) _Address_id(field graphql.CollectedField, obj *Address) graphql.Marshaler { + res := obj.ID + return graphql.MarshalInt(res) +} + +func (ec *executionContext) _Address_street(field graphql.CollectedField, obj *Address) graphql.Marshaler { + res := obj.Street + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Address_country(field graphql.CollectedField, obj *Address) graphql.Marshaler { + res := obj.Country + return graphql.MarshalString(res) +} + var customerImplementors = []string{"Customer"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _customer(sel []query.Selection, it *Customer) graphql.Marshaler { +func (ec *executionContext) _Customer(sel []query.Selection, obj *Customer) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, customerImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Customer") case "id": - res := it.ID - - out.Values[i] = graphql.MarshalInt(res) + out.Values[i] = ec._Customer_id(field, obj) case "name": - res := it.Name - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Customer_name(field, obj) case "address": - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Customer_address(ec.ctx, it) - if err != nil { - ec.Error(err) - return - } - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec._address(field.Selections, res) - } - }(i, field) + out.Values[i] = ec._Customer_address(field, obj) case "orders": - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Customer_orders(ec.ctx, it) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._order(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._Customer_orders(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -187,23 +158,59 @@ func (ec *executionContext) _customer(sel []query.Selection, it *Customer) graph return out } +func (ec *executionContext) _Customer_id(field graphql.CollectedField, obj *Customer) graphql.Marshaler { + res := obj.ID + return graphql.MarshalInt(res) +} + +func (ec *executionContext) _Customer_name(field graphql.CollectedField, obj *Customer) graphql.Marshaler { + res := obj.Name + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Customer_address(field graphql.CollectedField, obj *Customer) graphql.Marshaler { + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Customer_address(ec.ctx, obj) + if err != nil { + ec.Error(err) + return graphql.Null + } + if res == nil { + return graphql.Null + } + return ec._Address(field.Selections, res) + }) +} + +func (ec *executionContext) _Customer_orders(field graphql.CollectedField, obj *Customer) graphql.Marshaler { + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Customer_orders(ec.ctx, obj) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._Order(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + var itemImplementors = []string{"Item"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _item(sel []query.Selection, it *Item) graphql.Marshaler { +func (ec *executionContext) _Item(sel []query.Selection, obj *Item) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, itemImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Item") case "name": - res := it.Name - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Item_name(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -212,49 +219,31 @@ func (ec *executionContext) _item(sel []query.Selection, it *Item) graphql.Marsh return out } +func (ec *executionContext) _Item_name(field graphql.CollectedField, obj *Item) graphql.Marshaler { + res := obj.Name + return graphql.MarshalString(res) +} + var orderImplementors = []string{"Order"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _order(sel []query.Selection, it *Order) graphql.Marshaler { +func (ec *executionContext) _Order(sel []query.Selection, obj *Order) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, orderImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Order") case "id": - res := it.ID - - out.Values[i] = graphql.MarshalInt(res) + out.Values[i] = ec._Order_id(field, obj) case "date": - res := it.Date - - out.Values[i] = graphql.MarshalTime(res) + out.Values[i] = ec._Order_date(field, obj) case "amount": - res := it.Amount - - out.Values[i] = graphql.MarshalFloat(res) + out.Values[i] = ec._Order_amount(field, obj) case "items": - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Order_items(ec.ctx, it) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._item(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._Order_items(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -263,106 +252,56 @@ func (ec *executionContext) _order(sel []query.Selection, it *Order) graphql.Mar return out } +func (ec *executionContext) _Order_id(field graphql.CollectedField, obj *Order) graphql.Marshaler { + res := obj.ID + return graphql.MarshalInt(res) +} + +func (ec *executionContext) _Order_date(field graphql.CollectedField, obj *Order) graphql.Marshaler { + res := obj.Date + return graphql.MarshalTime(res) +} + +func (ec *executionContext) _Order_amount(field graphql.CollectedField, obj *Order) graphql.Marshaler { + res := obj.Amount + return graphql.MarshalFloat(res) +} + +func (ec *executionContext) _Order_items(field graphql.CollectedField, obj *Order) graphql.Marshaler { + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Order_items(ec.ctx, obj) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._Item(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + var queryImplementors = []string{"Query"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _query(sel []query.Selection) graphql.Marshaler { +func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, queryImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Query") case "customers": - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_customers(ec.ctx) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._customer(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._Query_customers(field) case "torture": - var arg0 [][]int - if tmp, ok := field.Args["customerIds"]; ok { - var err error - rawIf1 := tmp.([]interface{}) - arg0 = make([][]int, len(rawIf1)) - for idx1 := range rawIf1 { - rawIf2 := rawIf1[idx1].([]interface{}) - arg0[idx1] = make([]int, len(rawIf2)) - for idx2 := range rawIf2 { - - arg0[idx1][idx2], err = graphql.UnmarshalInt(rawIf2[idx2]) - } - } - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_torture(ec.ctx, arg0) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - arr2 := graphql.Array{} - for idx2 := range res[idx1] { - var tmp2 graphql.Marshaler - tmp2 = ec._customer(field.Selections, &res[idx1][idx2]) - arr2 = append(arr2, tmp2) - } - tmp1 = arr2 - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._Query_torture(field) case "__schema": - res := ec.introspectSchema() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Schema(field.Selections, res) - } + out.Values[i] = ec._Query___schema(field) case "__type": - var arg0 string - if tmp, ok := field.Args["name"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := ec.introspectType(arg0) - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec._Query___type(field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -371,56 +310,106 @@ func (ec *executionContext) _query(sel []query.Selection) graphql.Marshaler { return out } +func (ec *executionContext) _Query_customers(field graphql.CollectedField) graphql.Marshaler { + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_customers(ec.ctx) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._Customer(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + +func (ec *executionContext) _Query_torture(field graphql.CollectedField) graphql.Marshaler { + var arg0 [][]int + if tmp, ok := field.Args["customerIds"]; ok { + var err error + rawIf1 := tmp.([]interface{}) + arg0 = make([][]int, len(rawIf1)) + for idx1 := range rawIf1 { + rawIf2 := rawIf1[idx1].([]interface{}) + arg0[idx1] = make([]int, len(rawIf2)) + for idx2 := range rawIf2 { + + arg0[idx1][idx2], err = graphql.UnmarshalInt(rawIf2[idx2]) + } + } + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_torture(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + 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 ec._Customer(field.Selections, &res[idx1][idx2]) }()) + } + return arr2 + }()) + } + return arr1 + }) +} + +func (ec *executionContext) _Query___schema(field graphql.CollectedField) graphql.Marshaler { + res := ec.introspectSchema() + if res == nil { + return graphql.Null + } + return ec.___Schema(field.Selections, res) +} + +func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["name"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := ec.introspectType(arg0) + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + var __DirectiveImplementors = []string{"__Directive"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(sel []query.Selection, it *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __DirectiveImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Directive_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Directive_description(field, obj) case "locations": - res := it.Locations() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = graphql.MarshalString(res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Directive_locations(field, obj) case "args": - res := it.Args() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Directive_args(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -429,43 +418,62 @@ func (ec *executionContext) ___Directive(sel []query.Selection, it *introspectio return out } +func (ec *executionContext) ___Directive_name(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Directive_description(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Locations() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + var __EnumValueImplementors = []string{"__EnumValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __EnumValueImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___EnumValue_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___EnumValue_description(field, obj) case "isDeprecated": - res := it.IsDeprecated() - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec.___EnumValue_isDeprecated(field, obj) case "deprecationReason": - res := it.DeprecationReason() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___EnumValue_deprecationReason(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -474,66 +482,56 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspectio return out } +func (ec *executionContext) ___EnumValue_name(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___EnumValue_description(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___EnumValue_isDeprecated(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __FieldImplementors = []string{"__Field"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.Field) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __FieldImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Field_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Field_description(field, obj) case "args": - res := it.Args() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Field_args(field, obj) case "type": - res := it.Type() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Field_type(field, obj) case "isDeprecated": - res := it.IsDeprecated() - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec.___Field_isDeprecated(field, obj) case "deprecationReason": - res := it.DeprecationReason() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Field_deprecationReason(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -542,47 +540,74 @@ func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Fi return out } +func (ec *executionContext) ___Field_name(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Field_description(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Field_type(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Field_isDeprecated(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __InputValueImplementors = []string{"__InputValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __InputValueImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___InputValue_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___InputValue_description(field, obj) case "type": - res := it.Type() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___InputValue_type(field, obj) case "defaultValue": - res := it.DefaultValue() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___InputValue_defaultValue(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -591,73 +616,57 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspecti return out } +func (ec *executionContext) ___InputValue_name(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___InputValue_description(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___InputValue_type(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.DefaultValue() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __SchemaImplementors = []string{"__Schema"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __SchemaImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Schema") case "types": - res := it.Types() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Schema_types(field, obj) case "queryType": - res := it.QueryType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_queryType(field, obj) case "mutationType": - res := it.MutationType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_mutationType(field, obj) case "subscriptionType": - res := it.SubscriptionType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_subscriptionType(field, obj) case "directives": - res := it.Directives() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Directive(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Schema_directives(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -666,148 +675,213 @@ func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.S return out } +func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Types() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Schema_queryType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.QueryType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_mutationType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.MutationType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_subscriptionType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.SubscriptionType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Directives() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Directive(field.Selections, res[idx1]) + }()) + } + return arr1 +} + var __TypeImplementors = []string{"__Type"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(sel []query.Selection, it *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Type) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __TypeImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - res := it.Kind() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Type_kind(field, obj) case "name": - res := it.Name() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Type_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Type_description(field, obj) case "fields": - var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { - var err error - - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := it.Fields(arg0) + out.Values[i] = ec.___Type_fields(field, obj) + case "interfaces": + out.Values[i] = ec.___Type_interfaces(field, obj) + case "possibleTypes": + out.Values[i] = ec.___Type_possibleTypes(field, obj) + case "enumValues": + out.Values[i] = ec.___Type_enumValues(field, obj) + case "inputFields": + out.Values[i] = ec.___Type_inputFields(field, obj) + case "ofType": + out.Values[i] = ec.___Type_ofType(field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler + return out +} - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Field(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - case "interfaces": - res := it.Interfaces() +func (ec *executionContext) ___Type_kind(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Kind() + return graphql.MarshalString(res) +} - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler +func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Name() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - case "possibleTypes": - res := it.PossibleTypes() +func (ec *executionContext) ___Type_description(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler +func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - case "enumValues": - var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { - var err error - - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.Fields(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null } - res := it.EnumValues(arg0) + return ec.___Field(field.Selections, res[idx1]) + }()) + } + return arr1 +} - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler +func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Interfaces() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___EnumValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) +func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.PossibleTypes() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null } - out.Values[i] = arr1 - case "inputFields": - res := it.InputFields() + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler +func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.EnumValues(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null } - out.Values[i] = arr1 - case "ofType": - res := it.OfType() + return ec.___EnumValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) +func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.InputFields() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null } - default: - panic("unknown field " + strconv.Quote(field.Name)) - } + return ec.___InputValue(field.Selections, res[idx1]) + }()) } + return arr1 +} - return out +func (ec *executionContext) ___Type_ofType(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.OfType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) } var parsedSchema = schema.MustParse("schema {\n query: Query\n}\n\ntype Query {\n customers: [Customer!]\n\n # this method is here to test code generation of nested arrays\n torture(customerIds: [[Int]]): [[Customer!]]\n}\n\ntype Customer {\n id: Int!\n name: String!\n address: Address\n orders: [Order!]\n}\n\ntype Address {\n id: Int!\n street: String!\n country: String!\n}\n\ntype Order {\n id: Int!\n date: Time!\n amount: Float!\n items: [Item!]\n}\n\ntype Item {\n name: String!\n}\nscalar Time\n") diff --git a/example/scalars/generated.go b/example/scalars/generated.go index 5e26a2204b7..96d44cb5edc 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -3,9 +3,9 @@ package scalars import ( + "bytes" context "context" strconv "strconv" - sync "sync" time "time" graphql "github.com/vektah/gqlgen/graphql" @@ -35,11 +35,12 @@ func (e *executableSchema) Schema() *schema.Schema { func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response { ec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx} - data := ec._query(op.Selections) - ec.wg.Wait() + data := ec._Query(op.Selections) + var buf bytes.Buffer + data.MarshalGQL(&buf) return &graphql.Response{ - Data: data, + Data: buf.Bytes(), Errors: ec.Errors, } } @@ -48,10 +49,8 @@ func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, va return &graphql.Response{Errors: []*errors.QueryError{{Message: "mutations are not supported"}}} } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) <-chan *graphql.Response { - events := make(chan *graphql.Response, 1) - events <- &graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}} - return events +func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) func() *graphql.Response { + return graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}}) } type executionContext struct { @@ -60,102 +59,28 @@ type executionContext struct { variables map[string]interface{} doc *query.Document ctx context.Context - wg sync.WaitGroup } var queryImplementors = []string{"Query"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _query(sel []query.Selection) graphql.Marshaler { +func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, queryImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Query") case "user": - var arg0 string - if tmp, ok := field.Args["id"]; ok { - var err error - - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_user(ec.ctx, arg0) - if err != nil { - ec.Error(err) - return - } - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec._user(field.Selections, res) - } - }(i, field) + out.Values[i] = ec._Query_user(field) case "search": - var arg0 SearchArgs - if tmp, ok := field.Args["input"]; ok { - var err error - - arg0, err = UnmarshalSearchArgs(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_search(ec.ctx, arg0) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._user(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._Query_search(field) case "__schema": - res := ec.introspectSchema() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Schema(field.Selections, res) - } + out.Values[i] = ec._Query___schema(field) case "__type": - var arg0 string - if tmp, ok := field.Args["name"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := ec.introspectType(arg0) - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec._Query___type(field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -164,39 +89,103 @@ func (ec *executionContext) _query(sel []query.Selection) graphql.Marshaler { return out } +func (ec *executionContext) _Query_user(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["id"]; ok { + var err error + + arg0, err = graphql.UnmarshalID(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_user(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + if res == nil { + return graphql.Null + } + return ec._User(field.Selections, res) + }) +} + +func (ec *executionContext) _Query_search(field graphql.CollectedField) graphql.Marshaler { + var arg0 SearchArgs + if tmp, ok := field.Args["input"]; ok { + var err error + + arg0, err = UnmarshalSearchArgs(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_search(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._User(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + +func (ec *executionContext) _Query___schema(field graphql.CollectedField) graphql.Marshaler { + res := ec.introspectSchema() + if res == nil { + return graphql.Null + } + return ec.___Schema(field.Selections, res) +} + +func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["name"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := ec.introspectType(arg0) + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + var userImplementors = []string{"User"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _user(sel []query.Selection, it *User) graphql.Marshaler { +func (ec *executionContext) _User(sel []query.Selection, obj *User) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, userImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("User") case "id": - res := it.ID - - out.Values[i] = graphql.MarshalID(res) + out.Values[i] = ec._User_id(field, obj) case "name": - res := it.Name - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._User_name(field, obj) case "created": - res := it.Created - - out.Values[i] = MarshalTimestamp(res) + out.Values[i] = ec._User_created(field, obj) case "location": - res := it.Location - - out.Values[i] = res + out.Values[i] = ec._User_location(field, obj) case "isBanned": - res := it.IsBanned - - out.Values[i] = graphql.MarshalBoolean(bool(res)) + out.Values[i] = ec._User_isBanned(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -205,56 +194,51 @@ func (ec *executionContext) _user(sel []query.Selection, it *User) graphql.Marsh return out } +func (ec *executionContext) _User_id(field graphql.CollectedField, obj *User) graphql.Marshaler { + res := obj.ID + return graphql.MarshalID(res) +} + +func (ec *executionContext) _User_name(field graphql.CollectedField, obj *User) graphql.Marshaler { + res := obj.Name + return graphql.MarshalString(res) +} + +func (ec *executionContext) _User_created(field graphql.CollectedField, obj *User) graphql.Marshaler { + res := obj.Created + return MarshalTimestamp(res) +} + +func (ec *executionContext) _User_location(field graphql.CollectedField, obj *User) graphql.Marshaler { + res := obj.Location + return res +} + +func (ec *executionContext) _User_isBanned(field graphql.CollectedField, obj *User) graphql.Marshaler { + res := obj.IsBanned + return graphql.MarshalBoolean(bool(res)) +} + var __DirectiveImplementors = []string{"__Directive"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(sel []query.Selection, it *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __DirectiveImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Directive_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Directive_description(field, obj) case "locations": - res := it.Locations() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = graphql.MarshalString(res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Directive_locations(field, obj) case "args": - res := it.Args() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Directive_args(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -263,43 +247,62 @@ func (ec *executionContext) ___Directive(sel []query.Selection, it *introspectio return out } +func (ec *executionContext) ___Directive_name(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Directive_description(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Locations() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + var __EnumValueImplementors = []string{"__EnumValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __EnumValueImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___EnumValue_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___EnumValue_description(field, obj) case "isDeprecated": - res := it.IsDeprecated() - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec.___EnumValue_isDeprecated(field, obj) case "deprecationReason": - res := it.DeprecationReason() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___EnumValue_deprecationReason(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -308,66 +311,56 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspectio return out } +func (ec *executionContext) ___EnumValue_name(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___EnumValue_description(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___EnumValue_isDeprecated(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __FieldImplementors = []string{"__Field"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.Field) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __FieldImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Field_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Field_description(field, obj) case "args": - res := it.Args() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Field_args(field, obj) case "type": - res := it.Type() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Field_type(field, obj) case "isDeprecated": - res := it.IsDeprecated() - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec.___Field_isDeprecated(field, obj) case "deprecationReason": - res := it.DeprecationReason() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Field_deprecationReason(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -376,47 +369,74 @@ func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Fi return out } +func (ec *executionContext) ___Field_name(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Field_description(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Field_type(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Field_isDeprecated(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __InputValueImplementors = []string{"__InputValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __InputValueImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___InputValue_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___InputValue_description(field, obj) case "type": - res := it.Type() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___InputValue_type(field, obj) case "defaultValue": - res := it.DefaultValue() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___InputValue_defaultValue(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -425,73 +445,57 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspecti return out } +func (ec *executionContext) ___InputValue_name(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___InputValue_description(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___InputValue_type(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.DefaultValue() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __SchemaImplementors = []string{"__Schema"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __SchemaImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Schema") case "types": - res := it.Types() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Schema_types(field, obj) case "queryType": - res := it.QueryType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_queryType(field, obj) case "mutationType": - res := it.MutationType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_mutationType(field, obj) case "subscriptionType": - res := it.SubscriptionType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_subscriptionType(field, obj) case "directives": - res := it.Directives() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Directive(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Schema_directives(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -500,142 +504,88 @@ func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.S return out } +func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Types() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Schema_queryType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.QueryType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_mutationType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.MutationType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_subscriptionType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.SubscriptionType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Directives() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Directive(field.Selections, res[idx1]) + }()) + } + return arr1 +} + var __TypeImplementors = []string{"__Type"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(sel []query.Selection, it *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Type) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __TypeImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - res := it.Kind() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Type_kind(field, obj) case "name": - res := it.Name() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Type_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Type_description(field, obj) case "fields": - var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { - var err error - - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := it.Fields(arg0) - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Field(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_fields(field, obj) case "interfaces": - res := it.Interfaces() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_interfaces(field, obj) case "possibleTypes": - res := it.PossibleTypes() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_possibleTypes(field, obj) case "enumValues": - var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { - var err error - - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := it.EnumValues(arg0) - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___EnumValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_enumValues(field, obj) case "inputFields": - res := it.InputFields() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_inputFields(field, obj) case "ofType": - res := it.OfType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Type_ofType(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -644,6 +594,125 @@ func (ec *executionContext) ___Type(sel []query.Selection, it *introspection.Typ return out } +func (ec *executionContext) ___Type_kind(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Kind() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Name() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Type_description(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error + + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.Fields(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Field(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Interfaces() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.PossibleTypes() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error + + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.EnumValues(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___EnumValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.InputFields() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_ofType(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.OfType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + func UnmarshalSearchArgs(v interface{}) (SearchArgs, error) { var it SearchArgs diff --git a/example/starwars/generated.go b/example/starwars/generated.go index 5f7602c2515..586d8e0a353 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated.go @@ -3,10 +3,10 @@ package starwars import ( + "bytes" context "context" fmt "fmt" strconv "strconv" - sync "sync" time "time" graphql "github.com/vektah/gqlgen/graphql" @@ -21,16 +21,16 @@ func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema { } type Resolvers interface { - Droid_friends(ctx context.Context, it *Droid) ([]Character, error) - Droid_friendsConnection(ctx context.Context, it *Droid, first *int, after *string) (FriendsConnection, error) + Droid_friends(ctx context.Context, obj *Droid) ([]Character, error) + Droid_friendsConnection(ctx context.Context, obj *Droid, first *int, after *string) (FriendsConnection, error) - FriendsConnection_edges(ctx context.Context, it *FriendsConnection) ([]FriendsEdge, error) - FriendsConnection_friends(ctx context.Context, it *FriendsConnection) ([]Character, error) + FriendsConnection_edges(ctx context.Context, obj *FriendsConnection) ([]FriendsEdge, error) + FriendsConnection_friends(ctx context.Context, obj *FriendsConnection) ([]Character, error) - Human_friends(ctx context.Context, it *Human) ([]Character, error) - Human_friendsConnection(ctx context.Context, it *Human, first *int, after *string) (FriendsConnection, error) + Human_friends(ctx context.Context, obj *Human) ([]Character, error) + Human_friendsConnection(ctx context.Context, obj *Human, first *int, after *string) (FriendsConnection, error) - Human_starships(ctx context.Context, it *Human) ([]Starship, error) + Human_starships(ctx context.Context, obj *Human) ([]Starship, error) Mutation_createReview(ctx context.Context, episode string, review Review) (*Review, error) Query_hero(ctx context.Context, episode *string) (Character, error) @@ -53,11 +53,12 @@ func (e *executableSchema) Schema() *schema.Schema { func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response { ec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx} - data := ec._query(op.Selections) - ec.wg.Wait() + data := ec._Query(op.Selections) + var buf bytes.Buffer + data.MarshalGQL(&buf) return &graphql.Response{ - Data: data, + Data: buf.Bytes(), Errors: ec.Errors, } } @@ -65,19 +66,18 @@ func (e *executableSchema) Query(ctx context.Context, doc *query.Document, varia func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response { ec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx} - data := ec._mutation(op.Selections) - ec.wg.Wait() + data := ec._Mutation(op.Selections) + var buf bytes.Buffer + data.MarshalGQL(&buf) return &graphql.Response{ - Data: data, + Data: buf.Bytes(), Errors: ec.Errors, } } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) <-chan *graphql.Response { - events := make(chan *graphql.Response, 1) - events <- &graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}} - return events +func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) func() *graphql.Response { + return graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}}) } type executionContext struct { @@ -86,98 +86,32 @@ type executionContext struct { variables map[string]interface{} doc *query.Document ctx context.Context - wg sync.WaitGroup } var droidImplementors = []string{"Droid", "Character"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _droid(sel []query.Selection, it *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid(sel []query.Selection, obj *Droid) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, droidImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Droid") case "id": - res := it.ID - - out.Values[i] = graphql.MarshalID(res) + out.Values[i] = ec._Droid_id(field, obj) case "name": - res := it.Name - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Droid_name(field, obj) case "friends": - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Droid_friends(ec.ctx, it) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._character(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._Droid_friends(field, obj) case "friendsConnection": - var arg0 *int - if tmp, ok := field.Args["first"]; ok { - var err error - var ptr1 int - - ptr1, err = graphql.UnmarshalInt(tmp) - arg0 = &ptr1 - if err != nil { - ec.Error(err) - return graphql.Null - } - } - var arg1 *string - if tmp, ok := field.Args["after"]; ok { - var err error - var ptr1 string - - ptr1, err = graphql.UnmarshalID(tmp) - arg1 = &ptr1 - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Droid_friendsConnection(ec.ctx, it, arg0, arg1) - if err != nil { - ec.Error(err) - return - } - - out.Values[i] = ec._friendsConnection(field.Selections, &res) - }(i, field) + out.Values[i] = ec._Droid_friendsConnection(field, obj) case "appearsIn": - res := it.AppearsIn - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = graphql.MarshalString(res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec._Droid_appearsIn(field, obj) case "primaryFunction": - res := it.PrimaryFunction - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Droid_primaryFunction(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -186,63 +120,100 @@ func (ec *executionContext) _droid(sel []query.Selection, it *Droid) graphql.Mar return out } +func (ec *executionContext) _Droid_id(field graphql.CollectedField, obj *Droid) graphql.Marshaler { + res := obj.ID + return graphql.MarshalID(res) +} + +func (ec *executionContext) _Droid_name(field graphql.CollectedField, obj *Droid) graphql.Marshaler { + res := obj.Name + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Droid_friends(field graphql.CollectedField, obj *Droid) graphql.Marshaler { + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Droid_friends(ec.ctx, obj) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + +func (ec *executionContext) _Droid_friendsConnection(field graphql.CollectedField, obj *Droid) graphql.Marshaler { + var arg0 *int + if tmp, ok := field.Args["first"]; ok { + var err error + var ptr1 int + + ptr1, err = graphql.UnmarshalInt(tmp) + arg0 = &ptr1 + if err != nil { + ec.Error(err) + return graphql.Null + } + } + var arg1 *string + if tmp, ok := field.Args["after"]; ok { + var err error + var ptr1 string + + ptr1, err = graphql.UnmarshalID(tmp) + arg1 = &ptr1 + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Droid_friendsConnection(ec.ctx, obj, arg0, arg1) + if err != nil { + ec.Error(err) + return graphql.Null + } + return ec._FriendsConnection(field.Selections, &res) + }) +} + +func (ec *executionContext) _Droid_appearsIn(field graphql.CollectedField, obj *Droid) graphql.Marshaler { + res := obj.AppearsIn + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +func (ec *executionContext) _Droid_primaryFunction(field graphql.CollectedField, obj *Droid) graphql.Marshaler { + res := obj.PrimaryFunction + return graphql.MarshalString(res) +} + var friendsConnectionImplementors = []string{"FriendsConnection"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _friendsConnection(sel []query.Selection, it *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _FriendsConnection(sel []query.Selection, obj *FriendsConnection) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, friendsConnectionImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("FriendsConnection") case "totalCount": - res := it.TotalCount() - - out.Values[i] = graphql.MarshalInt(res) + out.Values[i] = ec._FriendsConnection_totalCount(field, obj) case "edges": - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.FriendsConnection_edges(ec.ctx, it) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._friendsEdge(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._FriendsConnection_edges(field, obj) case "friends": - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.FriendsConnection_friends(ec.ctx, it) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._character(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._FriendsConnection_friends(field, obj) case "pageInfo": - res := it.PageInfo() - - out.Values[i] = ec._pageInfo(field.Selections, &res) + out.Values[i] = ec._FriendsConnection_pageInfo(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -251,27 +222,62 @@ func (ec *executionContext) _friendsConnection(sel []query.Selection, it *Friend return out } +func (ec *executionContext) _FriendsConnection_totalCount(field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { + res := obj.TotalCount() + return graphql.MarshalInt(res) +} + +func (ec *executionContext) _FriendsConnection_edges(field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.FriendsConnection_edges(ec.ctx, obj) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._FriendsEdge(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + +func (ec *executionContext) _FriendsConnection_friends(field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.FriendsConnection_friends(ec.ctx, obj) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + +func (ec *executionContext) _FriendsConnection_pageInfo(field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { + res := obj.PageInfo() + return ec._PageInfo(field.Selections, &res) +} + var friendsEdgeImplementors = []string{"FriendsEdge"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _friendsEdge(sel []query.Selection, it *FriendsEdge) graphql.Marshaler { +func (ec *executionContext) _FriendsEdge(sel []query.Selection, obj *FriendsEdge) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, friendsEdgeImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("FriendsEdge") case "cursor": - res := it.Cursor - - out.Values[i] = graphql.MarshalID(res) + out.Values[i] = ec._FriendsEdge_cursor(field, obj) case "node": - res := it.Node - - out.Values[i] = ec._character(field.Selections, &res) + out.Values[i] = ec._FriendsEdge_node(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -280,127 +286,44 @@ func (ec *executionContext) _friendsEdge(sel []query.Selection, it *FriendsEdge) return out } +func (ec *executionContext) _FriendsEdge_cursor(field graphql.CollectedField, obj *FriendsEdge) graphql.Marshaler { + res := obj.Cursor + return graphql.MarshalID(res) +} + +func (ec *executionContext) _FriendsEdge_node(field graphql.CollectedField, obj *FriendsEdge) graphql.Marshaler { + res := obj.Node + return ec._Character(field.Selections, &res) +} + var humanImplementors = []string{"Human", "Character"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _human(sel []query.Selection, it *Human) graphql.Marshaler { +func (ec *executionContext) _Human(sel []query.Selection, obj *Human) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, humanImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Human") case "id": - res := it.ID - - out.Values[i] = graphql.MarshalID(res) + out.Values[i] = ec._Human_id(field, obj) case "name": - res := it.Name - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Human_name(field, obj) case "height": - var arg0 string - if tmp, ok := field.Args["unit"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := it.Height(arg0) - - out.Values[i] = graphql.MarshalFloat(res) + out.Values[i] = ec._Human_height(field, obj) case "mass": - res := it.Mass - - out.Values[i] = graphql.MarshalFloat(res) + out.Values[i] = ec._Human_mass(field, obj) case "friends": - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Human_friends(ec.ctx, it) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._character(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._Human_friends(field, obj) case "friendsConnection": - var arg0 *int - if tmp, ok := field.Args["first"]; ok { - var err error - var ptr1 int - - ptr1, err = graphql.UnmarshalInt(tmp) - arg0 = &ptr1 - if err != nil { - ec.Error(err) - return graphql.Null - } - } - var arg1 *string - if tmp, ok := field.Args["after"]; ok { - var err error - var ptr1 string - - ptr1, err = graphql.UnmarshalID(tmp) - arg1 = &ptr1 - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Human_friendsConnection(ec.ctx, it, arg0, arg1) - if err != nil { - ec.Error(err) - return - } - - out.Values[i] = ec._friendsConnection(field.Selections, &res) - }(i, field) + out.Values[i] = ec._Human_friendsConnection(field, obj) case "appearsIn": - res := it.AppearsIn - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = graphql.MarshalString(res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec._Human_appearsIn(field, obj) case "starships": - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Human_starships(ec.ctx, it) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._starship(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._Human_starships(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -409,51 +332,124 @@ func (ec *executionContext) _human(sel []query.Selection, it *Human) graphql.Mar return out } +func (ec *executionContext) _Human_id(field graphql.CollectedField, obj *Human) graphql.Marshaler { + res := obj.ID + return graphql.MarshalID(res) +} + +func (ec *executionContext) _Human_name(field graphql.CollectedField, obj *Human) graphql.Marshaler { + res := obj.Name + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Human_height(field graphql.CollectedField, obj *Human) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["unit"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.Height(arg0) + return graphql.MarshalFloat(res) +} + +func (ec *executionContext) _Human_mass(field graphql.CollectedField, obj *Human) graphql.Marshaler { + res := obj.Mass + return graphql.MarshalFloat(res) +} + +func (ec *executionContext) _Human_friends(field graphql.CollectedField, obj *Human) graphql.Marshaler { + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Human_friends(ec.ctx, obj) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._Character(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + +func (ec *executionContext) _Human_friendsConnection(field graphql.CollectedField, obj *Human) graphql.Marshaler { + var arg0 *int + if tmp, ok := field.Args["first"]; ok { + var err error + var ptr1 int + + ptr1, err = graphql.UnmarshalInt(tmp) + arg0 = &ptr1 + if err != nil { + ec.Error(err) + return graphql.Null + } + } + var arg1 *string + if tmp, ok := field.Args["after"]; ok { + var err error + var ptr1 string + + ptr1, err = graphql.UnmarshalID(tmp) + arg1 = &ptr1 + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Human_friendsConnection(ec.ctx, obj, arg0, arg1) + if err != nil { + ec.Error(err) + return graphql.Null + } + return ec._FriendsConnection(field.Selections, &res) + }) +} + +func (ec *executionContext) _Human_appearsIn(field graphql.CollectedField, obj *Human) graphql.Marshaler { + res := obj.AppearsIn + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +func (ec *executionContext) _Human_starships(field graphql.CollectedField, obj *Human) graphql.Marshaler { + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Human_starships(ec.ctx, obj) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._Starship(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + var mutationImplementors = []string{"Mutation"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _mutation(sel []query.Selection) graphql.Marshaler { +func (ec *executionContext) _Mutation(sel []query.Selection) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, mutationImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Mutation") case "createReview": - var arg0 string - if tmp, ok := field.Args["episode"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - var arg1 Review - if tmp, ok := field.Args["review"]; ok { - var err error - - arg1, err = UnmarshalReviewInput(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res, err := ec.resolvers.Mutation_createReview(ec.ctx, arg0, arg1) - if err != nil { - ec.Error(err) - continue - } - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec._review(field.Selections, res) - } + out.Values[i] = ec._Mutation_createReview(field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -462,31 +458,56 @@ func (ec *executionContext) _mutation(sel []query.Selection) graphql.Marshaler { return out } +func (ec *executionContext) _Mutation_createReview(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["episode"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + var arg1 Review + if tmp, ok := field.Args["review"]; ok { + var err error + + arg1, err = UnmarshalReviewInput(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res, err := ec.resolvers.Mutation_createReview(ec.ctx, arg0, arg1) + if err != nil { + ec.Error(err) + return graphql.Null + } + if res == nil { + return graphql.Null + } + return ec._Review(field.Selections, res) +} + var pageInfoImplementors = []string{"PageInfo"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _pageInfo(sel []query.Selection, it *PageInfo) graphql.Marshaler { +func (ec *executionContext) _PageInfo(sel []query.Selection, obj *PageInfo) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, pageInfoImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("PageInfo") case "startCursor": - res := it.StartCursor - - out.Values[i] = graphql.MarshalID(res) + out.Values[i] = ec._PageInfo_startCursor(field, obj) case "endCursor": - res := it.EndCursor - - out.Values[i] = graphql.MarshalID(res) + out.Values[i] = ec._PageInfo_endCursor(field, obj) case "hasNextPage": - res := it.HasNextPage - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec._PageInfo_hasNextPage(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -495,237 +516,51 @@ func (ec *executionContext) _pageInfo(sel []query.Selection, it *PageInfo) graph return out } +func (ec *executionContext) _PageInfo_startCursor(field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { + res := obj.StartCursor + return graphql.MarshalID(res) +} + +func (ec *executionContext) _PageInfo_endCursor(field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { + res := obj.EndCursor + return graphql.MarshalID(res) +} + +func (ec *executionContext) _PageInfo_hasNextPage(field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { + res := obj.HasNextPage + return graphql.MarshalBoolean(res) +} + var queryImplementors = []string{"Query"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _query(sel []query.Selection) graphql.Marshaler { +func (ec *executionContext) _Query(sel []query.Selection) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, queryImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Query") case "hero": - var arg0 *string - if tmp, ok := field.Args["episode"]; ok { - var err error - var ptr1 string - - ptr1, err = graphql.UnmarshalString(tmp) - arg0 = &ptr1 - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_hero(ec.ctx, arg0) - if err != nil { - ec.Error(err) - return - } - - out.Values[i] = ec._character(field.Selections, &res) - }(i, field) + out.Values[i] = ec._Query_hero(field) case "reviews": - var arg0 string - if tmp, ok := field.Args["episode"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - var arg1 *time.Time - if tmp, ok := field.Args["since"]; ok { - var err error - var ptr1 time.Time - - ptr1, err = graphql.UnmarshalTime(tmp) - arg1 = &ptr1 - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_reviews(ec.ctx, arg0, arg1) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._review(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._Query_reviews(field) case "search": - var arg0 string - if tmp, ok := field.Args["text"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_search(ec.ctx, arg0) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._searchResult(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._Query_search(field) case "character": - var arg0 string - if tmp, ok := field.Args["id"]; ok { - var err error - - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_character(ec.ctx, arg0) - if err != nil { - ec.Error(err) - return - } - - out.Values[i] = ec._character(field.Selections, &res) - }(i, field) + out.Values[i] = ec._Query_character(field) case "droid": - var arg0 string - if tmp, ok := field.Args["id"]; ok { - var err error - - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_droid(ec.ctx, arg0) - if err != nil { - ec.Error(err) - return - } - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec._droid(field.Selections, res) - } - }(i, field) + out.Values[i] = ec._Query_droid(field) case "human": - var arg0 string - if tmp, ok := field.Args["id"]; ok { - var err error - - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_human(ec.ctx, arg0) - if err != nil { - ec.Error(err) - return - } - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec._human(field.Selections, res) - } - }(i, field) + out.Values[i] = ec._Query_human(field) case "starship": - var arg0 string - if tmp, ok := field.Args["id"]; ok { - var err error - - arg0, err = graphql.UnmarshalID(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.Query_starship(ec.ctx, arg0) - if err != nil { - ec.Error(err) - return - } - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec._starship(field.Selections, res) - } - }(i, field) + out.Values[i] = ec._Query_starship(field) case "__schema": - res := ec.introspectSchema() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Schema(field.Selections, res) - } + out.Values[i] = ec._Query___schema(field) case "__type": - var arg0 string - if tmp, ok := field.Args["name"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := ec.introspectType(arg0) - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec._Query___type(field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -734,35 +569,228 @@ func (ec *executionContext) _query(sel []query.Selection) graphql.Marshaler { return out } +func (ec *executionContext) _Query_hero(field graphql.CollectedField) graphql.Marshaler { + var arg0 *string + if tmp, ok := field.Args["episode"]; ok { + var err error + var ptr1 string + + ptr1, err = graphql.UnmarshalString(tmp) + arg0 = &ptr1 + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_hero(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + return ec._Character(field.Selections, &res) + }) +} + +func (ec *executionContext) _Query_reviews(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["episode"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + var arg1 *time.Time + if tmp, ok := field.Args["since"]; ok { + var err error + var ptr1 time.Time + + ptr1, err = graphql.UnmarshalTime(tmp) + arg1 = &ptr1 + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_reviews(ec.ctx, arg0, arg1) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._Review(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + +func (ec *executionContext) _Query_search(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["text"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_search(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._SearchResult(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + +func (ec *executionContext) _Query_character(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["id"]; ok { + var err error + + arg0, err = graphql.UnmarshalID(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_character(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + return ec._Character(field.Selections, &res) + }) +} + +func (ec *executionContext) _Query_droid(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["id"]; ok { + var err error + + arg0, err = graphql.UnmarshalID(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_droid(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + if res == nil { + return graphql.Null + } + return ec._Droid(field.Selections, res) + }) +} + +func (ec *executionContext) _Query_human(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["id"]; ok { + var err error + + arg0, err = graphql.UnmarshalID(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_human(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + if res == nil { + return graphql.Null + } + return ec._Human(field.Selections, res) + }) +} + +func (ec *executionContext) _Query_starship(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["id"]; ok { + var err error + + arg0, err = graphql.UnmarshalID(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.Query_starship(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + if res == nil { + return graphql.Null + } + return ec._Starship(field.Selections, res) + }) +} + +func (ec *executionContext) _Query___schema(field graphql.CollectedField) graphql.Marshaler { + res := ec.introspectSchema() + if res == nil { + return graphql.Null + } + return ec.___Schema(field.Selections, res) +} + +func (ec *executionContext) _Query___type(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["name"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := ec.introspectType(arg0) + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + var reviewImplementors = []string{"Review"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _review(sel []query.Selection, it *Review) graphql.Marshaler { +func (ec *executionContext) _Review(sel []query.Selection, obj *Review) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, reviewImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Review") case "stars": - res := it.Stars - - out.Values[i] = graphql.MarshalInt(res) + out.Values[i] = ec._Review_stars(field, obj) case "commentary": - res := it.Commentary - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec._Review_commentary(field, obj) case "time": - res := it.Time - - out.Values[i] = graphql.MarshalTime(res) + out.Values[i] = ec._Review_time(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -771,58 +799,44 @@ func (ec *executionContext) _review(sel []query.Selection, it *Review) graphql.M return out } +func (ec *executionContext) _Review_stars(field graphql.CollectedField, obj *Review) graphql.Marshaler { + res := obj.Stars + return graphql.MarshalInt(res) +} + +func (ec *executionContext) _Review_commentary(field graphql.CollectedField, obj *Review) graphql.Marshaler { + res := obj.Commentary + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) _Review_time(field graphql.CollectedField, obj *Review) graphql.Marshaler { + res := obj.Time + return graphql.MarshalTime(res) +} + var starshipImplementors = []string{"Starship"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _starship(sel []query.Selection, it *Starship) graphql.Marshaler { +func (ec *executionContext) _Starship(sel []query.Selection, obj *Starship) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, starshipImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Starship") case "id": - res := it.ID - - out.Values[i] = graphql.MarshalID(res) + out.Values[i] = ec._Starship_id(field, obj) case "name": - res := it.Name - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Starship_name(field, obj) case "length": - var arg0 string - if tmp, ok := field.Args["unit"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := it.Length(arg0) - - out.Values[i] = graphql.MarshalFloat(res) + out.Values[i] = ec._Starship_length(field, obj) case "history": - res := it.History - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - arr2 := graphql.Array{} - for idx2 := range res[idx1] { - var tmp2 graphql.Marshaler - tmp2 = graphql.MarshalInt(res[idx1][idx2]) - arr2 = append(arr2, tmp2) - } - tmp1 = arr2 - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec._Starship_history(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -831,56 +845,66 @@ func (ec *executionContext) _starship(sel []query.Selection, it *Starship) graph return out } +func (ec *executionContext) _Starship_id(field graphql.CollectedField, obj *Starship) graphql.Marshaler { + res := obj.ID + return graphql.MarshalID(res) +} + +func (ec *executionContext) _Starship_name(field graphql.CollectedField, obj *Starship) graphql.Marshaler { + res := obj.Name + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Starship_length(field graphql.CollectedField, obj *Starship) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["unit"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.Length(arg0) + return graphql.MarshalFloat(res) +} + +func (ec *executionContext) _Starship_history(field graphql.CollectedField, obj *Starship) graphql.Marshaler { + res := obj.History + arr1 := graphql.Array{} + 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 + }()) + } + return arr1 +} + var __DirectiveImplementors = []string{"__Directive"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(sel []query.Selection, it *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __DirectiveImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Directive_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Directive_description(field, obj) case "locations": - res := it.Locations() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = graphql.MarshalString(res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Directive_locations(field, obj) case "args": - res := it.Args() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Directive_args(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -889,43 +913,62 @@ func (ec *executionContext) ___Directive(sel []query.Selection, it *introspectio return out } +func (ec *executionContext) ___Directive_name(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Directive_description(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Locations() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + var __EnumValueImplementors = []string{"__EnumValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __EnumValueImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___EnumValue_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___EnumValue_description(field, obj) case "isDeprecated": - res := it.IsDeprecated() - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec.___EnumValue_isDeprecated(field, obj) case "deprecationReason": - res := it.DeprecationReason() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___EnumValue_deprecationReason(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -934,66 +977,56 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspectio return out } +func (ec *executionContext) ___EnumValue_name(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___EnumValue_description(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___EnumValue_isDeprecated(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __FieldImplementors = []string{"__Field"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.Field) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __FieldImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Field_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Field_description(field, obj) case "args": - res := it.Args() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Field_args(field, obj) case "type": - res := it.Type() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Field_type(field, obj) case "isDeprecated": - res := it.IsDeprecated() - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec.___Field_isDeprecated(field, obj) case "deprecationReason": - res := it.DeprecationReason() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Field_deprecationReason(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -1002,47 +1035,74 @@ func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Fi return out } +func (ec *executionContext) ___Field_name(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Field_description(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Field_type(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Field_isDeprecated(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __InputValueImplementors = []string{"__InputValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __InputValueImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___InputValue_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___InputValue_description(field, obj) case "type": - res := it.Type() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___InputValue_type(field, obj) case "defaultValue": - res := it.DefaultValue() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___InputValue_defaultValue(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -1051,73 +1111,57 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspecti return out } +func (ec *executionContext) ___InputValue_name(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___InputValue_description(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___InputValue_type(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.DefaultValue() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __SchemaImplementors = []string{"__Schema"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __SchemaImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Schema") case "types": - res := it.Types() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Schema_types(field, obj) case "queryType": - res := it.QueryType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_queryType(field, obj) case "mutationType": - res := it.MutationType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_mutationType(field, obj) case "subscriptionType": - res := it.SubscriptionType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_subscriptionType(field, obj) case "directives": - res := it.Directives() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Directive(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Schema_directives(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -1126,142 +1170,88 @@ func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.S return out } +func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Types() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Schema_queryType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.QueryType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_mutationType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.MutationType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_subscriptionType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.SubscriptionType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Directives() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Directive(field.Selections, res[idx1]) + }()) + } + return arr1 +} + var __TypeImplementors = []string{"__Type"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(sel []query.Selection, it *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Type) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __TypeImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - res := it.Kind() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Type_kind(field, obj) case "name": - res := it.Name() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Type_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Type_description(field, obj) case "fields": - var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { - var err error - - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := it.Fields(arg0) - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Field(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_fields(field, obj) case "interfaces": - res := it.Interfaces() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_interfaces(field, obj) case "possibleTypes": - res := it.PossibleTypes() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_possibleTypes(field, obj) case "enumValues": - var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { - var err error - - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := it.EnumValues(arg0) - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___EnumValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_enumValues(field, obj) case "inputFields": - res := it.InputFields() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_inputFields(field, obj) case "ofType": - res := it.OfType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Type_ofType(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -1270,46 +1260,165 @@ func (ec *executionContext) ___Type(sel []query.Selection, it *introspection.Typ return out } -func (ec *executionContext) _character(sel []query.Selection, it *Character) graphql.Marshaler { - switch it := (*it).(type) { +func (ec *executionContext) ___Type_kind(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Kind() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Name() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Type_description(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error + + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.Fields(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Field(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Interfaces() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.PossibleTypes() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error + + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.EnumValues(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___EnumValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.InputFields() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_ofType(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.OfType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) _Character(sel []query.Selection, obj *Character) graphql.Marshaler { + switch obj := (*obj).(type) { case nil: return graphql.Null case Human: - return ec._human(sel, &it) + return ec._Human(sel, &obj) case *Human: - return ec._human(sel, it) + return ec._Human(sel, obj) case Droid: - return ec._droid(sel, &it) + return ec._Droid(sel, &obj) case *Droid: - return ec._droid(sel, it) + return ec._Droid(sel, obj) default: - panic(fmt.Errorf("unexpected type %T", it)) + panic(fmt.Errorf("unexpected type %T", obj)) } } -func (ec *executionContext) _searchResult(sel []query.Selection, it *SearchResult) graphql.Marshaler { - switch it := (*it).(type) { +func (ec *executionContext) _SearchResult(sel []query.Selection, obj *SearchResult) graphql.Marshaler { + switch obj := (*obj).(type) { case nil: return graphql.Null case Human: - return ec._human(sel, &it) + return ec._Human(sel, &obj) case *Human: - return ec._human(sel, it) + return ec._Human(sel, obj) case Droid: - return ec._droid(sel, &it) + return ec._Droid(sel, &obj) case *Droid: - return ec._droid(sel, it) + return ec._Droid(sel, obj) case Starship: - return ec._starship(sel, &it) + return ec._Starship(sel, &obj) case *Starship: - return ec._starship(sel, it) + return ec._Starship(sel, obj) default: - panic(fmt.Errorf("unexpected type %T", it)) + panic(fmt.Errorf("unexpected type %T", obj)) } } diff --git a/example/todo/generated.go b/example/todo/generated.go index abfa348a650..79fc1579814 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -3,9 +3,9 @@ package todo import ( + "bytes" context "context" strconv "strconv" - sync "sync" graphql "github.com/vektah/gqlgen/graphql" errors "github.com/vektah/gqlgen/neelance/errors" @@ -48,11 +48,12 @@ func (e *executableSchema) Schema() *schema.Schema { func (e *executableSchema) Query(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response { ec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx} - data := ec._myQuery(op.Selections) - ec.wg.Wait() + data := ec._MyQuery(op.Selections) + var buf bytes.Buffer + data.MarshalGQL(&buf) return &graphql.Response{ - Data: data, + Data: buf.Bytes(), Errors: ec.Errors, } } @@ -60,19 +61,18 @@ func (e *executableSchema) Query(ctx context.Context, doc *query.Document, varia func (e *executableSchema) Mutation(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) *graphql.Response { ec := executionContext{resolvers: e.resolvers, variables: variables, doc: doc, ctx: ctx} - data := ec._myMutation(op.Selections) - ec.wg.Wait() + data := ec._MyMutation(op.Selections) + var buf bytes.Buffer + data.MarshalGQL(&buf) return &graphql.Response{ - Data: data, + Data: buf.Bytes(), Errors: ec.Errors, } } -func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) <-chan *graphql.Response { - events := make(chan *graphql.Response, 1) - events <- &graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}} - return events +func (e *executableSchema) Subscription(ctx context.Context, doc *query.Document, variables map[string]interface{}, op *query.Operation) func() *graphql.Response { + return graphql.OneShot(&graphql.Response{Errors: []*errors.QueryError{{Message: "subscriptions are not supported"}}}) } type executionContext struct { @@ -81,72 +81,24 @@ type executionContext struct { variables map[string]interface{} doc *query.Document ctx context.Context - wg sync.WaitGroup } var myMutationImplementors = []string{"MyMutation"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _myMutation(sel []query.Selection) graphql.Marshaler { +func (ec *executionContext) _MyMutation(sel []query.Selection) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, myMutationImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("MyMutation") case "createTodo": - var arg0 TodoInput - if tmp, ok := field.Args["todo"]; ok { - var err error - - arg0, err = UnmarshalTodoInput(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res, err := ec.resolvers.MyMutation_createTodo(ec.ctx, arg0) - if err != nil { - ec.Error(err) - continue - } - - out.Values[i] = ec._todo(field.Selections, &res) + out.Values[i] = ec._MyMutation_createTodo(field) case "updateTodo": - var arg0 int - if tmp, ok := field.Args["id"]; ok { - var err error - - arg0, err = graphql.UnmarshalInt(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - var arg1 map[string]interface{} - if tmp, ok := field.Args["changes"]; ok { - var err error - - arg1, err = graphql.UnmarshalMap(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res, err := ec.resolvers.MyMutation_updateTodo(ec.ctx, arg0, arg1) - if err != nil { - ec.Error(err) - continue - } - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec._todo(field.Selections, res) - } + out.Values[i] = ec._MyMutation_updateTodo(field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -155,105 +107,79 @@ func (ec *executionContext) _myMutation(sel []query.Selection) graphql.Marshaler return out } +func (ec *executionContext) _MyMutation_createTodo(field graphql.CollectedField) graphql.Marshaler { + var arg0 TodoInput + if tmp, ok := field.Args["todo"]; ok { + var err error + + arg0, err = UnmarshalTodoInput(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res, err := ec.resolvers.MyMutation_createTodo(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + return ec._Todo(field.Selections, &res) +} + +func (ec *executionContext) _MyMutation_updateTodo(field graphql.CollectedField) graphql.Marshaler { + var arg0 int + if tmp, ok := field.Args["id"]; ok { + var err error + + arg0, err = graphql.UnmarshalInt(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + var arg1 map[string]interface{} + if tmp, ok := field.Args["changes"]; ok { + var err error + + arg1, err = graphql.UnmarshalMap(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res, err := ec.resolvers.MyMutation_updateTodo(ec.ctx, arg0, arg1) + if err != nil { + ec.Error(err) + return graphql.Null + } + if res == nil { + return graphql.Null + } + return ec._Todo(field.Selections, res) +} + var myQueryImplementors = []string{"MyQuery"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _myQuery(sel []query.Selection) graphql.Marshaler { +func (ec *executionContext) _MyQuery(sel []query.Selection) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, myQueryImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("MyQuery") case "todo": - var arg0 int - if tmp, ok := field.Args["id"]; ok { - var err error - - arg0, err = graphql.UnmarshalInt(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.MyQuery_todo(ec.ctx, arg0) - if err != nil { - ec.Error(err) - return - } - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec._todo(field.Selections, res) - } - }(i, field) + out.Values[i] = ec._MyQuery_todo(field) case "lastTodo": - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.MyQuery_lastTodo(ec.ctx) - if err != nil { - ec.Error(err) - return - } - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec._todo(field.Selections, res) - } - }(i, field) + out.Values[i] = ec._MyQuery_lastTodo(field) case "todos": - ec.wg.Add(1) - go func(i int, field graphql.CollectedField) { - defer ec.wg.Done() - res, err := ec.resolvers.MyQuery_todos(ec.ctx) - if err != nil { - ec.Error(err) - return - } - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = ec._todo(field.Selections, &res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 - }(i, field) + out.Values[i] = ec._MyQuery_todos(field) case "__schema": - res := ec.introspectSchema() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Schema(field.Selections, res) - } + out.Values[i] = ec._MyQuery___schema(field) case "__type": - var arg0 string - if tmp, ok := field.Args["name"]; ok { - var err error - - arg0, err = graphql.UnmarshalString(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := ec.introspectType(arg0) - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec._MyQuery___type(field) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -262,31 +188,103 @@ func (ec *executionContext) _myQuery(sel []query.Selection) graphql.Marshaler { return out } +func (ec *executionContext) _MyQuery_todo(field graphql.CollectedField) graphql.Marshaler { + var arg0 int + if tmp, ok := field.Args["id"]; ok { + var err error + + arg0, err = graphql.UnmarshalInt(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.MyQuery_todo(ec.ctx, arg0) + if err != nil { + ec.Error(err) + return graphql.Null + } + if res == nil { + return graphql.Null + } + return ec._Todo(field.Selections, res) + }) +} + +func (ec *executionContext) _MyQuery_lastTodo(field graphql.CollectedField) graphql.Marshaler { + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.MyQuery_lastTodo(ec.ctx) + if err != nil { + ec.Error(err) + return graphql.Null + } + if res == nil { + return graphql.Null + } + return ec._Todo(field.Selections, res) + }) +} + +func (ec *executionContext) _MyQuery_todos(field graphql.CollectedField) graphql.Marshaler { + return graphql.Defer(func() graphql.Marshaler { + res, err := ec.resolvers.MyQuery_todos(ec.ctx) + if err != nil { + ec.Error(err) + return graphql.Null + } + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return ec._Todo(field.Selections, &res[idx1]) }()) + } + return arr1 + }) +} + +func (ec *executionContext) _MyQuery___schema(field graphql.CollectedField) graphql.Marshaler { + res := ec.introspectSchema() + if res == nil { + return graphql.Null + } + return ec.___Schema(field.Selections, res) +} + +func (ec *executionContext) _MyQuery___type(field graphql.CollectedField) graphql.Marshaler { + var arg0 string + if tmp, ok := field.Args["name"]; ok { + var err error + + arg0, err = graphql.UnmarshalString(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := ec.introspectType(arg0) + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + var todoImplementors = []string{"Todo"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) _todo(sel []query.Selection, it *Todo) graphql.Marshaler { +func (ec *executionContext) _Todo(sel []query.Selection, obj *Todo) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, todoImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Todo") case "id": - res := it.ID - - out.Values[i] = graphql.MarshalInt(res) + out.Values[i] = ec._Todo_id(field, obj) case "text": - res := it.Text - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec._Todo_text(field, obj) case "done": - res := it.Done - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec._Todo_done(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -295,56 +293,41 @@ func (ec *executionContext) _todo(sel []query.Selection, it *Todo) graphql.Marsh return out } +func (ec *executionContext) _Todo_id(field graphql.CollectedField, obj *Todo) graphql.Marshaler { + res := obj.ID + return graphql.MarshalInt(res) +} + +func (ec *executionContext) _Todo_text(field graphql.CollectedField, obj *Todo) graphql.Marshaler { + res := obj.Text + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Todo_done(field graphql.CollectedField, obj *Todo) graphql.Marshaler { + res := obj.Done + return graphql.MarshalBoolean(res) +} + var __DirectiveImplementors = []string{"__Directive"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Directive(sel []query.Selection, it *introspection.Directive) graphql.Marshaler { +func (ec *executionContext) ___Directive(sel []query.Selection, obj *introspection.Directive) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __DirectiveImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Directive_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Directive_description(field, obj) case "locations": - res := it.Locations() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - tmp1 = graphql.MarshalString(res[idx1]) - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Directive_locations(field, obj) case "args": - res := it.Args() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Directive_args(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -353,43 +336,62 @@ func (ec *executionContext) ___Directive(sel []query.Selection, it *introspectio return out } +func (ec *executionContext) ___Directive_name(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Directive_description(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Directive_locations(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Locations() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { return graphql.MarshalString(res[idx1]) }()) + } + return arr1 +} + +func (ec *executionContext) ___Directive_args(field graphql.CollectedField, obj *introspection.Directive) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + var __EnumValueImplementors = []string{"__EnumValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspection.EnumValue) graphql.Marshaler { +func (ec *executionContext) ___EnumValue(sel []query.Selection, obj *introspection.EnumValue) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __EnumValueImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___EnumValue_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___EnumValue_description(field, obj) case "isDeprecated": - res := it.IsDeprecated() - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec.___EnumValue_isDeprecated(field, obj) case "deprecationReason": - res := it.DeprecationReason() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___EnumValue_deprecationReason(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -398,66 +400,56 @@ func (ec *executionContext) ___EnumValue(sel []query.Selection, it *introspectio return out } +func (ec *executionContext) ___EnumValue_name(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___EnumValue_description(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___EnumValue_isDeprecated(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___EnumValue_deprecationReason(field graphql.CollectedField, obj *introspection.EnumValue) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __FieldImplementors = []string{"__Field"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Field) graphql.Marshaler { +func (ec *executionContext) ___Field(sel []query.Selection, obj *introspection.Field) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __FieldImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Field_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Field_description(field, obj) case "args": - res := it.Args() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Field_args(field, obj) case "type": - res := it.Type() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Field_type(field, obj) case "isDeprecated": - res := it.IsDeprecated() - - out.Values[i] = graphql.MarshalBoolean(res) + out.Values[i] = ec.___Field_isDeprecated(field, obj) case "deprecationReason": - res := it.DeprecationReason() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Field_deprecationReason(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -466,47 +458,74 @@ func (ec *executionContext) ___Field(sel []query.Selection, it *introspection.Fi return out } +func (ec *executionContext) ___Field_name(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Field_description(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Field_args(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Args() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Field_type(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Field_isDeprecated(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.IsDeprecated() + return graphql.MarshalBoolean(res) +} + +func (ec *executionContext) ___Field_deprecationReason(field graphql.CollectedField, obj *introspection.Field) graphql.Marshaler { + res := obj.DeprecationReason() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __InputValueImplementors = []string{"__InputValue"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspection.InputValue) graphql.Marshaler { +func (ec *executionContext) ___InputValue(sel []query.Selection, obj *introspection.InputValue) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __InputValueImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - res := it.Name() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___InputValue_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___InputValue_description(field, obj) case "type": - res := it.Type() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___InputValue_type(field, obj) case "defaultValue": - res := it.DefaultValue() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___InputValue_defaultValue(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -515,73 +534,57 @@ func (ec *executionContext) ___InputValue(sel []query.Selection, it *introspecti return out } +func (ec *executionContext) ___InputValue_name(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Name() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___InputValue_description(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___InputValue_type(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.Type() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___InputValue_defaultValue(field graphql.CollectedField, obj *introspection.InputValue) graphql.Marshaler { + res := obj.DefaultValue() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + var __SchemaImplementors = []string{"__Schema"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.Schema) graphql.Marshaler { +func (ec *executionContext) ___Schema(sel []query.Selection, obj *introspection.Schema) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __SchemaImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Schema") case "types": - res := it.Types() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Schema_types(field, obj) case "queryType": - res := it.QueryType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_queryType(field, obj) case "mutationType": - res := it.MutationType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_mutationType(field, obj) case "subscriptionType": - res := it.SubscriptionType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Schema_subscriptionType(field, obj) case "directives": - res := it.Directives() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Directive(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Schema_directives(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -590,142 +593,88 @@ func (ec *executionContext) ___Schema(sel []query.Selection, it *introspection.S return out } +func (ec *executionContext) ___Schema_types(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Types() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Schema_queryType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.QueryType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_mutationType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.MutationType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_subscriptionType(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.SubscriptionType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + +func (ec *executionContext) ___Schema_directives(field graphql.CollectedField, obj *introspection.Schema) graphql.Marshaler { + res := obj.Directives() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Directive(field.Selections, res[idx1]) + }()) + } + return arr1 +} + var __TypeImplementors = []string{"__Type"} // nolint: gocyclo, errcheck, gas, goconst -func (ec *executionContext) ___Type(sel []query.Selection, it *introspection.Type) graphql.Marshaler { +func (ec *executionContext) ___Type(sel []query.Selection, obj *introspection.Type) graphql.Marshaler { fields := graphql.CollectFields(ec.doc, sel, __TypeImplementors, ec.variables) out := graphql.NewOrderedMap(len(fields)) for i, field := range fields { out.Keys[i] = field.Alias - out.Values[i] = graphql.Null switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - res := it.Kind() - - out.Values[i] = graphql.MarshalString(res) + out.Values[i] = ec.___Type_kind(field, obj) case "name": - res := it.Name() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Type_name(field, obj) case "description": - res := it.Description() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = graphql.MarshalString(*res) - } + out.Values[i] = ec.___Type_description(field, obj) case "fields": - var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { - var err error - - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := it.Fields(arg0) - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Field(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_fields(field, obj) case "interfaces": - res := it.Interfaces() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_interfaces(field, obj) case "possibleTypes": - res := it.PossibleTypes() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___Type(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_possibleTypes(field, obj) case "enumValues": - var arg0 bool - if tmp, ok := field.Args["includeDeprecated"]; ok { - var err error - - arg0, err = graphql.UnmarshalBoolean(tmp) - if err != nil { - ec.Error(err) - return graphql.Null - } - } - res := it.EnumValues(arg0) - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___EnumValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_enumValues(field, obj) case "inputFields": - res := it.InputFields() - - arr1 := graphql.Array{} - for idx1 := range res { - var tmp1 graphql.Marshaler - - if res[idx1] == nil { - tmp1 = graphql.Null - } else { - tmp1 = ec.___InputValue(field.Selections, res[idx1]) - } - arr1 = append(arr1, tmp1) - } - out.Values[i] = arr1 + out.Values[i] = ec.___Type_inputFields(field, obj) case "ofType": - res := it.OfType() - - if res == nil { - out.Values[i] = graphql.Null - } else { - out.Values[i] = ec.___Type(field.Selections, res) - } + out.Values[i] = ec.___Type_ofType(field, obj) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -734,6 +683,125 @@ func (ec *executionContext) ___Type(sel []query.Selection, it *introspection.Typ return out } +func (ec *executionContext) ___Type_kind(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Kind() + return graphql.MarshalString(res) +} + +func (ec *executionContext) ___Type_name(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Name() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Type_description(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Description() + if res == nil { + return graphql.Null + } + return graphql.MarshalString(*res) +} + +func (ec *executionContext) ___Type_fields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error + + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.Fields(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Field(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_interfaces(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.Interfaces() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_possibleTypes(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.PossibleTypes() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_enumValues(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + var arg0 bool + if tmp, ok := field.Args["includeDeprecated"]; ok { + var err error + + arg0, err = graphql.UnmarshalBoolean(tmp) + if err != nil { + ec.Error(err) + return graphql.Null + } + } + res := obj.EnumValues(arg0) + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___EnumValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_inputFields(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.InputFields() + arr1 := graphql.Array{} + for idx1 := range res { + arr1 = append(arr1, func() graphql.Marshaler { + if res[idx1] == nil { + return graphql.Null + } + return ec.___InputValue(field.Selections, res[idx1]) + }()) + } + return arr1 +} + +func (ec *executionContext) ___Type_ofType(field graphql.CollectedField, obj *introspection.Type) graphql.Marshaler { + res := obj.OfType() + if res == nil { + return graphql.Null + } + return ec.___Type(field.Selections, res) +} + func UnmarshalTodoInput(v interface{}) (TodoInput, error) { var it TodoInput