Skip to content

Commit

Permalink
refactored execField some more
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Mar 24, 2017
1 parent a43ef24 commit 9dd714e
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions internal/exec/exec.go
Original file line number Diff line number Diff line change
@@ -558,63 +558,65 @@ func (e *objectExec) execSelectionSet(ctx context.Context, r *request, selSet *q
}

func (fe *normalFieldExec) execField(ctx context.Context, r *request, e *objectExec, f *query.Field, resolver reflect.Value) interface{} {
span, spanCtx := opentracing.StartSpanFromContext(ctx, fe.spanLabel)
defer span.Finish()
span.SetTag(OpenTracingTagType, fe.typeName)
span.SetTag(OpenTracingTagField, fe.field.Name)
if fe.trivial {
span.SetTag(OpenTracingTagTrivial, true)
}

var in []reflect.Value

if fe.hasContext {
in = append(in, reflect.ValueOf(spanCtx))
}

var args map[string]interface{}
var packedArgs reflect.Value
if fe.argsPacker != nil {
args := make(map[string]interface{})
args = make(map[string]interface{})
for _, arg := range f.Arguments {
args[arg.Name.Name] = arg.Value.Value
span.SetTag(OpenTracingTagArgsPrefix+arg.Name.Name, arg.Value.Value)
}
packed, err := fe.argsPacker.pack(r, args)
var err error
packedArgs, err = fe.argsPacker.pack(r, args)
if err != nil {
r.addError(errors.Errorf("%s", err))
return nil
}
in = append(in, packed)
}

do := func(applyLimiter bool) interface{} {
if applyLimiter {
r.limiter <- struct{}{}
}

var err *errors.QueryError
if ctxErr := spanCtx.Err(); ctxErr != nil {
err = errors.Errorf("%s", ctxErr)
span, spanCtx := opentracing.StartSpanFromContext(ctx, fe.spanLabel)
defer span.Finish()
span.SetTag(OpenTracingTagType, fe.typeName)
span.SetTag(OpenTracingTagField, fe.field.Name)
if fe.trivial {
span.SetTag(OpenTracingTagTrivial, true)
}
for name, value := range args {
span.SetTag(OpenTracingTagArgsPrefix+name, value)
}

var result reflect.Value
func() {
err := func() (err *errors.QueryError) {
defer func() {
if panicValue := recover(); panicValue != nil {
err = makePanicError(panicValue)
}
}()

if err != nil {
return // don't execute any more resolvers if context got cancelled
if err := spanCtx.Err(); err != nil {
return errors.Errorf("%s", err) // don't execute any more resolvers if context got cancelled
}

var in []reflect.Value
if fe.hasContext {
in = append(in, reflect.ValueOf(spanCtx))
}
if fe.argsPacker != nil {
in = append(in, packedArgs)
}
out := resolver.Method(fe.methodIndex).Call(in)
result = out[0]
if fe.hasError && !out[1].IsNil() {
resolverErr := out[1].Interface().(error)
err = errors.Errorf("%s", err)
err := errors.Errorf("%s", resolverErr)
err.ResolverError = resolverErr
return err
}
return nil
}()

if applyLimiter {

0 comments on commit 9dd714e

Please sign in to comment.