Skip to content

Commit

Permalink
rename ResolverContext to FieldContext
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Nov 5, 2019
1 parent 092ed95 commit 2898a62
Show file tree
Hide file tree
Showing 29 changed files with 4,076 additions and 3,956 deletions.
4 changes: 2 additions & 2 deletions codegen/directives.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func (ec *executionContext) _subscriptionMiddleware(ctx context.Context, obj *as
{{ if .Directives.LocationDirectives "FIELD" }}
func (ec *executionContext) _fieldMiddleware(ctx context.Context, obj interface{}, next graphql.Resolver) interface{} {
{{- if .Directives.LocationDirectives "FIELD" }}
rctx := graphql.GetResolverContext(ctx)
for _, d := range rctx.Field.Directives {
fc := graphql.GetFieldContext(ctx)
for _, d := range fc.Field.Directives {
switch d.Name {
{{- range $directive := .Directives.LocationDirectives "FIELD" }}
case "{{$directive.Name}}":
Expand Down
14 changes: 7 additions & 7 deletions codegen/field.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Contex
{{- if $object.Stream }}
{{- $null = "nil" }}
{{- end }}
rctx := &graphql.ResolverContext{
fc := &graphql.FieldContext{
Object: {{$object.Name|quote}},
Field: field,
Args: nil,
IsMethod: {{or $field.IsMethod $field.IsResolver}},
Stats: graphql.FieldStats{Started: graphql.Now()},
}
defer func () {
rctx.Stats.Completed = graphql.Now()
fc.Stats.Completed = graphql.Now()
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = {{ $null }}
}
}()
ctx = graphql.WithResolverContext(ctx, rctx)
ctx = graphql.WithFieldContext(ctx, fc)
{{- if $field.Args }}
rawArgs := field.ArgumentMap(ec.Variables)
args, err := ec.{{ $field.ArgsFunc }}(ctx,rawArgs)
if err != nil {
ec.Error(ctx, err)
return {{ $null }}
}
rctx.Args = args
fc.Args = args
{{- end }}
rctx.Stats.ArgumentsCompleted = graphql.Now()
fc.Stats.ArgumentsCompleted = graphql.Now()
{{- if $.Directives.LocationDirectives "FIELD" }}
resTmp := ec._fieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(rctx context.Context) (interface{}, error) {
{{ template "field" $field }}
Expand All @@ -45,7 +45,7 @@ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Contex
{{- end }}
if resTmp == nil {
{{- if $field.TypeReference.GQL.NonNull }}
if !graphql.HasFieldError(ctx, rctx) {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
{{- end }}
Expand All @@ -67,7 +67,7 @@ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Contex
}
{{- else }}
res := resTmp.({{$field.TypeReference.GO | ref}})
rctx.Result = res
fc.Result = res
return ec.{{ $field.TypeReference.MarshalFunc }}(ctx, field.Selections, res)
{{- end }}
}
Expand Down
2 changes: 1 addition & 1 deletion codegen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ func GenerateCode(data *Data) error {
Filename: data.Config.Exec.Filename,
Data: data,
RegionTags: true,
GeneratedHeader: true,
GeneratedHeader: false,
})
}
6 changes: 4 additions & 2 deletions codegen/object.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ var {{ $object.Name|lcFirst}}Implementors = {{$object.Implementors}}
{{- if .Stream }}
func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.SelectionSet) func() graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, {{$object.Name|lcFirst}}Implementors)
ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{
Object: {{$object.Name|quote}},
Stats: graphql.FieldStats{Started: graphql.Now()},
})
if len(fields) != 1 {
ec.Errorf(ctx, "must subscribe to exactly one stream")
Expand All @@ -26,8 +27,9 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.SelectionSet{{ if not $object.Root }},obj {{$object.Reference | ref }}{{ end }}) graphql.Marshaler {
fields := graphql.CollectFields(ec.OperationContext, sel, {{$object.Name|lcFirst}}Implementors)
{{if $object.Root}}
ctx = graphql.WithResolverContext(ctx, &graphql.ResolverContext{
ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{
Object: {{$object.Name|quote}},
Stats: graphql.FieldStats{Started: graphql.Now()},
})
{{end}}

Expand Down
Loading

0 comments on commit 2898a62

Please sign in to comment.