Skip to content

Commit

Permalink
remove automatic field stat collection to reduce time calls
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Nov 11, 2019
1 parent a77d9fc commit 631b48a
Show file tree
Hide file tree
Showing 17 changed files with 4,424 additions and 5,812 deletions.
16 changes: 7 additions & 9 deletions codegen/field.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Contex
{{- if $object.Stream }}
{{- $null = "nil" }}
{{- end }}
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 () {
fc.Stats.Completed = graphql.Now()
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = {{ $null }}
}
}()
fc := &graphql.FieldContext{
Object: {{$object.Name|quote}},
Field: field,
Args: nil,
IsMethod: {{or $field.IsMethod $field.IsResolver}},
}

ctx = graphql.WithFieldContext(ctx, fc)
{{- if $field.Args }}
rawArgs := field.ArgumentMap(ec.Variables)
Expand All @@ -29,7 +28,6 @@ func (ec *executionContext) _{{$object.Name}}_{{$field.Name}}(ctx context.Contex
}
fc.Args = args
{{- end }}
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 Down
2 changes: 0 additions & 2 deletions codegen/object.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
fields := graphql.CollectFields(ec.OperationContext, sel, {{$object.Name|lcFirst}}Implementors)
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 @@ -29,7 +28,6 @@ func (ec *executionContext) _{{$object.Name}}(ctx context.Context, sel ast.Selec
{{if $object.Root}}
ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{
Object: {{$object.Name|quote}},
Stats: graphql.FieldStats{Started: graphql.Now()},
})
{{end}}

Expand Down
Loading

0 comments on commit 631b48a

Please sign in to comment.