@@ -44,8 +44,7 @@ import {
4444} from '../type/definition.js' ;
4545import type { GraphQLSchema } from '../type/schema.js' ;
4646
47- import type { MinimalTracingChannel } from '../diagnostics.js' ;
48- import { resolveChannel , shouldTrace , traceMixed } from '../diagnostics.js' ;
47+ import { resolveChannel , traceMixed } from '../diagnostics.js' ;
4948
5049import { AbortedGraphQLExecutionError } from './AbortedGraphQLExecutionError.js' ;
5150import { withCancellation } from './cancellablePromise.js' ;
@@ -481,9 +480,6 @@ export class Executor<
481480 groupedFieldSet : GroupedFieldSet ,
482481 positionContext : TPositionContext | undefined ,
483482 ) : PromiseOrValue < ObjMap < unknown > > {
484- const tracingChannel = shouldTrace ( resolveChannel )
485- ? resolveChannel
486- : undefined ;
487483 return promiseReduce (
488484 groupedFieldSet ,
489485 ( results , [ responseName , fieldDetailsList ] ) => {
@@ -497,7 +493,6 @@ export class Executor<
497493 fieldDetailsList ,
498494 fieldPath ,
499495 positionContext ,
500- tracingChannel ,
501496 ) ;
502497 if ( result === undefined ) {
503498 return results ;
@@ -528,9 +523,6 @@ export class Executor<
528523 ) : PromiseOrValue < ObjMap < unknown > > {
529524 const results = Object . create ( null ) ;
530525 let containsPromise = false ;
531- const tracingChannel = shouldTrace ( resolveChannel )
532- ? resolveChannel
533- : undefined ;
534526
535527 try {
536528 for ( const [ responseName , fieldDetailsList ] of groupedFieldSet ) {
@@ -541,7 +533,6 @@ export class Executor<
541533 fieldDetailsList ,
542534 fieldPath ,
543535 positionContext ,
544- tracingChannel ,
545536 ) ;
546537
547538 if ( result !== undefined ) {
@@ -583,7 +574,6 @@ export class Executor<
583574 fieldDetailsList : FieldDetailsList ,
584575 path : Path ,
585576 positionContext : TPositionContext | undefined ,
586- tracingChannel : MinimalTracingChannel | undefined ,
587577 ) : PromiseOrValue < unknown > {
588578 const validatedExecutionArgs = this . validatedExecutionArgs ;
589579 const { schema, contextValue, variableValues, hideSuggestions } =
@@ -597,7 +587,18 @@ export class Executor<
597587 }
598588
599589 const returnType = fieldDef . type ;
600- const resolveFn = fieldDef . resolve ?? validatedExecutionArgs . fieldResolver ;
590+ let resolveFn = fieldDef . resolve ?? validatedExecutionArgs . fieldResolver ;
591+
592+ if ( resolveChannel ?. hasSubscribers ) {
593+ const channel = resolveChannel ;
594+ const originalResolveFn = resolveFn ;
595+ resolveFn = ( s , args , c , info ) =>
596+ traceMixed (
597+ channel ,
598+ this . buildResolveCtx ( args , info , fieldDef . resolve === undefined ) ,
599+ ( ) => originalResolveFn ( s , args , c , info ) ,
600+ ) ;
601+ }
601602
602603 const info = buildResolveInfo (
603604 validatedExecutionArgs ,
@@ -625,17 +626,7 @@ export class Executor<
625626 // The resolve function's optional third argument is a context value that
626627 // is provided to every resolve function within an execution. It is commonly
627628 // used to represent an authenticated user, or request-specific caches.
628- const result = tracingChannel
629- ? this . invokeResolverWithTracing (
630- tracingChannel ,
631- resolveFn ,
632- source ,
633- args ,
634- contextValue ,
635- info ,
636- fieldDef . resolve === undefined ,
637- )
638- : resolveFn ( source , args , contextValue , info ) ;
629+ const result = resolveFn ( source , args , contextValue , info ) ;
639630
640631 if ( isPromiseLike ( result ) ) {
641632 return this . completePromisedValue (
@@ -672,22 +663,6 @@ export class Executor<
672663 }
673664 }
674665
675- invokeResolverWithTracing (
676- tracingChannel : MinimalTracingChannel ,
677- resolveFn : GraphQLFieldResolver < unknown , unknown > ,
678- source : unknown ,
679- args : { readonly [ argument : string ] : unknown } ,
680- contextValue : unknown ,
681- info : GraphQLResolveInfo ,
682- isTrivialResolver : boolean ,
683- ) : PromiseOrValue < unknown > {
684- return traceMixed (
685- tracingChannel ,
686- this . buildResolveCtx ( args , info , isTrivialResolver ) ,
687- ( ) => resolveFn ( source , args , contextValue , info ) ,
688- ) ;
689- }
690-
691666 /**
692667 * Build a graphql:resolve channel context for a single field invocation.
693668 *
0 commit comments