diff --git a/client/client.go b/client/client.go index 169a1327ba5..1d482700f03 100644 --- a/client/client.go +++ b/client/client.go @@ -73,7 +73,7 @@ func (p *Client) mkRequest(query string, options ...Option) Request { return r } -func (p *Client) Post(query string, response interface{}, options ...Option) error { +func (p *Client) Post(query string, response interface{}, options ...Option) (resperr error) { r := p.mkRequest(query, options...) requestBody, err := json.Marshal(r) if err != nil { @@ -109,11 +109,13 @@ func (p *Client) Post(query string, response interface{}, options ...Option) err return fmt.Errorf("decode: %s", err.Error()) } + // we want to unpack even if there is an error, so we can see partial responses + unpackErr := unpack(respDataRaw.Data, response) + if respDataRaw.Errors != nil { return RawJsonError{respDataRaw.Errors} } - - return unpack(respDataRaw.Data, response) + return unpackErr } type RawJsonError struct { diff --git a/codegen/object.go b/codegen/object.go index ef44f2f7433..84a989ce4b5 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -7,6 +7,8 @@ import ( "strings" "text/template" "unicode" + + "github.com/vektah/gqlparser/ast" ) type GoFieldType int @@ -183,13 +185,26 @@ func (f *Field) CallArgs() string { // should be in the template, but its recursive and has a bunch of args func (f *Field) WriteJson() string { - return f.doWriteJson("res", f.Type.Modifiers, false, 1) + return f.doWriteJson("res", f.Type.Modifiers, f.ASTType, false, 1) } -func (f *Field) doWriteJson(val string, remainingMods []string, isPtr bool, depth int) string { +func (f *Field) doWriteJson(val string, remainingMods []string, astType *ast.Type, isPtr bool, depth int) string { switch { case len(remainingMods) > 0 && remainingMods[0] == modPtr: - return fmt.Sprintf("if %s == nil { return graphql.Null }\n%s", val, f.doWriteJson(val, remainingMods[1:], true, depth+1)) + return tpl(` + if {{.val}} == nil { + {{- if .nonNull }} + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + {{- end }} + return graphql.Null + } + {{.next }}`, map[string]interface{}{ + "val": val, + "nonNull": astType.NonNull, + "next": f.doWriteJson(val, remainingMods[1:], astType, true, depth+1), + }) case len(remainingMods) > 0 && remainingMods[0] == modList: if isPtr { @@ -211,7 +226,7 @@ func (f *Field) doWriteJson(val string, remainingMods []string, isPtr bool, dept "val": val, "arr": arr, "index": index, - "next": f.doWriteJson(val+"["+index+"]", remainingMods[1:], false, depth+1), + "next": f.doWriteJson(val+"["+index+"]", remainingMods[1:], astType.Elem, false, depth+1), }) case f.IsScalar: diff --git a/codegen/object_build.go b/codegen/object_build.go index aaf61a9ba24..95602a9138d 100644 --- a/codegen/object_build.go +++ b/codegen/object_build.go @@ -108,7 +108,7 @@ func (cfg *Config) buildObject(types NamedTypes, typ *ast.Definition, imports *I for _, field := range typ.Fields { if typ == cfg.schema.Query && field.Name == "__type" { obj.Fields = append(obj.Fields, Field{ - Type: &Type{types["__Schema"], []string{modPtr}, nil}, + Type: &Type{types["__Schema"], []string{modPtr}, ast.NamedType("__Schema", nil), nil}, GQLName: "__schema", NoErr: true, GoFieldType: GoFieldMethod, @@ -120,14 +120,14 @@ func (cfg *Config) buildObject(types NamedTypes, typ *ast.Definition, imports *I } if typ == cfg.schema.Query && field.Name == "__schema" { obj.Fields = append(obj.Fields, Field{ - Type: &Type{types["__Type"], []string{modPtr}, nil}, + Type: &Type{types["__Type"], []string{modPtr}, ast.NamedType("__Schema", nil), nil}, GQLName: "__type", NoErr: true, GoFieldType: GoFieldMethod, GoReceiverName: "ec", GoFieldName: "introspectType", Args: []FieldArgument{ - {GQLName: "name", Type: &Type{types["String"], []string{}, nil}, Object: &Object{}}, + {GQLName: "name", Type: &Type{types["String"], []string{}, ast.NamedType("String", nil), nil}, Object: &Object{}}, }, Object: obj, }) diff --git a/codegen/templates/data.go b/codegen/templates/data.go index eb9f2e1beb1..31291b0235d 100644 --- a/codegen/templates/data.go +++ b/codegen/templates/data.go @@ -2,12 +2,12 @@ package templates var data = map[string]string{ "args.gotpl": "\t{{- if . }}args := map[string]interface{}{} {{end}}\n\t{{- range $i, $arg := . }}\n\t\tvar arg{{$i}} {{$arg.Signature }}\n\t\tif tmp, ok := rawArgs[{{$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(ctx, err)\n\t\t\t\t{{- if $arg.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\targs[{{$arg.GQLName|quote}}] = arg{{$i}}\n\t{{- end -}}\n", - "field.gotpl": "{{ $field := . }}\n{{ $object := $field.Object }}\n\n{{- if $object.Stream }}\n\tfunc (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler {\n\t\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\t{{ template \"args.gotpl\" $field.Args }}\n\t\t{{- end }}\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field})\n\t\tresults, err := ec.resolvers.{{ $field.ShortInvocation }}\n\t\tif err != nil {\n\t\t\tec.Error(ctx, 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}}(ctx context.Context, field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.FullName}}{{end}}) graphql.Marshaler {\n\t\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\t{{ template \"args.gotpl\" $field.Args }}\n\t\t{{- end }}\n\t\trctx := &graphql.ResolverContext{\n\t\t\tObject: {{$object.GQLType|quote}},\n\t\t\tArgs: {{if $field.Args }}args{{else}}nil{{end}},\n\t\t\tField: field,\n\t\t}\n\t\tctx = graphql.WithResolverContext(ctx, rctx)\n\t\tresTmp := ec.FieldMiddleware(ctx, func(ctx context.Context) (interface{}, error) {\n\t\t\t{{- if $field.IsResolver }}\n\t\t\t\treturn ec.resolvers.{{ $field.ShortInvocation }}\n\t\t\t{{- else if $field.IsMethod }}\n\t\t\t\t{{- if $field.NoErr }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }}), nil\n\t\t\t\t{{- else }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }})\n\t\t\t\t{{- end }}\n\t\t\t{{- else if $field.IsVariable }}\n\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}, nil\n\t\t\t{{- end }}\n\t\t})\n\t\tif resTmp == nil {\n\t\t\treturn graphql.Null\n\t\t}\n\t\tres := resTmp.({{$field.Signature}})\n\t\t{{ $field.WriteJson }}\n\t}\n{{ end }}\n", + "field.gotpl": "{{ $field := . }}\n{{ $object := $field.Object }}\n\n{{- if $object.Stream }}\n\tfunc (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(ctx context.Context, field graphql.CollectedField) func() graphql.Marshaler {\n\t\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\t{{ template \"args.gotpl\" $field.Args }}\n\t\t{{- end }}\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{Field: field})\n\t\tresults, err := ec.resolvers.{{ $field.ShortInvocation }}\n\t\tif err != nil {\n\t\t\tec.Error(ctx, 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}}(ctx context.Context, field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.FullName}}{{end}}) graphql.Marshaler {\n\t\t{{- if $field.Args }}\n\t\t\trawArgs := field.ArgumentMap(ec.Variables)\n\t\t\t{{ template \"args.gotpl\" $field.Args }}\n\t\t{{- end }}\n\t\trctx := &graphql.ResolverContext{\n\t\t\tObject: {{$object.GQLType|quote}},\n\t\t\tArgs: {{if $field.Args }}args{{else}}nil{{end}},\n\t\t\tField: field,\n\t\t}\n\t\tctx = graphql.WithResolverContext(ctx, rctx)\n\t\tresTmp := ec.FieldMiddleware(ctx, func(ctx context.Context) (interface{}, error) {\n\t\t\t{{- if $field.IsResolver }}\n\t\t\t\treturn ec.resolvers.{{ $field.ShortInvocation }}\n\t\t\t{{- else if $field.IsMethod }}\n\t\t\t\t{{- if $field.NoErr }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }}), nil\n\t\t\t\t{{- else }}\n\t\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}({{ $field.CallArgs }})\n\t\t\t\t{{- end }}\n\t\t\t{{- else if $field.IsVariable }}\n\t\t\t\treturn {{$field.GoReceiverName}}.{{$field.GoFieldName}}, nil\n\t\t\t{{- end }}\n\t\t})\n\t\tif resTmp == nil {\n\t\t\t{{- if $field.ASTType.NonNull }}\n\t\t\t\tif !ec.HasError(rctx) {\n\t\t\t\t\tec.Errorf(ctx, \"must not be null\")\n\t\t\t\t}\n\t\t\t{{- end }}\n\t\t\treturn graphql.Null\n\t\t}\n\t\tres := resTmp.({{$field.Signature}})\n\t\t{{ $field.WriteJson }}\n\t}\n{{ end }}\n", "generated.gotpl": "// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.\n\npackage {{ .PackageName }}\n\nimport (\n{{- range $import := .Imports }}\n\t{{- $import.Write }}\n{{ end }}\n)\n\n// NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.\nfunc NewExecutableSchema(cfg Config) graphql.ExecutableSchema {\n\treturn &executableSchema{\n\t\tresolvers: cfg.Resolvers,\n\t\tdirectives: cfg.Directives,\n\t}\n}\n\ntype Config struct {\n\tResolvers ResolverRoot\n\tDirectives DirectiveRoot\n}\n\ntype ResolverRoot interface {\n{{- range $object := .Objects -}}\n\t{{ if $object.HasResolvers -}}\n\t\t{{$object.GQLType}}() {{$object.GQLType}}Resolver\n\t{{ end }}\n{{- end }}\n}\n\ntype DirectiveRoot struct {\n{{ range $directive := .Directives }}\n\t{{ $directive.Declaration }}\n{{ end }}\n}\n\n{{- range $object := .Objects -}}\n\t{{ if $object.HasResolvers }}\n\t\ttype {{$object.GQLType}}Resolver interface {\n\t\t{{ range $field := $object.Fields -}}\n\t\t\t{{ $field.ShortResolverDeclaration }}\n\t\t{{ end }}\n\t\t}\n\t{{- end }}\n{{- end }}\n\ntype executableSchema struct {\n\tresolvers ResolverRoot\n\tdirectives DirectiveRoot\n}\n\nfunc (e *executableSchema) Schema() *ast.Schema {\n\treturn parsedSchema\n}\n\nfunc (e *executableSchema) Query(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {\n\t{{- if .QueryRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tbuf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\tdata := ec._{{.QueryRoot.GQLType}}(ctx, op.SelectionSet)\n\t\t\tvar buf bytes.Buffer\n\t\t\tdata.MarshalGQL(&buf)\n\t\t\treturn buf.Bytes()\n\t\t})\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf,\n\t\t\tErrors: ec.Errors,\n\t\t}\n\t{{- else }}\n\t\treturn graphql.ErrorResponse(ctx, \"queries are not supported\")\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {\n\t{{- if .MutationRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tbuf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\tdata := ec._{{.MutationRoot.GQLType}}(ctx, op.SelectionSet)\n\t\t\tvar buf bytes.Buffer\n\t\t\tdata.MarshalGQL(&buf)\n\t\t\treturn buf.Bytes()\n\t\t})\n\n\t\treturn &graphql.Response{\n\t\t\tData: buf,\n\t\t\tErrors: ec.Errors,\n\t\t}\n\t{{- else }}\n\t\treturn graphql.ErrorResponse(ctx, \"mutations are not supported\")\n\t{{- end }}\n}\n\nfunc (e *executableSchema) Subscription(ctx context.Context, op *ast.OperationDefinition) func() *graphql.Response {\n\t{{- if .SubscriptionRoot }}\n\t\tec := executionContext{graphql.GetRequestContext(ctx), e}\n\n\t\tnext := ec._{{.SubscriptionRoot.GQLType}}(ctx, op.SelectionSet)\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 := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {\n\t\t\t\tbuf.Reset()\n\t\t\t\tdata := next()\n\n\t\t\t\tif data == nil {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\tdata.MarshalGQL(&buf)\n\t\t\t\treturn buf.Bytes()\n\t\t\t})\n\n\t\t\treturn &graphql.Response{\n\t\t\t\tData: buf,\n\t\t\t\tErrors: ec.Errors,\n\t\t\t}\n\t\t}\n\t{{- else }}\n\t\treturn graphql.OneShot(graphql.ErrorResponse(ctx, \"subscriptions are not supported\"))\n\t{{- end }}\n}\n\ntype executionContext struct {\n\t*graphql.RequestContext\n\t*executableSchema\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\nfunc (ec *executionContext) FieldMiddleware(ctx context.Context, next graphql.Resolver) (ret interface{}) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\tec.Error(ctx, ec.Recover(ctx, r))\n\t\t\tret = nil\n\t\t}\n\t}()\n\t{{- if .Directives }}\n\trctx := graphql.GetResolverContext(ctx)\n\tfor _, d := range rctx.Field.Definition.Directives {\n\t\tswitch d.Name {\n\t\t{{- range $directive := .Directives }}\n\t\tcase \"{{$directive.Name}}\":\n\t\t\tif ec.directives.{{$directive.Name|ucFirst}} != nil {\n\t\t\t\t{{- if $directive.Args }}\n\t\t\t\t\trawArgs := d.ArgumentMap(ec.Variables)\n\t\t\t\t\t{{ template \"args.gotpl\" $directive.Args }}\n\t\t\t\t{{- end }}\n\t\t\t\tn := next\n\t\t\t\tnext = func(ctx context.Context) (interface{}, error) {\n\t\t\t\t\treturn ec.directives.{{$directive.Name|ucFirst}}({{$directive.CallArgs}})\n\t\t\t\t}\n\t\t\t}\n\t\t{{- end }}\n\t\t}\n\t}\n\t{{- end }}\n\tres, err := ec.ResolverMiddleware(ctx, next)\n\tif err != nil {\n\t\tec.Error(ctx, err)\n\t\treturn nil\n\t}\n\treturn res\n}\n\nfunc (ec *executionContext) introspectSchema() *introspection.Schema {\n\treturn introspection.WrapSchema(parsedSchema)\n}\n\nfunc (ec *executionContext) introspectType(name string) *introspection.Type {\n\treturn introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name])\n}\n\nvar parsedSchema = gqlparser.MustLoadSchema(\n\t&ast.Source{Name: {{.SchemaFilename|quote}}, Input: {{.SchemaRaw|rawQuote}}},\n)\n", "input.gotpl": "\t{{- if .IsMarshaled }}\n\tfunc Unmarshal{{ .GQLType }}(v interface{}) ({{.FullName}}, error) {\n\t\tvar it {{.FullName}}\n\t\tvar asMap = v.(map[string]interface{})\n\t\t{{ range $field := .Fields}}\n\t\t\t{{- if $field.Default}}\n\t\t\t\tif _, present := asMap[{{$field.GQLName|quote}}] ; !present {\n\t\t\t\t\tasMap[{{$field.GQLName|quote}}] = {{ $field.Default | dump }}\n\t\t\t\t}\n\t\t\t{{- end}}\n\t\t{{- end }}\n\n\t\tfor k, v := range asMap {\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.GoFieldName) \"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}}(ctx context.Context, sel ast.SelectionSet, 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\t\t{{- if $implementor.ValueReceiver }}\n\t\t\tcase {{$implementor.FullName}}:\n\t\t\t\treturn ec._{{$implementor.GQLType}}(ctx, sel, &obj)\n\t\t{{- end}}\n\t\tcase *{{$implementor.FullName}}:\n\t\t\treturn ec._{{$implementor.GQLType}}(ctx, sel, obj)\n\t{{- end }}\n\tdefault:\n\t\tpanic(fmt.Errorf(\"unexpected type %T\", obj))\n\t}\n}\n", "models.gotpl": "// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.\n\npackage {{ .PackageName }}\n\nimport (\n{{- range $import := .Imports }}\n\t{{- $import.Write }}\n{{ end }}\n)\n\n{{ range $model := .Models }}\n\t{{- if .IsInterface }}\n\t\ttype {{.GoType}} interface {}\n\t{{- else }}\n\t\ttype {{.GoType}} struct {\n\t\t\t{{- range $field := .Fields }}\n\t\t\t\t{{- if $field.GoFieldName }}\n\t\t\t\t\t{{ $field.GoFieldName }} {{$field.Signature}} `json:\"{{$field.GQLName}}\"`\n\t\t\t\t{{- else }}\n\t\t\t\t\t{{ $field.GoFKName }} {{$field.GoFKType}}\n\t\t\t\t{{- end }}\n\t\t\t{{- end }}\n\t\t}\n\t{{- end }}\n{{- end}}\n\n{{ range $enum := .Enums }}\n\ttype {{.GoType}} string\n\tconst (\n\t{{ range $value := .Values -}}\n\t\t{{with .Description}} {{.|prefixLines \"// \"}} {{end}}\n\t\t{{$enum.GoType}}{{ .Name|toCamel }} {{$enum.GoType}} = {{.Name|quote}}\n\t{{- end }}\n\t)\n\n\tfunc (e {{.GoType}}) IsValid() bool {\n\t\tswitch e {\n\t\tcase {{ range $index, $element := .Values}}{{if $index}},{{end}}{{ $enum.GoType }}{{ $element.Name|toCamel }}{{end}}:\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n\n\tfunc (e {{.GoType}}) String() string {\n\t\treturn string(e)\n\t}\n\n\tfunc (e *{{.GoType}}) UnmarshalGQL(v interface{}) error {\n\t\tstr, ok := v.(string)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"enums must be strings\")\n\t\t}\n\n\t\t*e = {{.GoType}}(str)\n\t\tif !e.IsValid() {\n\t\t\treturn fmt.Errorf(\"%s is not a valid {{.GQLType}}\", str)\n\t\t}\n\t\treturn nil\n\t}\n\n\tfunc (e {{.GoType}}) MarshalGQL(w io.Writer) {\n\t\tfmt.Fprint(w, strconv.Quote(e.String()))\n\t}\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}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler {\n\tfields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors)\n\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\tObject: {{$object.GQLType|quote}},\n\t})\n\tif len(fields) != 1 {\n\t\tec.Errorf(ctx, \"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}}(ctx, 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}}(ctx context.Context, sel ast.SelectionSet{{if not $object.Root}}, obj *{{$object.FullName}} {{end}}) graphql.Marshaler {\n\tfields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors)\n\t{{if $object.Root}}\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\tObject: {{$object.GQLType|quote}},\n\t\t})\n\t{{end}}\n\n\t{{if $object.IsConcurrent}} var wg sync.WaitGroup {{end}}\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\t{{- if $field.IsConcurrent }}\n\t\t\t\twg.Add(1)\n\t\t\t\tgo func(i int, field graphql.CollectedField) {\n\t\t\t{{- end }}\n\t\t\t\tout.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}})\n\t\t\t{{- if $field.IsConcurrent }}\n\t\t\t\t\twg.Done()\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\t{{if $object.IsConcurrent}} wg.Wait() {{end}}\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}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler {\n\tfields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors)\n\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\tObject: {{$object.GQLType|quote}},\n\t})\n\tif len(fields) != 1 {\n\t\tec.Errorf(ctx, \"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}}(ctx, 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}}(ctx context.Context, sel ast.SelectionSet{{if not $object.Root}}, obj *{{$object.FullName}} {{end}}) graphql.Marshaler {\n\tfields := graphql.CollectFields(ctx, sel, {{$object.GQLType|lcFirst}}Implementors)\n\t{{if $object.Root}}\n\t\tctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{\n\t\t\tObject: {{$object.GQLType|quote}},\n\t\t})\n\t{{end}}\n\n\t{{if $object.IsConcurrent}} var wg sync.WaitGroup {{end}}\n\tout := graphql.NewOrderedMap(len(fields))\n\tinvalid := false\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\t{{- if $field.IsConcurrent }}\n\t\t\t\twg.Add(1)\n\t\t\t\tgo func(i int, field graphql.CollectedField) {\n\t\t\t{{- end }}\n\t\t\t\tout.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}})\n\t\t\t\t{{- if $field.ASTType.NonNull }}\n\t\t\t\t\tif out.Values[i] == graphql.Null {\n\t\t\t\t\t\tinvalid = true\n\t\t\t\t\t}\n\t\t\t\t{{- end }}\n\t\t\t{{- if $field.IsConcurrent }}\n\t\t\t\t\twg.Done()\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\t{{if $object.IsConcurrent}} wg.Wait() {{end}}\n\tif invalid { return graphql.Null }\n\treturn out\n}\n{{- end }}\n", "resolver.gotpl": "//go:generate gorunpkg github.com/99designs/gqlgen\n\npackage {{ .PackageName }}\n\nimport (\n{{- range $import := .Imports }}\n\t{{- $import.Write }}\n{{ end }}\n)\n\ntype {{.ResolverType}} struct {}\n\n{{ range $object := .Objects -}}\n\t{{- if $object.HasResolvers -}}\n\t\tfunc (r *{{$.ResolverType}}) {{$object.GQLType}}() {{ $object.ResolverInterface.FullName }} {\n\t\t\treturn &{{lcFirst $object.GQLType}}Resolver{r}\n\t\t}\n\t{{ end -}}\n{{ end }}\n\n{{ range $object := .Objects -}}\n\t{{- if $object.HasResolvers -}}\n\t\ttype {{lcFirst $object.GQLType}}Resolver struct { *Resolver }\n\n\t\t{{ range $field := $object.Fields -}}\n\t\t\t{{- if $field.IsResolver -}}\n\t\t\tfunc (r *{{lcFirst $object.GQLType}}Resolver) {{ $field.ShortResolverDeclaration }} {\n\t\t\t\tpanic(\"not implemented\")\n\t\t\t}\n\t\t\t{{ end -}}\n\t\t{{ end -}}\n\t{{ end -}}\n{{ end }}\n", "server.gotpl": "package main\n\nimport (\n{{- range $import := .Imports }}\n\t{{- $import.Write }}\n{{ end }}\n)\n\nconst defaultPort = \"8080\"\n\nfunc main() {\n\tport := os.Getenv(\"PORT\")\n\tif port == \"\" {\n\t\tport = defaultPort\n\t}\n\n\thttp.Handle(\"/\", handler.Playground(\"GraphQL playground\", \"/query\"))\n\thttp.Handle(\"/query\", handler.GraphQL({{.ExecPackageName}}.NewExecutableSchema({{.ExecPackageName}}.Config{Resolvers: &{{.ResolverPackageName}}.Resolver{}})))\n\n\tlog.Printf(\"connect to http://localhost:%s/ for GraphQL playground\", port)\n\tlog.Fatal(http.ListenAndServe(\":\" + port, nil))\n}\n", } diff --git a/codegen/templates/field.gotpl b/codegen/templates/field.gotpl index d46c87add38..bfc2f1592ff 100644 --- a/codegen/templates/field.gotpl +++ b/codegen/templates/field.gotpl @@ -49,6 +49,11 @@ {{- end }} }) if resTmp == nil { + {{- if $field.ASTType.NonNull }} + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + {{- end }} return graphql.Null } res := resTmp.({{$field.Signature}}) diff --git a/codegen/templates/object.gotpl b/codegen/templates/object.gotpl index 62081b331df..e98cbe1ee55 100644 --- a/codegen/templates/object.gotpl +++ b/codegen/templates/object.gotpl @@ -34,6 +34,7 @@ func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.Se {{if $object.IsConcurrent}} var wg sync.WaitGroup {{end}} out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -47,6 +48,11 @@ func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.Se go func(i int, field graphql.CollectedField) { {{- end }} out.Values[i] = ec._{{$object.GQLType}}_{{$field.GQLName}}(ctx, field{{if not $object.Root}}, obj{{end}}) + {{- if $field.ASTType.NonNull }} + if out.Values[i] == graphql.Null { + invalid = true + } + {{- end }} {{- if $field.IsConcurrent }} wg.Done() }(i, field) @@ -57,6 +63,7 @@ func (ec *executionContext) _{{$object.GQLType}}(ctx context.Context, sel ast.Se } } {{if $object.IsConcurrent}} wg.Wait() {{end}} + if invalid { return graphql.Null } return out } {{- end }} diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 293bba0719e..0ddf302e9be 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -49,6 +49,8 @@ type QueryResolver interface { NestedOutputs(ctx context.Context) ([][]*OuterObject, error) Keywords(ctx context.Context, input *Keywords) (bool, error) Shapes(ctx context.Context) ([]*Shape, error) + ErrorBubble(ctx context.Context) (*Error, error) + Valid(ctx context.Context) (string, error) KeywordArgs(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) } @@ -97,6 +99,7 @@ func (ec *executionContext) _Circle(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, circleImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -112,6 +115,9 @@ func (ec *executionContext) _Circle(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -149,6 +155,132 @@ func (ec *executionContext) _Circle_area(ctx context.Context, field graphql.Coll return graphql.MarshalFloat(res) } +var errorImplementors = []string{"Error"} + +// nolint: gocyclo, errcheck, gas, goconst +func (ec *executionContext) _Error(ctx context.Context, sel ast.SelectionSet, obj *Error) graphql.Marshaler { + fields := graphql.CollectFields(ctx, sel, errorImplementors) + + out := graphql.NewOrderedMap(len(fields)) + invalid := false + for i, field := range fields { + out.Keys[i] = field.Alias + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Error") + case "id": + out.Values[i] = ec._Error_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "errorOnNonRequiredField": + out.Values[i] = ec._Error_errorOnNonRequiredField(ctx, field, obj) + case "errorOnRequiredField": + out.Values[i] = ec._Error_errorOnRequiredField(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + case "nilOnRequiredField": + out.Values[i] = ec._Error_nilOnRequiredField(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + + if invalid { + return graphql.Null + } + return out +} + +func (ec *executionContext) _Error_id(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { + rctx := &graphql.ResolverContext{ + Object: "Error", + Args: nil, + Field: field, + } + ctx = graphql.WithResolverContext(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, func(ctx context.Context) (interface{}, error) { + return obj.ID, nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + return graphql.MarshalID(res) +} + +func (ec *executionContext) _Error_errorOnNonRequiredField(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { + rctx := &graphql.ResolverContext{ + Object: "Error", + Args: nil, + Field: field, + } + ctx = graphql.WithResolverContext(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, func(ctx context.Context) (interface{}, error) { + return obj.ErrorOnNonRequiredField() + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(string) + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Error_errorOnRequiredField(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { + rctx := &graphql.ResolverContext{ + Object: "Error", + Args: nil, + Field: field, + } + ctx = graphql.WithResolverContext(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, func(ctx context.Context) (interface{}, error) { + return obj.ErrorOnRequiredField() + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + return graphql.MarshalString(res) +} + +func (ec *executionContext) _Error_nilOnRequiredField(ctx context.Context, field graphql.CollectedField, obj *Error) graphql.Marshaler { + rctx := &graphql.ResolverContext{ + Object: "Error", + Args: nil, + Field: field, + } + ctx = graphql.WithResolverContext(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, func(ctx context.Context) (interface{}, error) { + return obj.NilOnRequiredField(), nil + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*string) + + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return graphql.MarshalString(*res) +} + var forcedResolverImplementors = []string{"ForcedResolver"} // nolint: gocyclo, errcheck, gas, goconst @@ -157,6 +289,7 @@ func (ec *executionContext) _ForcedResolver(ctx context.Context, sel ast.Selecti var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -174,6 +307,9 @@ func (ec *executionContext) _ForcedResolver(ctx context.Context, sel ast.Selecti } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -191,6 +327,7 @@ func (ec *executionContext) _ForcedResolver_field(ctx context.Context, field gra return graphql.Null } res := resTmp.(*Circle) + if res == nil { return graphql.Null } @@ -204,6 +341,7 @@ func (ec *executionContext) _InnerObject(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, innerObjectImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -212,11 +350,17 @@ func (ec *executionContext) _InnerObject(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("InnerObject") case "id": out.Values[i] = ec._InnerObject_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -231,6 +375,9 @@ func (ec *executionContext) _InnerObject_id(ctx context.Context, field graphql.C return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(int) @@ -244,6 +391,7 @@ func (ec *executionContext) _InvalidIdentifier(ctx context.Context, sel ast.Sele fields := graphql.CollectFields(ctx, sel, invalidIdentifierImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -252,11 +400,17 @@ func (ec *executionContext) _InvalidIdentifier(ctx context.Context, sel ast.Sele out.Values[i] = graphql.MarshalString("InvalidIdentifier") case "id": out.Values[i] = ec._InvalidIdentifier_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -271,6 +425,9 @@ func (ec *executionContext) _InvalidIdentifier_id(ctx context.Context, field gra return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(int) @@ -284,6 +441,7 @@ func (ec *executionContext) _It(ctx context.Context, sel ast.SelectionSet, obj * fields := graphql.CollectFields(ctx, sel, itImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -292,11 +450,17 @@ func (ec *executionContext) _It(ctx context.Context, sel ast.SelectionSet, obj * out.Values[i] = graphql.MarshalString("It") case "id": out.Values[i] = ec._It_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -311,6 +475,9 @@ func (ec *executionContext) _It_id(ctx context.Context, field graphql.CollectedF return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -324,6 +491,7 @@ func (ec *executionContext) _OuterObject(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, outerObjectImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -332,11 +500,17 @@ func (ec *executionContext) _OuterObject(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("OuterObject") case "inner": out.Values[i] = ec._OuterObject_inner(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -351,6 +525,9 @@ func (ec *executionContext) _OuterObject_inner(ctx context.Context, field graphq return obj.Inner, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(InnerObject) @@ -369,6 +546,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -415,6 +593,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Query_keywords(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "shapes": @@ -423,10 +604,28 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr out.Values[i] = ec._Query_shapes(ctx, field) wg.Done() }(i, field) + case "errorBubble": + wg.Add(1) + go func(i int, field graphql.CollectedField) { + out.Values[i] = ec._Query_errorBubble(ctx, field) + wg.Done() + }(i, field) + case "valid": + wg.Add(1) + go func(i int, field graphql.CollectedField) { + out.Values[i] = ec._Query_valid(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } + wg.Done() + }(i, field) case "keywordArgs": wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Query_keywordArgs(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "__type": @@ -438,6 +637,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -455,6 +657,7 @@ func (ec *executionContext) _Query_invalidIdentifier(ctx context.Context, field return graphql.Null } res := resTmp.(*invalid_packagename.InvalidIdentifier) + if res == nil { return graphql.Null } @@ -475,6 +678,7 @@ func (ec *executionContext) _Query_collision(ctx context.Context, field graphql. return graphql.Null } res := resTmp.(*introspection1.It) + if res == nil { return graphql.Null } @@ -512,6 +716,7 @@ func (ec *executionContext) _Query_mapInput(ctx context.Context, field graphql.C return graphql.Null } res := resTmp.(*bool) + if res == nil { return graphql.Null } @@ -549,6 +754,7 @@ func (ec *executionContext) _Query_recursive(ctx context.Context, field graphql. return graphql.Null } res := resTmp.(*bool) + if res == nil { return graphql.Null } @@ -607,6 +813,7 @@ func (ec *executionContext) _Query_nestedInputs(ctx context.Context, field graph return graphql.Null } res := resTmp.(*bool) + if res == nil { return graphql.Null } @@ -639,6 +846,7 @@ func (ec *executionContext) _Query_nestedOutputs(ctx context.Context, field grap rctx := graphql.GetResolverContext(ctx) rctx.PushIndex(idx2) defer rctx.Pop() + if res[idx1][idx2] == nil { return graphql.Null } @@ -679,6 +887,9 @@ func (ec *executionContext) _Query_keywords(ctx context.Context, field graphql.C return ec.resolvers.Query().Keywords(ctx, args["input"].(*Keywords)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -705,6 +916,7 @@ func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.Col rctx := graphql.GetResolverContext(ctx) rctx.PushIndex(idx1) defer rctx.Pop() + if res[idx1] == nil { return graphql.Null } @@ -714,6 +926,47 @@ func (ec *executionContext) _Query_shapes(ctx context.Context, field graphql.Col return arr1 } +func (ec *executionContext) _Query_errorBubble(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rctx := &graphql.ResolverContext{ + Object: "Query", + Args: nil, + Field: field, + } + ctx = graphql.WithResolverContext(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, func(ctx context.Context) (interface{}, error) { + return ec.resolvers.Query().ErrorBubble(ctx) + }) + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*Error) + + if res == nil { + return graphql.Null + } + return ec._Error(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_valid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { + rctx := &graphql.ResolverContext{ + Object: "Query", + Args: nil, + Field: field, + } + ctx = graphql.WithResolverContext(ctx, rctx) + resTmp := ec.FieldMiddleware(ctx, func(ctx context.Context) (interface{}, error) { + return ec.resolvers.Query().Valid(ctx) + }) + if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + return graphql.MarshalString(res) +} + func (ec *executionContext) _Query_keywordArgs(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { rawArgs := field.ArgumentMap(ec.Variables) args := map[string]interface{}{} @@ -977,6 +1230,9 @@ func (ec *executionContext) _Query_keywordArgs(ctx context.Context, field graphq return ec.resolvers.Query().KeywordArgs(ctx, args["break"].(string), args["default"].(string), args["func"].(string), args["interface"].(string), args["select"].(string), args["case"].(string), args["defer"].(string), args["go"].(string), args["map"].(string), args["struct"].(string), args["chan"].(string), args["else"].(string), args["goto"].(string), args["package"].(string), args["switch"].(string), args["const"].(string), args["fallthrough"].(string), args["if"].(string), args["range"].(string), args["type"].(string), args["continue"].(string), args["for"].(string), args["import"].(string), args["return"].(string), args["var"].(string)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -1009,6 +1265,7 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1029,6 +1286,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C return graphql.Null } res := resTmp.(*introspection.Schema) + if res == nil { return graphql.Null } @@ -1042,6 +1300,7 @@ func (ec *executionContext) _Rectangle(ctx context.Context, sel ast.SelectionSet fields := graphql.CollectFields(ctx, sel, rectangleImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1059,6 +1318,9 @@ func (ec *executionContext) _Rectangle(ctx context.Context, sel ast.SelectionSet } } + if invalid { + return graphql.Null + } return out } @@ -1120,6 +1382,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1128,17 +1391,29 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__Directive") case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -1153,6 +1428,9 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1187,6 +1465,9 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr return obj.Locations, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]string) @@ -1213,6 +1494,9 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -1235,6 +1519,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1243,10 +1528,16 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__EnumValue") case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: @@ -1254,6 +1545,9 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } + if invalid { + return graphql.Null + } return out } @@ -1268,6 +1562,9 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1302,6 +1599,9 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -1332,6 +1632,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __FieldImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1340,14 +1641,26 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Field") case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: @@ -1355,6 +1668,9 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } + if invalid { + return graphql.Null + } return out } @@ -1369,6 +1685,9 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1403,6 +1722,9 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -1429,10 +1751,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1449,6 +1778,9 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -1479,6 +1811,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1487,10 +1820,16 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection out.Values[i] = graphql.MarshalString("__InputValue") case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: @@ -1498,6 +1837,9 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } + if invalid { + return graphql.Null + } return out } @@ -1512,6 +1854,9 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1546,10 +1891,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1569,6 +1921,7 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1582,6 +1935,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1590,19 +1944,31 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Schema") case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -1617,6 +1983,9 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C return obj.Types(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Type) @@ -1643,10 +2012,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph return obj.QueryType(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1666,6 +2042,7 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1686,6 +2063,7 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1703,6 +2081,9 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap return obj.Directives(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Directive) @@ -1725,6 +2106,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, __TypeImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1733,6 +2115,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o out.Values[i] = graphql.MarshalString("__Type") case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": @@ -1754,6 +2139,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -1768,6 +2156,9 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll return obj.Kind(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1788,6 +2179,7 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1979,6 +2371,7 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -2271,6 +2664,15 @@ var parsedSchema = gqlparser.MustLoadSchema( nestedOutputs: [[OuterObject]] keywords(input: Keywords): Boolean! shapes: [Shape] + errorBubble: Error + valid: String! +} + +type Error { + id: ID! + errorOnNonRequiredField: String + errorOnRequiredField: String! + nilOnRequiredField: String! } type InvalidIdentifier { diff --git a/codegen/testserver/generated_test.go b/codegen/testserver/generated_test.go index b4bb895b746..bd7b09b6748 100644 --- a/codegen/testserver/generated_test.go +++ b/codegen/testserver/generated_test.go @@ -4,16 +4,18 @@ package testserver import ( + "context" "net/http" - "testing" - + "net/http/httptest" "reflect" + "testing" + "github.com/99designs/gqlgen/client" "github.com/99designs/gqlgen/handler" "github.com/stretchr/testify/require" ) -func TestCompiles(t *testing.T) { +func TestGeneratedResolversAreValid(t *testing.T) { http.Handle("/query", handler.GraphQL(NewExecutableSchema(Config{ Resolvers: &Resolver{}, }))) @@ -24,3 +26,75 @@ func TestForcedResolverFieldIsPointer(t *testing.T) { require.True(t, ok) require.Equal(t, "*testserver.Circle", field.Type.Out(0).String()) } + +func TestGeneratedServer(t *testing.T) { + srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{ + Resolvers: &testResolver{}, + }))) + c := client.New(srv.URL) + + t.Run("null bubbling", func(t *testing.T) { + t.Run("when function errors on non required field", func(t *testing.T) { + var resp struct { + Valid string + ErrorBubble *struct { + Id string + ErrorOnNonRequiredField *string + } + } + err := c.Post(`query { valid, errorBubble { id, errorOnNonRequiredField } }`, &resp) + + require.EqualError(t, err, `[{"message":"boom","path":["errorBubble","errorOnNonRequiredField"]}]`) + require.Equal(t, "E1234", resp.ErrorBubble.Id) + require.Nil(t, resp.ErrorBubble.ErrorOnNonRequiredField) + require.Equal(t, "Ok", resp.Valid) + }) + + t.Run("when function errors", func(t *testing.T) { + var resp struct { + Valid string + ErrorBubble *struct { + NilOnRequiredField string + } + } + err := c.Post(`query { valid, errorBubble { id, errorOnRequiredField } }`, &resp) + + require.EqualError(t, err, `[{"message":"boom","path":["errorBubble","errorOnRequiredField"]}]`) + require.Nil(t, resp.ErrorBubble) + require.Equal(t, "Ok", resp.Valid) + }) + + t.Run("when user returns null on required field", func(t *testing.T) { + var resp struct { + Valid string + ErrorBubble *struct { + NilOnRequiredField string + } + } + err := c.Post(`query { valid, errorBubble { id, nilOnRequiredField } }`, &resp) + + require.EqualError(t, err, `[{"message":"must not be null","path":["errorBubble","nilOnRequiredField"]}]`) + require.Nil(t, resp.ErrorBubble) + require.Equal(t, "Ok", resp.Valid) + }) + }) +} + +type testResolver struct{} + +func (r *testResolver) ForcedResolver() ForcedResolverResolver { + return &forcedResolverResolver{nil} +} +func (r *testResolver) Query() QueryResolver { + return &testQueryResolver{} +} + +type testQueryResolver struct{ queryResolver } + +func (r *testQueryResolver) ErrorBubble(ctx context.Context) (*Error, error) { + return &Error{ID: "E1234"}, nil +} + +func (r *testQueryResolver) Valid(ctx context.Context) (string, error) { + return "Ok", nil +} diff --git a/codegen/testserver/gqlgen.yml b/codegen/testserver/gqlgen.yml index 455fecc4555..6cea9a88938 100644 --- a/codegen/testserver/gqlgen.yml +++ b/codegen/testserver/gqlgen.yml @@ -29,3 +29,5 @@ models: model: "github.com/99designs/gqlgen/codegen/testserver.ForcedResolver" fields: field: { resolver: true } + Error: + model: "github.com/99designs/gqlgen/codegen/testserver.Error" diff --git a/codegen/testserver/models.go b/codegen/testserver/models.go index 4eb1a451127..0390ddb45dd 100644 --- a/codegen/testserver/models.go +++ b/codegen/testserver/models.go @@ -1,5 +1,23 @@ package testserver +import "fmt" + type ForcedResolver struct { Field Circle } + +type Error struct { + ID string +} + +func (Error) ErrorOnRequiredField() (string, error) { + return "", fmt.Errorf("boom") +} + +func (Error) ErrorOnNonRequiredField() (string, error) { + return "", fmt.Errorf("boom") +} + +func (Error) NilOnRequiredField() *string { + return nil +} diff --git a/codegen/testserver/resolver.go b/codegen/testserver/resolver.go index ace486f35b8..f0ed8a17453 100644 --- a/codegen/testserver/resolver.go +++ b/codegen/testserver/resolver.go @@ -50,6 +50,12 @@ func (r *queryResolver) Keywords(ctx context.Context, input *Keywords) (bool, er func (r *queryResolver) Shapes(ctx context.Context) ([]*Shape, error) { panic("not implemented") } +func (r *queryResolver) ErrorBubble(ctx context.Context) (*Error, error) { + panic("not implemented") +} +func (r *queryResolver) Valid(ctx context.Context) (string, error) { + panic("not implemented") +} func (r *queryResolver) KeywordArgs(ctx context.Context, breakArg string, defaultArg string, funcArg string, interfaceArg string, selectArg string, caseArg string, deferArg string, goArg string, mapArg string, structArg string, chanArg string, elseArg string, gotoArg string, packageArg string, switchArg string, constArg string, fallthroughArg string, ifArg string, rangeArg string, typeArg string, continueArg string, forArg string, importArg string, returnArg string, varArg string) (bool, error) { panic("not implemented") } diff --git a/codegen/testserver/schema.graphql b/codegen/testserver/schema.graphql index 4024fc4271f..9e8ebe039fc 100644 --- a/codegen/testserver/schema.graphql +++ b/codegen/testserver/schema.graphql @@ -7,6 +7,15 @@ type Query { nestedOutputs: [[OuterObject]] keywords(input: Keywords): Boolean! shapes: [Shape] + errorBubble: Error + valid: String! +} + +type Error { + id: ID! + errorOnNonRequiredField: String + errorOnRequiredField: String! + nilOnRequiredField: String! } type InvalidIdentifier { diff --git a/codegen/type.go b/codegen/type.go index 04bb0954315..8c53fe55217 100644 --- a/codegen/type.go +++ b/codegen/type.go @@ -3,6 +3,8 @@ package codegen import ( "strconv" "strings" + + "github.com/vektah/gqlparser/ast" ) type NamedTypes map[string]*NamedType @@ -27,6 +29,7 @@ type Type struct { *NamedType Modifiers []string + ASTType *ast.Type AliasedType *Ref } diff --git a/codegen/type_build.go b/codegen/type_build.go index 127791c0245..f0ec6785d49 100644 --- a/codegen/type_build.go +++ b/codegen/type_build.go @@ -72,6 +72,7 @@ func pkgAndType(name string) (string, string) { } func (n NamedTypes) getType(t *ast.Type) *Type { + orig := t var modifiers []string for { if t.Elem != nil { @@ -87,6 +88,7 @@ func (n NamedTypes) getType(t *ast.Type) *Type { res := &Type{ NamedType: n[t.NamedType], Modifiers: modifiers, + ASTType: orig, } if res.IsInterface { diff --git a/example/chat/generated.go b/example/chat/generated.go index 3b396fab92e..8456b645081 100644 --- a/example/chat/generated.go +++ b/example/chat/generated.go @@ -127,6 +127,7 @@ func (ec *executionContext) _Chatroom(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, chatroomImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -135,13 +136,22 @@ func (ec *executionContext) _Chatroom(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("Chatroom") case "name": out.Values[i] = ec._Chatroom_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "messages": out.Values[i] = ec._Chatroom_messages(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -156,6 +166,9 @@ func (ec *executionContext) _Chatroom_name(ctx context.Context, field graphql.Co return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -173,6 +186,9 @@ func (ec *executionContext) _Chatroom_messages(ctx context.Context, field graphq return obj.Messages, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]Message) @@ -195,6 +211,7 @@ func (ec *executionContext) _Message(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, messageImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -203,17 +220,32 @@ func (ec *executionContext) _Message(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("Message") case "id": out.Values[i] = ec._Message_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "text": out.Values[i] = ec._Message_text(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "createdBy": out.Values[i] = ec._Message_createdBy(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "createdAt": out.Values[i] = ec._Message_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -228,6 +260,9 @@ func (ec *executionContext) _Message_id(ctx context.Context, field graphql.Colle return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -245,6 +280,9 @@ func (ec *executionContext) _Message_text(ctx context.Context, field graphql.Col return obj.Text, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -262,6 +300,9 @@ func (ec *executionContext) _Message_createdBy(ctx context.Context, field graphq return obj.CreatedBy, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -279,6 +320,9 @@ func (ec *executionContext) _Message_createdAt(ctx context.Context, field graphq return obj.CreatedAt, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(time.Time) @@ -296,6 +340,7 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) }) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -304,11 +349,17 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) out.Values[i] = graphql.MarshalString("Mutation") case "post": out.Values[i] = ec._Mutation_post(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -355,6 +406,9 @@ func (ec *executionContext) _Mutation_post(ctx context.Context, field graphql.Co return ec.resolvers.Mutation().Post(ctx, args["text"].(string), args["username"].(string), args["roomName"].(string)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(Message) @@ -373,6 +427,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -394,6 +449,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -423,6 +481,7 @@ func (ec *executionContext) _Query_room(ctx context.Context, field graphql.Colle return graphql.Null } res := resTmp.(*Chatroom) + if res == nil { return graphql.Null } @@ -455,6 +514,7 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -475,6 +535,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C return graphql.Null } res := resTmp.(*introspection.Schema) + if res == nil { return graphql.Null } @@ -539,6 +600,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -547,17 +609,29 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__Directive") case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -572,6 +646,9 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -606,6 +683,9 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr return obj.Locations, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]string) @@ -632,6 +712,9 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -654,6 +737,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -662,10 +746,16 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__EnumValue") case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: @@ -673,6 +763,9 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } + if invalid { + return graphql.Null + } return out } @@ -687,6 +780,9 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -721,6 +817,9 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -751,6 +850,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __FieldImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -759,14 +859,26 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Field") case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: @@ -774,6 +886,9 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } + if invalid { + return graphql.Null + } return out } @@ -788,6 +903,9 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -822,6 +940,9 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -848,10 +969,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -868,6 +996,9 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -898,6 +1029,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -906,10 +1038,16 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection out.Values[i] = graphql.MarshalString("__InputValue") case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: @@ -917,6 +1055,9 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } + if invalid { + return graphql.Null + } return out } @@ -931,6 +1072,9 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -965,10 +1109,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -988,6 +1139,7 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1001,6 +1153,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1009,19 +1162,31 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Schema") case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -1036,6 +1201,9 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C return obj.Types(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Type) @@ -1062,10 +1230,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph return obj.QueryType(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1085,6 +1260,7 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1105,6 +1281,7 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1122,6 +1299,9 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap return obj.Directives(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Directive) @@ -1144,6 +1324,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, __TypeImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1152,6 +1333,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o out.Values[i] = graphql.MarshalString("__Type") case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": @@ -1173,6 +1357,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -1187,6 +1374,9 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll return obj.Kind(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1207,6 +1397,7 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1398,6 +1589,7 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } diff --git a/example/config/generated.go b/example/config/generated.go index cb2e75e8b67..7fea7a18d68 100644 --- a/example/config/generated.go +++ b/example/config/generated.go @@ -106,6 +106,7 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) }) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -114,11 +115,17 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) out.Values[i] = graphql.MarshalString("Mutation") case "createTodo": out.Values[i] = ec._Mutation_createTodo(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -145,6 +152,9 @@ func (ec *executionContext) _Mutation_createTodo(ctx context.Context, field grap return ec.resolvers.Mutation().CreateTodo(ctx, args["input"].(NewTodo)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(Todo) @@ -163,6 +173,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -173,6 +184,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Query_todos(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "__type": @@ -184,6 +198,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -198,6 +215,9 @@ func (ec *executionContext) _Query_todos(ctx context.Context, field graphql.Coll return ec.resolvers.Query().Todos(ctx) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]Todo) @@ -239,6 +259,7 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -259,6 +280,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C return graphql.Null } res := resTmp.(*introspection.Schema) + if res == nil { return graphql.Null } @@ -273,6 +295,7 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -283,21 +306,39 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Todo_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "databaseId": out.Values[i] = ec._Todo_databaseId(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "text": out.Values[i] = ec._Todo_text(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "done": out.Values[i] = ec._Todo_done(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "user": out.Values[i] = ec._Todo_user(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -312,6 +353,9 @@ func (ec *executionContext) _Todo_id(ctx context.Context, field graphql.Collecte return ec.resolvers.Todo().ID(ctx, obj) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -329,6 +373,9 @@ func (ec *executionContext) _Todo_databaseId(ctx context.Context, field graphql. return obj.DatabaseID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(int) @@ -346,6 +393,9 @@ func (ec *executionContext) _Todo_text(ctx context.Context, field graphql.Collec return obj.Description, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -363,6 +413,9 @@ func (ec *executionContext) _Todo_done(ctx context.Context, field graphql.Collec return obj.Done, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -380,6 +433,9 @@ func (ec *executionContext) _Todo_user(ctx context.Context, field graphql.Collec return obj.User, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(User) @@ -393,6 +449,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ctx, sel, userImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -401,13 +458,22 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = graphql.MarshalString("User") case "id": out.Values[i] = ec._User_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec._User_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -422,6 +488,9 @@ func (ec *executionContext) _User_id(ctx context.Context, field graphql.Collecte return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -439,6 +508,9 @@ func (ec *executionContext) _User_name(ctx context.Context, field graphql.Collec return obj.FullName(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -452,6 +524,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -460,17 +533,29 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__Directive") case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -485,6 +570,9 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -519,6 +607,9 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr return obj.Locations, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]string) @@ -545,6 +636,9 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -567,6 +661,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -575,10 +670,16 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__EnumValue") case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: @@ -586,6 +687,9 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } + if invalid { + return graphql.Null + } return out } @@ -600,6 +704,9 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -634,6 +741,9 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -664,6 +774,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __FieldImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -672,14 +783,26 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Field") case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: @@ -687,6 +810,9 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } + if invalid { + return graphql.Null + } return out } @@ -701,6 +827,9 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -735,6 +864,9 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -761,10 +893,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -781,6 +920,9 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -811,6 +953,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -819,10 +962,16 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection out.Values[i] = graphql.MarshalString("__InputValue") case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: @@ -830,6 +979,9 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } + if invalid { + return graphql.Null + } return out } @@ -844,6 +996,9 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -878,10 +1033,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -901,6 +1063,7 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -914,6 +1077,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -922,19 +1086,31 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Schema") case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -949,6 +1125,9 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C return obj.Types(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Type) @@ -975,10 +1154,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph return obj.QueryType(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -998,6 +1184,7 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1018,6 +1205,7 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1035,6 +1223,9 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap return obj.Directives(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Directive) @@ -1057,6 +1248,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, __TypeImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1065,6 +1257,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o out.Values[i] = graphql.MarshalString("__Type") case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": @@ -1086,6 +1281,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -1100,6 +1298,9 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll return obj.Kind(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1120,6 +1321,7 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1311,6 +1513,7 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } diff --git a/example/dataloader/generated.go b/example/dataloader/generated.go index 5c5c7e33d3a..2c7ba01013c 100644 --- a/example/dataloader/generated.go +++ b/example/dataloader/generated.go @@ -94,6 +94,7 @@ func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, addressImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -102,15 +103,27 @@ func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("Address") case "id": out.Values[i] = ec._Address_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "street": out.Values[i] = ec._Address_street(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "country": out.Values[i] = ec._Address_country(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -125,6 +138,9 @@ func (ec *executionContext) _Address_id(ctx context.Context, field graphql.Colle return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(int) @@ -142,6 +158,9 @@ func (ec *executionContext) _Address_street(ctx context.Context, field graphql.C return obj.Street, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -159,6 +178,9 @@ func (ec *executionContext) _Address_country(ctx context.Context, field graphql. return obj.Country, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -173,6 +195,7 @@ func (ec *executionContext) _Customer(ctx context.Context, sel ast.SelectionSet, var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -181,8 +204,14 @@ func (ec *executionContext) _Customer(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("Customer") case "id": out.Values[i] = ec._Customer_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec._Customer_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "address": wg.Add(1) go func(i int, field graphql.CollectedField) { @@ -200,6 +229,9 @@ func (ec *executionContext) _Customer(ctx context.Context, sel ast.SelectionSet, } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -214,6 +246,9 @@ func (ec *executionContext) _Customer_id(ctx context.Context, field graphql.Coll return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(int) @@ -231,6 +266,9 @@ func (ec *executionContext) _Customer_name(ctx context.Context, field graphql.Co return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -251,6 +289,7 @@ func (ec *executionContext) _Customer_address(ctx context.Context, field graphql return graphql.Null } res := resTmp.(*Address) + if res == nil { return graphql.Null } @@ -290,6 +329,7 @@ func (ec *executionContext) _Item(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ctx, sel, itemImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -298,11 +338,17 @@ func (ec *executionContext) _Item(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = graphql.MarshalString("Item") case "name": out.Values[i] = ec._Item_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -317,6 +363,9 @@ func (ec *executionContext) _Item_name(ctx context.Context, field graphql.Collec return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -331,6 +380,7 @@ func (ec *executionContext) _Order(ctx context.Context, sel ast.SelectionSet, ob var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -339,10 +389,19 @@ func (ec *executionContext) _Order(ctx context.Context, sel ast.SelectionSet, ob out.Values[i] = graphql.MarshalString("Order") case "id": out.Values[i] = ec._Order_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "date": out.Values[i] = ec._Order_date(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "amount": out.Values[i] = ec._Order_amount(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "items": wg.Add(1) go func(i int, field graphql.CollectedField) { @@ -354,6 +413,9 @@ func (ec *executionContext) _Order(ctx context.Context, sel ast.SelectionSet, ob } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -368,6 +430,9 @@ func (ec *executionContext) _Order_id(ctx context.Context, field graphql.Collect return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(int) @@ -385,6 +450,9 @@ func (ec *executionContext) _Order_date(ctx context.Context, field graphql.Colle return obj.Date, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(time.Time) @@ -402,6 +470,9 @@ func (ec *executionContext) _Order_amount(ctx context.Context, field graphql.Col return obj.Amount, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(float64) @@ -446,6 +517,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -479,6 +551,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -652,6 +727,7 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -672,6 +748,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C return graphql.Null } res := resTmp.(*introspection.Schema) + if res == nil { return graphql.Null } @@ -685,6 +762,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -693,17 +771,29 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__Directive") case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -718,6 +808,9 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -752,6 +845,9 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr return obj.Locations, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]string) @@ -778,6 +874,9 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -800,6 +899,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -808,10 +908,16 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__EnumValue") case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: @@ -819,6 +925,9 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } + if invalid { + return graphql.Null + } return out } @@ -833,6 +942,9 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -867,6 +979,9 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -897,6 +1012,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __FieldImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -905,14 +1021,26 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Field") case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: @@ -920,6 +1048,9 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } + if invalid { + return graphql.Null + } return out } @@ -934,6 +1065,9 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -968,6 +1102,9 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -994,10 +1131,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1014,6 +1158,9 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -1044,6 +1191,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1052,10 +1200,16 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection out.Values[i] = graphql.MarshalString("__InputValue") case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: @@ -1063,6 +1217,9 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } + if invalid { + return graphql.Null + } return out } @@ -1077,6 +1234,9 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1111,10 +1271,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1134,6 +1301,7 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1147,6 +1315,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1155,19 +1324,31 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Schema") case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -1182,6 +1363,9 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C return obj.Types(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Type) @@ -1208,10 +1392,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph return obj.QueryType(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1231,6 +1422,7 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1251,6 +1443,7 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1268,6 +1461,9 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap return obj.Directives(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Directive) @@ -1290,6 +1486,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, __TypeImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1298,6 +1495,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o out.Values[i] = graphql.MarshalString("__Type") case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": @@ -1319,6 +1519,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -1333,6 +1536,9 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll return obj.Kind(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1353,6 +1559,7 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1544,6 +1751,7 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } diff --git a/example/scalars/generated.go b/example/scalars/generated.go index dd75719736e..4ab0d65deca 100644 --- a/example/scalars/generated.go +++ b/example/scalars/generated.go @@ -91,6 +91,7 @@ func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, addressImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -99,6 +100,9 @@ func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("Address") case "id": out.Values[i] = ec._Address_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "location": out.Values[i] = ec._Address_location(ctx, field, obj) default: @@ -106,6 +110,9 @@ func (ec *executionContext) _Address(ctx context.Context, sel ast.SelectionSet, } } + if invalid { + return graphql.Null + } return out } @@ -120,6 +127,9 @@ func (ec *executionContext) _Address_id(ctx context.Context, field graphql.Colle return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(external.ObjectID) @@ -140,6 +150,7 @@ func (ec *executionContext) _Address_location(ctx context.Context, field graphql return graphql.Null } res := resTmp.(*model.Point) + if res == nil { return graphql.Null } @@ -158,6 +169,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -174,6 +186,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Query_search(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "__type": @@ -185,6 +200,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -214,6 +232,7 @@ func (ec *executionContext) _Query_user(ctx context.Context, field graphql.Colle return graphql.Null } res := resTmp.(*model.User) + if res == nil { return graphql.Null } @@ -243,6 +262,9 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col return ec.resolvers.Query().Search(ctx, args["input"].(model.SearchArgs)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]model.User) @@ -284,6 +306,7 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -304,6 +327,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C return graphql.Null } res := resTmp.(*introspection.Schema) + if res == nil { return graphql.Null } @@ -318,6 +342,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -326,22 +351,37 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = graphql.MarshalString("User") case "id": out.Values[i] = ec._User_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec._User_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "created": out.Values[i] = ec._User_created(ctx, field, obj) case "isBanned": out.Values[i] = ec._User_isBanned(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "primitiveResolver": wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._User_primitiveResolver(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "customResolver": wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._User_customResolver(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "address": @@ -353,6 +393,9 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -367,6 +410,9 @@ func (ec *executionContext) _User_id(ctx context.Context, field graphql.Collecte return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(external.ObjectID) @@ -384,6 +430,9 @@ func (ec *executionContext) _User_name(ctx context.Context, field graphql.Collec return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -418,6 +467,9 @@ func (ec *executionContext) _User_isBanned(ctx context.Context, field graphql.Co return obj.IsBanned, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(model.Banned) @@ -435,6 +487,9 @@ func (ec *executionContext) _User_primitiveResolver(ctx context.Context, field g return ec.resolvers.User().PrimitiveResolver(ctx, obj) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -452,6 +507,9 @@ func (ec *executionContext) _User_customResolver(ctx context.Context, field grap return ec.resolvers.User().CustomResolver(ctx, obj) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(model.Point) @@ -499,6 +557,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -507,17 +566,29 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__Directive") case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -532,6 +603,9 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -566,6 +640,9 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr return obj.Locations, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]string) @@ -592,6 +669,9 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -614,6 +694,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -622,10 +703,16 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__EnumValue") case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: @@ -633,6 +720,9 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } + if invalid { + return graphql.Null + } return out } @@ -647,6 +737,9 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -681,6 +774,9 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -711,6 +807,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __FieldImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -719,14 +816,26 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Field") case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: @@ -734,6 +843,9 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } + if invalid { + return graphql.Null + } return out } @@ -748,6 +860,9 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -782,6 +897,9 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -808,10 +926,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -828,6 +953,9 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -858,6 +986,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -866,10 +995,16 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection out.Values[i] = graphql.MarshalString("__InputValue") case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: @@ -877,6 +1012,9 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } + if invalid { + return graphql.Null + } return out } @@ -891,6 +1029,9 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -925,10 +1066,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -948,6 +1096,7 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -961,6 +1110,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -969,19 +1119,31 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Schema") case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -996,6 +1158,9 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C return obj.Types(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Type) @@ -1022,10 +1187,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph return obj.QueryType(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1045,6 +1217,7 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1065,6 +1238,7 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1082,6 +1256,9 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap return obj.Directives(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Directive) @@ -1104,6 +1281,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, __TypeImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1112,6 +1290,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o out.Values[i] = graphql.MarshalString("__Type") case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": @@ -1133,6 +1314,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -1147,6 +1331,9 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll return obj.Kind(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1167,6 +1354,7 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1358,6 +1546,7 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } diff --git a/example/selection/generated.go b/example/selection/generated.go index e8d19b1c53a..58155f057e0 100644 --- a/example/selection/generated.go +++ b/example/selection/generated.go @@ -84,6 +84,7 @@ func (ec *executionContext) _Like(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ctx, sel, likeImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -92,8 +93,14 @@ func (ec *executionContext) _Like(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = graphql.MarshalString("Like") case "reaction": out.Values[i] = ec._Like_reaction(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "sent": out.Values[i] = ec._Like_sent(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "selection": out.Values[i] = ec._Like_selection(ctx, field, obj) case "collected": @@ -103,6 +110,9 @@ func (ec *executionContext) _Like(ctx context.Context, sel ast.SelectionSet, obj } } + if invalid { + return graphql.Null + } return out } @@ -117,6 +127,9 @@ func (ec *executionContext) _Like_reaction(ctx context.Context, field graphql.Co return obj.Reaction, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -134,6 +147,9 @@ func (ec *executionContext) _Like_sent(ctx context.Context, field graphql.Collec return obj.Sent, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(time.Time) @@ -199,6 +215,7 @@ func (ec *executionContext) _Post(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ctx, sel, postImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -207,8 +224,14 @@ func (ec *executionContext) _Post(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = graphql.MarshalString("Post") case "message": out.Values[i] = ec._Post_message(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "sent": out.Values[i] = ec._Post_sent(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "selection": out.Values[i] = ec._Post_selection(ctx, field, obj) case "collected": @@ -218,6 +241,9 @@ func (ec *executionContext) _Post(ctx context.Context, sel ast.SelectionSet, obj } } + if invalid { + return graphql.Null + } return out } @@ -232,6 +258,9 @@ func (ec *executionContext) _Post_message(ctx context.Context, field graphql.Col return obj.Message, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -249,6 +278,9 @@ func (ec *executionContext) _Post_sent(ctx context.Context, field graphql.Collec return obj.Sent, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(time.Time) @@ -319,6 +351,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -340,6 +373,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -395,6 +431,7 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -415,6 +452,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C return graphql.Null } res := resTmp.(*introspection.Schema) + if res == nil { return graphql.Null } @@ -428,6 +466,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -436,17 +475,29 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__Directive") case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -461,6 +512,9 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -495,6 +549,9 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr return obj.Locations, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]string) @@ -521,6 +578,9 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -543,6 +603,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -551,10 +612,16 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__EnumValue") case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: @@ -562,6 +629,9 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } + if invalid { + return graphql.Null + } return out } @@ -576,6 +646,9 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -610,6 +683,9 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -640,6 +716,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __FieldImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -648,14 +725,26 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Field") case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: @@ -663,6 +752,9 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } + if invalid { + return graphql.Null + } return out } @@ -677,6 +769,9 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -711,6 +806,9 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -737,10 +835,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -757,6 +862,9 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -787,6 +895,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -795,10 +904,16 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection out.Values[i] = graphql.MarshalString("__InputValue") case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: @@ -806,6 +921,9 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } + if invalid { + return graphql.Null + } return out } @@ -820,6 +938,9 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -854,10 +975,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -877,6 +1005,7 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -890,6 +1019,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -898,19 +1028,31 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Schema") case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -925,6 +1067,9 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C return obj.Types(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Type) @@ -951,10 +1096,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph return obj.QueryType(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -974,6 +1126,7 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -994,6 +1147,7 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1011,6 +1165,9 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap return obj.Directives(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Directive) @@ -1033,6 +1190,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, __TypeImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1041,6 +1199,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o out.Values[i] = graphql.MarshalString("__Type") case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": @@ -1062,6 +1223,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -1076,6 +1240,9 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll return obj.Kind(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1096,6 +1263,7 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1287,6 +1455,7 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } diff --git a/example/starwars/generated.go b/example/starwars/generated.go index e0b971931a4..a9514437f3d 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated.go @@ -128,6 +128,7 @@ func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, ob var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -136,8 +137,14 @@ func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, ob out.Values[i] = graphql.MarshalString("Droid") case "id": out.Values[i] = ec._Droid_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec._Droid_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "friends": wg.Add(1) go func(i int, field graphql.CollectedField) { @@ -148,10 +155,16 @@ func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, ob wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Droid_friendsConnection(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "appearsIn": out.Values[i] = ec._Droid_appearsIn(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "primaryFunction": out.Values[i] = ec._Droid_primaryFunction(ctx, field, obj) default: @@ -159,6 +172,9 @@ func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, ob } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -173,6 +189,9 @@ func (ec *executionContext) _Droid_id(ctx context.Context, field graphql.Collect return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -190,6 +209,9 @@ func (ec *executionContext) _Droid_name(ctx context.Context, field graphql.Colle return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -265,6 +287,9 @@ func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field return ec.resolvers.Droid().FriendsConnection(ctx, obj, args["first"].(*int), args["after"].(*string)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(FriendsConnection) @@ -282,6 +307,9 @@ func (ec *executionContext) _Droid_appearsIn(ctx context.Context, field graphql. return obj.AppearsIn, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]Episode) @@ -322,6 +350,7 @@ func (ec *executionContext) _FriendsConnection(ctx context.Context, sel ast.Sele var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -330,6 +359,9 @@ func (ec *executionContext) _FriendsConnection(ctx context.Context, sel ast.Sele out.Values[i] = graphql.MarshalString("FriendsConnection") case "totalCount": out.Values[i] = ec._FriendsConnection_totalCount(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "edges": wg.Add(1) go func(i int, field graphql.CollectedField) { @@ -344,11 +376,17 @@ func (ec *executionContext) _FriendsConnection(ctx context.Context, sel ast.Sele }(i, field) case "pageInfo": out.Values[i] = ec._FriendsConnection_pageInfo(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -363,6 +401,9 @@ func (ec *executionContext) _FriendsConnection_totalCount(ctx context.Context, f return obj.TotalCount(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(int) @@ -432,6 +473,9 @@ func (ec *executionContext) _FriendsConnection_pageInfo(ctx context.Context, fie return obj.PageInfo(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(PageInfo) @@ -445,6 +489,7 @@ func (ec *executionContext) _FriendsEdge(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, friendsEdgeImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -453,6 +498,9 @@ func (ec *executionContext) _FriendsEdge(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("FriendsEdge") case "cursor": out.Values[i] = ec._FriendsEdge_cursor(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "node": out.Values[i] = ec._FriendsEdge_node(ctx, field, obj) default: @@ -460,6 +508,9 @@ func (ec *executionContext) _FriendsEdge(ctx context.Context, sel ast.SelectionS } } + if invalid { + return graphql.Null + } return out } @@ -474,6 +525,9 @@ func (ec *executionContext) _FriendsEdge_cursor(ctx context.Context, field graph return obj.Cursor, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -505,6 +559,7 @@ func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, ob var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -513,10 +568,19 @@ func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, ob out.Values[i] = graphql.MarshalString("Human") case "id": out.Values[i] = ec._Human_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec._Human_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "height": out.Values[i] = ec._Human_height(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "mass": out.Values[i] = ec._Human_mass(ctx, field, obj) case "friends": @@ -529,10 +593,16 @@ func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, ob wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Human_friendsConnection(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "appearsIn": out.Values[i] = ec._Human_appearsIn(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "starships": wg.Add(1) go func(i int, field graphql.CollectedField) { @@ -544,6 +614,9 @@ func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, ob } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -558,6 +631,9 @@ func (ec *executionContext) _Human_id(ctx context.Context, field graphql.Collect return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -575,6 +651,9 @@ func (ec *executionContext) _Human_name(ctx context.Context, field graphql.Colle return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -604,6 +683,9 @@ func (ec *executionContext) _Human_height(ctx context.Context, field graphql.Col return obj.Height(args["unit"].(LengthUnit)), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(float64) @@ -696,6 +778,9 @@ func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field return ec.resolvers.Human().FriendsConnection(ctx, obj, args["first"].(*int), args["after"].(*string)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(FriendsConnection) @@ -713,6 +798,9 @@ func (ec *executionContext) _Human_appearsIn(ctx context.Context, field graphql. return obj.AppearsIn, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]Episode) @@ -765,6 +853,7 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) }) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -778,6 +867,9 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) } } + if invalid { + return graphql.Null + } return out } @@ -817,6 +909,7 @@ func (ec *executionContext) _Mutation_createReview(ctx context.Context, field gr return graphql.Null } res := resTmp.(*Review) + if res == nil { return graphql.Null } @@ -830,6 +923,7 @@ func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, pageInfoImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -838,15 +932,27 @@ func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("PageInfo") case "startCursor": out.Values[i] = ec._PageInfo_startCursor(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "endCursor": out.Values[i] = ec._PageInfo_endCursor(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "hasNextPage": out.Values[i] = ec._PageInfo_hasNextPage(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -861,6 +967,9 @@ func (ec *executionContext) _PageInfo_startCursor(ctx context.Context, field gra return obj.StartCursor, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -878,6 +987,9 @@ func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graph return obj.EndCursor, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -895,6 +1007,9 @@ func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field gra return obj.HasNextPage, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -913,6 +1028,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -929,12 +1045,18 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Query_reviews(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "search": wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Query_search(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "character": @@ -970,6 +1092,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -1040,6 +1165,9 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co return ec.resolvers.Query().Reviews(ctx, args["episode"].(Episode), args["since"].(*time.Time)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]Review) @@ -1078,6 +1206,9 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col return ec.resolvers.Query().Search(ctx, args["text"].(string)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]SearchResult) @@ -1148,6 +1279,7 @@ func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*Droid) + if res == nil { return graphql.Null } @@ -1180,6 +1312,7 @@ func (ec *executionContext) _Query_human(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*Human) + if res == nil { return graphql.Null } @@ -1212,6 +1345,7 @@ func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.C return graphql.Null } res := resTmp.(*Starship) + if res == nil { return graphql.Null } @@ -1244,6 +1378,7 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1264,6 +1399,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C return graphql.Null } res := resTmp.(*introspection.Schema) + if res == nil { return graphql.Null } @@ -1277,6 +1413,7 @@ func (ec *executionContext) _Review(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, reviewImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1285,6 +1422,9 @@ func (ec *executionContext) _Review(ctx context.Context, sel ast.SelectionSet, o out.Values[i] = graphql.MarshalString("Review") case "stars": out.Values[i] = ec._Review_stars(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "commentary": out.Values[i] = ec._Review_commentary(ctx, field, obj) case "time": @@ -1294,6 +1434,9 @@ func (ec *executionContext) _Review(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -1308,6 +1451,9 @@ func (ec *executionContext) _Review_stars(ctx context.Context, field graphql.Col return obj.Stars, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(int) @@ -1328,6 +1474,7 @@ func (ec *executionContext) _Review_commentary(ctx context.Context, field graphq return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1359,6 +1506,7 @@ func (ec *executionContext) _Starship(ctx context.Context, sel ast.SelectionSet, var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1367,21 +1515,36 @@ func (ec *executionContext) _Starship(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("Starship") case "id": out.Values[i] = ec._Starship_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec._Starship_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "length": wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Starship_length(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "history": out.Values[i] = ec._Starship_history(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -1396,6 +1559,9 @@ func (ec *executionContext) _Starship_id(ctx context.Context, field graphql.Coll return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1413,6 +1579,9 @@ func (ec *executionContext) _Starship_name(ctx context.Context, field graphql.Co return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1442,6 +1611,9 @@ func (ec *executionContext) _Starship_length(ctx context.Context, field graphql. return ec.resolvers.Starship().Length(ctx, obj, args["unit"].(LengthUnit)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(float64) @@ -1459,6 +1631,9 @@ func (ec *executionContext) _Starship_history(ctx context.Context, field graphql return obj.History, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([][]int) @@ -1490,6 +1665,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1498,17 +1674,29 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__Directive") case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -1523,6 +1711,9 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1557,6 +1748,9 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr return obj.Locations, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]string) @@ -1583,6 +1777,9 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -1605,6 +1802,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1613,10 +1811,16 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__EnumValue") case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: @@ -1624,6 +1828,9 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } + if invalid { + return graphql.Null + } return out } @@ -1638,6 +1845,9 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1672,6 +1882,9 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -1702,6 +1915,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __FieldImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1710,14 +1924,26 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Field") case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: @@ -1725,6 +1951,9 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } + if invalid { + return graphql.Null + } return out } @@ -1739,6 +1968,9 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1773,6 +2005,9 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -1799,10 +2034,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1819,6 +2061,9 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -1849,6 +2094,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1857,10 +2103,16 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection out.Values[i] = graphql.MarshalString("__InputValue") case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: @@ -1868,6 +2120,9 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } + if invalid { + return graphql.Null + } return out } @@ -1882,6 +2137,9 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1916,10 +2174,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1939,6 +2204,7 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1952,6 +2218,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1960,19 +2227,31 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Schema") case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -1987,6 +2266,9 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C return obj.Types(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Type) @@ -2013,10 +2295,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph return obj.QueryType(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -2036,6 +2325,7 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -2056,6 +2346,7 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -2073,6 +2364,9 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap return obj.Directives(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Directive) @@ -2095,6 +2389,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, __TypeImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -2103,6 +2398,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o out.Values[i] = graphql.MarshalString("__Type") case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": @@ -2124,6 +2422,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -2138,6 +2439,9 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll return obj.Kind(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -2158,6 +2462,7 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -2349,6 +2654,7 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } diff --git a/example/todo/generated.go b/example/todo/generated.go index 69f28e9a529..795abe71236 100644 --- a/example/todo/generated.go +++ b/example/todo/generated.go @@ -107,6 +107,7 @@ func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSe }) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -115,6 +116,9 @@ func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSe out.Values[i] = graphql.MarshalString("MyMutation") case "createTodo": out.Values[i] = ec._MyMutation_createTodo(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } case "updateTodo": out.Values[i] = ec._MyMutation_updateTodo(ctx, field) default: @@ -122,6 +126,9 @@ func (ec *executionContext) _MyMutation(ctx context.Context, sel ast.SelectionSe } } + if invalid { + return graphql.Null + } return out } @@ -148,6 +155,9 @@ func (ec *executionContext) _MyMutation_createTodo(ctx context.Context, field gr return ec.resolvers.MyMutation().CreateTodo(ctx, args["todo"].(TodoInput)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(Todo) @@ -190,6 +200,7 @@ func (ec *executionContext) _MyMutation_updateTodo(ctx context.Context, field gr return graphql.Null } res := resTmp.(*Todo) + if res == nil { return graphql.Null } @@ -208,6 +219,7 @@ func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -236,6 +248,9 @@ func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._MyQuery_todos(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "__type": @@ -247,6 +262,9 @@ func (ec *executionContext) _MyQuery(ctx context.Context, sel ast.SelectionSet) } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -276,6 +294,7 @@ func (ec *executionContext) _MyQuery_todo(ctx context.Context, field graphql.Col return graphql.Null } res := resTmp.(*Todo) + if res == nil { return graphql.Null } @@ -308,6 +327,7 @@ func (ec *executionContext) _MyQuery_authenticatedTodo(ctx context.Context, fiel return graphql.Null } res := resTmp.(*Todo) + if res == nil { return graphql.Null } @@ -328,6 +348,7 @@ func (ec *executionContext) _MyQuery_lastTodo(ctx context.Context, field graphql return graphql.Null } res := resTmp.(*Todo) + if res == nil { return graphql.Null } @@ -345,6 +366,9 @@ func (ec *executionContext) _MyQuery_todos(ctx context.Context, field graphql.Co return ec.resolvers.MyQuery().Todos(ctx) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]Todo) @@ -386,6 +410,7 @@ func (ec *executionContext) _MyQuery___type(ctx context.Context, field graphql.C return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -406,6 +431,7 @@ func (ec *executionContext) _MyQuery___schema(ctx context.Context, field graphql return graphql.Null } res := resTmp.(*introspection.Schema) + if res == nil { return graphql.Null } @@ -419,6 +445,7 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj fields := graphql.CollectFields(ctx, sel, todoImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -427,15 +454,27 @@ func (ec *executionContext) _Todo(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = graphql.MarshalString("Todo") case "id": out.Values[i] = ec._Todo_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "text": out.Values[i] = ec._Todo_text(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "done": out.Values[i] = ec._Todo_done(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -450,6 +489,9 @@ func (ec *executionContext) _Todo_id(ctx context.Context, field graphql.Collecte return obj.ID, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(int) @@ -467,6 +509,9 @@ func (ec *executionContext) _Todo_text(ctx context.Context, field graphql.Collec return obj.Text, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -484,6 +529,9 @@ func (ec *executionContext) _Todo_done(ctx context.Context, field graphql.Collec return obj.Done, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -497,6 +545,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -505,17 +554,29 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__Directive") case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -530,6 +591,9 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -564,6 +628,9 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr return obj.Locations, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]string) @@ -590,6 +657,9 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -612,6 +682,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -620,10 +691,16 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__EnumValue") case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: @@ -631,6 +708,9 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } + if invalid { + return graphql.Null + } return out } @@ -645,6 +725,9 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -679,6 +762,9 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -709,6 +795,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __FieldImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -717,14 +804,26 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Field") case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: @@ -732,6 +831,9 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } + if invalid { + return graphql.Null + } return out } @@ -746,6 +848,9 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -780,6 +885,9 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -806,10 +914,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -826,6 +941,9 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -856,6 +974,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -864,10 +983,16 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection out.Values[i] = graphql.MarshalString("__InputValue") case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: @@ -875,6 +1000,9 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } + if invalid { + return graphql.Null + } return out } @@ -889,6 +1017,9 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -923,10 +1054,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -946,6 +1084,7 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -959,6 +1098,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -967,19 +1107,31 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Schema") case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -994,6 +1146,9 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C return obj.Types(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Type) @@ -1020,10 +1175,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph return obj.QueryType(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1043,6 +1205,7 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1063,6 +1226,7 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1080,6 +1244,9 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap return obj.Directives(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Directive) @@ -1102,6 +1269,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, __TypeImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1110,6 +1278,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o out.Values[i] = graphql.MarshalString("__Type") case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": @@ -1131,6 +1302,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -1145,6 +1319,9 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll return obj.Kind(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1165,6 +1342,7 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1356,6 +1534,7 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } diff --git a/graphql/context.go b/graphql/context.go index 63c01c86797..66c63aaf54b 100644 --- a/graphql/context.go +++ b/graphql/context.go @@ -148,6 +148,34 @@ func (c *RequestContext) Error(ctx context.Context, err error) { c.Errors = append(c.Errors, c.ErrorPresenter(ctx, err)) } +// HasError returns true if the current field has already errored +func (c *RequestContext) HasError(rctx *ResolverContext) bool { + c.errorsMu.Lock() + defer c.errorsMu.Unlock() + path := rctx.Path() + + for _, err := range c.Errors { + if equalPath(err.Path, path) { + return true + } + } + return false +} + +func equalPath(a []interface{}, b []interface{}) bool { + if len(a) != len(b) { + return false + } + + for i := 0; i < len(a); i++ { + if a[i] != b[i] { + return false + } + } + + return true +} + // AddError is a convenience method for adding an error to the current response func AddError(ctx context.Context, err error) { GetRequestContext(ctx).Error(ctx, err) diff --git a/graphql/jsonw.go b/graphql/jsonw.go index ef9e69c7ab1..c112444a7e6 100644 --- a/graphql/jsonw.go +++ b/graphql/jsonw.go @@ -15,9 +15,9 @@ var closeBracket = []byte(`]`) var colon = []byte(`:`) var comma = []byte(`,`) -var Null = lit(nullLit) -var True = lit(trueLit) -var False = lit(falseLit) +var Null = &lit{nullLit} +var True = &lit{trueLit} +var False = &lit{falseLit} type Marshaler interface { MarshalGQL(w io.Writer) @@ -76,8 +76,8 @@ func (a Array) MarshalGQL(writer io.Writer) { writer.Write(closeBracket) } -func lit(b []byte) Marshaler { - return WriterFunc(func(w io.Writer) { - w.Write(b) - }) +type lit struct{ b []byte } + +func (l lit) MarshalGQL(w io.Writer) { + w.Write(l.b) } diff --git a/integration/generated.go b/integration/generated.go index ecd15597e03..00a3ec341fd 100644 --- a/integration/generated.go +++ b/integration/generated.go @@ -99,6 +99,7 @@ func (ec *executionContext) _Element(ctx context.Context, sel ast.SelectionSet, var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -109,12 +110,18 @@ func (ec *executionContext) _Element(ctx context.Context, sel ast.SelectionSet, wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Element_child(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "error": wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Element_error(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "mismatched": @@ -128,6 +135,9 @@ func (ec *executionContext) _Element(ctx context.Context, sel ast.SelectionSet, } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -142,6 +152,9 @@ func (ec *executionContext) _Element_child(ctx context.Context, field graphql.Co return ec.resolvers.Element().Child(ctx, obj) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(models.Element) @@ -159,6 +172,9 @@ func (ec *executionContext) _Element_error(ctx context.Context, field graphql.Co return ec.resolvers.Element().Error(ctx, obj) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -203,6 +219,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -219,6 +236,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Query_date(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "viewer": @@ -231,12 +251,18 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Query_jsonEncoding(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "error": wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._Query_error(ctx, field) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) case "__type": @@ -248,6 +274,9 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -271,6 +300,7 @@ func (ec *executionContext) _Query_path(ctx context.Context, field graphql.Colle rctx := graphql.GetResolverContext(ctx) rctx.PushIndex(idx1) defer rctx.Pop() + if res[idx1] == nil { return graphql.Null } @@ -303,6 +333,9 @@ func (ec *executionContext) _Query_date(ctx context.Context, field graphql.Colle return ec.resolvers.Query().Date(ctx, args["filter"].(models.DateFilter)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -323,6 +356,7 @@ func (ec *executionContext) _Query_viewer(ctx context.Context, field graphql.Col return graphql.Null } res := resTmp.(*models.Viewer) + if res == nil { return graphql.Null } @@ -340,6 +374,9 @@ func (ec *executionContext) _Query_jsonEncoding(ctx context.Context, field graph return ec.resolvers.Query().JSONEncoding(ctx) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -369,6 +406,9 @@ func (ec *executionContext) _Query_error(ctx context.Context, field graphql.Coll return ec.resolvers.Query().Error(ctx, args["type"].(models.ErrorType)) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -401,6 +441,7 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -421,6 +462,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C return graphql.Null } res := resTmp.(*introspection.Schema) + if res == nil { return graphql.Null } @@ -435,6 +477,7 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj var wg sync.WaitGroup out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -443,10 +486,16 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj out.Values[i] = graphql.MarshalString("User") case "name": out.Values[i] = ec._User_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "likes": wg.Add(1) go func(i int, field graphql.CollectedField) { out.Values[i] = ec._User_likes(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } wg.Done() }(i, field) default: @@ -454,6 +503,9 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj } } wg.Wait() + if invalid { + return graphql.Null + } return out } @@ -468,6 +520,9 @@ func (ec *executionContext) _User_name(ctx context.Context, field graphql.Collec return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -485,6 +540,9 @@ func (ec *executionContext) _User_likes(ctx context.Context, field graphql.Colle return ec.resolvers.User().Likes(ctx, obj) }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]string) @@ -507,6 +565,7 @@ func (ec *executionContext) _Viewer(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, viewerImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -520,6 +579,9 @@ func (ec *executionContext) _Viewer(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -537,6 +599,7 @@ func (ec *executionContext) _Viewer_user(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*remote_api.User) + if res == nil { return graphql.Null } @@ -550,6 +613,7 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __DirectiveImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -558,17 +622,29 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__Directive") case "name": out.Values[i] = ec.___Directive_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Directive_description(ctx, field, obj) case "locations": out.Values[i] = ec.___Directive_locations(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "args": out.Values[i] = ec.___Directive_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -583,6 +659,9 @@ func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -617,6 +696,9 @@ func (ec *executionContext) ___Directive_locations(ctx context.Context, field gr return obj.Locations, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]string) @@ -643,6 +725,9 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -665,6 +750,7 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS fields := graphql.CollectFields(ctx, sel, __EnumValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -673,10 +759,16 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS out.Values[i] = graphql.MarshalString("__EnumValue") case "name": out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___EnumValue_description(ctx, field, obj) case "isDeprecated": out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) default: @@ -684,6 +776,9 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS } } + if invalid { + return graphql.Null + } return out } @@ -698,6 +793,9 @@ func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -732,6 +830,9 @@ func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -762,6 +863,7 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __FieldImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -770,14 +872,26 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Field") case "name": out.Values[i] = ec.___Field_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___Field_description(ctx, field, obj) case "args": out.Values[i] = ec.___Field_args(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "type": out.Values[i] = ec.___Field_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "isDeprecated": out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "deprecationReason": out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) default: @@ -785,6 +899,9 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, } } + if invalid { + return graphql.Null + } return out } @@ -799,6 +916,9 @@ func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.Col return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -833,6 +953,9 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col return obj.Args, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.InputValue) @@ -859,10 +982,17 @@ func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.Col return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -879,6 +1009,9 @@ func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field gra return obj.IsDeprecated, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(bool) @@ -909,6 +1042,7 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection fields := graphql.CollectFields(ctx, sel, __InputValueImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -917,10 +1051,16 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection out.Values[i] = graphql.MarshalString("__InputValue") case "name": out.Values[i] = ec.___InputValue_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "description": out.Values[i] = ec.___InputValue_description(ctx, field, obj) case "type": out.Values[i] = ec.___InputValue_type(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "defaultValue": out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) default: @@ -928,6 +1068,9 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection } } + if invalid { + return graphql.Null + } return out } @@ -942,6 +1085,9 @@ func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphq return obj.Name, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -976,10 +1122,17 @@ func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphq return obj.Type, nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -999,6 +1152,7 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1012,6 +1166,7 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, fields := graphql.CollectFields(ctx, sel, __SchemaImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1020,19 +1175,31 @@ func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, out.Values[i] = graphql.MarshalString("__Schema") case "types": out.Values[i] = ec.___Schema_types(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "queryType": out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "mutationType": out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) case "subscriptionType": out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) case "directives": out.Values[i] = ec.___Schema_directives(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } default: panic("unknown field " + strconv.Quote(field.Name)) } } + if invalid { + return graphql.Null + } return out } @@ -1047,6 +1214,9 @@ func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.C return obj.Types(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Type) @@ -1073,10 +1243,17 @@ func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graph return obj.QueryType(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } return ec.___Type(ctx, field.Selections, res) @@ -1096,6 +1273,7 @@ func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field gr return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1116,6 +1294,7 @@ func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, fiel return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null } @@ -1133,6 +1312,9 @@ func (ec *executionContext) ___Schema_directives(ctx context.Context, field grap return obj.Directives(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.([]introspection.Directive) @@ -1155,6 +1337,7 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o fields := graphql.CollectFields(ctx, sel, __TypeImplementors) out := graphql.NewOrderedMap(len(fields)) + invalid := false for i, field := range fields { out.Keys[i] = field.Alias @@ -1163,6 +1346,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o out.Values[i] = graphql.MarshalString("__Type") case "kind": out.Values[i] = ec.___Type_kind(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalid = true + } case "name": out.Values[i] = ec.___Type_name(ctx, field, obj) case "description": @@ -1184,6 +1370,9 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o } } + if invalid { + return graphql.Null + } return out } @@ -1198,6 +1387,9 @@ func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.Coll return obj.Kind(), nil }) if resTmp == nil { + if !ec.HasError(rctx) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } res := resTmp.(string) @@ -1218,6 +1410,7 @@ func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.Coll return graphql.Null } res := resTmp.(*string) + if res == nil { return graphql.Null } @@ -1409,6 +1602,7 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co return graphql.Null } res := resTmp.(*introspection.Type) + if res == nil { return graphql.Null }