generated.gotpl

  1// Code generated by github.com/vektah/gqlgen, DO NOT EDIT.
  2
  3package {{ .PackageName }}
  4
  5import (
  6{{- range $import := .Imports }}
  7	{{- $import.Write }}
  8{{ end }}
  9)
 10
 11// MakeExecutableSchema creates an ExecutableSchema from the Resolvers interface.
 12func MakeExecutableSchema(resolvers Resolvers) graphql.ExecutableSchema {
 13	return &executableSchema{resolvers: resolvers}
 14}
 15
 16// NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.
 17func NewExecutableSchema(resolvers ResolverRoot) graphql.ExecutableSchema {
 18	return MakeExecutableSchema(shortMapper{r: resolvers})
 19}
 20
 21type Resolvers interface {
 22{{- range $object := .Objects -}}
 23	{{ range $field := $object.Fields -}}
 24		{{ $field.ResolverDeclaration }}
 25	{{ end }}
 26{{- end }}
 27}
 28
 29type ResolverRoot interface {
 30{{- range $object := .Objects -}}
 31	{{ if $object.HasResolvers -}}
 32		{{$object.GQLType}}() {{$object.GQLType}}Resolver
 33	{{ end }}
 34{{- end }}
 35}
 36
 37{{- range $object := .Objects -}}
 38	{{ if $object.HasResolvers }}
 39		type {{$object.GQLType}}Resolver interface {
 40		{{ range $field := $object.Fields -}}
 41			{{ $field.ShortResolverDeclaration }}
 42		{{ end }}
 43		}
 44	{{- end }}
 45{{- end }}
 46
 47type shortMapper struct {
 48	r ResolverRoot
 49}
 50
 51{{- range $object := .Objects -}}
 52	{{ range $field := $object.Fields -}}
 53		{{- if $field.IsResolver }}
 54			func (s shortMapper) {{ $field.ResolverDeclaration }} {
 55				return s.r.{{$field.ShortInvocation}}
 56			}
 57		{{- end }}
 58	{{ end }}
 59{{- end }}
 60
 61type executableSchema struct {
 62	resolvers      Resolvers
 63}
 64
 65func (e *executableSchema) Schema() *schema.Schema {
 66	return parsedSchema
 67}
 68
 69func (e *executableSchema) Query(ctx context.Context, op *query.Operation) *graphql.Response {
 70	{{- if .QueryRoot }}
 71		ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers}
 72
 73		buf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {
 74			data := ec._{{.QueryRoot.GQLType}}(ctx, op.Selections)
 75			var buf bytes.Buffer
 76			data.MarshalGQL(&buf)
 77			return buf.Bytes()
 78		})
 79
 80		return &graphql.Response{
 81			Data:   buf,
 82			Errors: ec.Errors,
 83		}
 84	{{- else }}
 85		return graphql.ErrorResponse(ctx, "queries are not supported")
 86	{{- end }}
 87}
 88
 89func (e *executableSchema) Mutation(ctx context.Context, op *query.Operation) *graphql.Response {
 90	{{- if .MutationRoot }}
 91		ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers}
 92
 93		buf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {
 94			data := ec._{{.MutationRoot.GQLType}}(ctx, op.Selections)
 95			var buf bytes.Buffer
 96			data.MarshalGQL(&buf)
 97			return buf.Bytes()
 98		})
 99
100		return &graphql.Response{
101			Data:   buf,
102			Errors: ec.Errors,
103		}
104	{{- else }}
105		return graphql.ErrorResponse(ctx, "mutations are not supported")
106	{{- end }}
107}
108
109func (e *executableSchema) Subscription(ctx context.Context, op *query.Operation) func() *graphql.Response {
110	{{- if .SubscriptionRoot }}
111		ec := executionContext{graphql.GetRequestContext(ctx), e.resolvers}
112
113		next := ec._{{.SubscriptionRoot.GQLType}}(ctx, op.Selections)
114		if ec.Errors != nil {
115			return graphql.OneShot(&graphql.Response{Data: []byte("null"), Errors: ec.Errors})
116		}
117
118		var buf bytes.Buffer
119		return func() *graphql.Response {
120			buf := ec.RequestMiddleware(ctx, func(ctx context.Context) []byte {
121				buf.Reset()
122				data := next()
123
124				if data == nil {
125					return nil
126				}
127				data.MarshalGQL(&buf)
128				return buf.Bytes()
129			})
130
131			return &graphql.Response{
132				Data:   buf,
133				Errors: ec.Errors,
134			}
135		}
136	{{- else }}
137		return graphql.OneShot(graphql.ErrorResponse(ctx, "subscriptions are not supported"))
138	{{- end }}
139}
140
141type executionContext struct {
142	*graphql.RequestContext
143
144	resolvers Resolvers
145}
146
147{{- range $object := .Objects }}
148	{{ template "object.gotpl" $object }}
149
150	{{- range $field := $object.Fields }}
151		{{ template "field.gotpl" $field }}
152	{{ end }}
153{{- end}}
154
155{{- range $interface := .Interfaces }}
156	{{ template "interface.gotpl" $interface }}
157{{- end }}
158
159{{- range $input := .Inputs }}
160	{{ template "input.gotpl" $input }}
161{{- end }}
162
163func (ec *executionContext) introspectSchema() *introspection.Schema {
164	return introspection.WrapSchema(parsedSchema)
165}
166
167func (ec *executionContext) introspectType(name string) *introspection.Type {
168	t := parsedSchema.Resolve(name)
169	if t == nil {
170		return nil
171	}
172	return introspection.WrapType(t)
173}
174
175var parsedSchema = schema.MustParse({{.SchemaRaw|rawQuote}})