Skip to content

Commit add27e4

Browse files
committed
move helpers into class
1 parent eea1a8e commit add27e4

1 file changed

Lines changed: 43 additions & 48 deletions

File tree

src/execution/Executor.ts

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ export class Executor<
626626
// is provided to every resolve function within an execution. It is commonly
627627
// used to represent an authenticated user, or request-specific caches.
628628
const result = tracingChannel
629-
? invokeResolverWithTracing(
629+
? this.invokeResolverWithTracing(
630630
tracingChannel,
631631
resolveFn,
632632
source,
@@ -672,6 +672,48 @@ export class Executor<
672672
}
673673
}
674674

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+
691+
/**
692+
* Build a graphql:resolve channel context for a single field invocation.
693+
*
694+
* `fieldPath` is exposed as a lazy getter because serializing the response
695+
* path is O(depth) and APMs that depth-filter or skip default resolvers
696+
* often never read it. `args` is passed through by reference.
697+
*/
698+
buildResolveCtx(
699+
args: ObjMap<unknown>,
700+
info: GraphQLResolveInfo,
701+
isDefaultResolver: boolean,
702+
): object {
703+
let cachedFieldPath: string | undefined;
704+
return {
705+
fieldName: info.fieldName,
706+
parentType: info.parentType.name,
707+
fieldType: String(info.returnType),
708+
args,
709+
isDefaultResolver,
710+
get fieldPath() {
711+
cachedFieldPath ??= pathToArray(info.path).join('.');
712+
return cachedFieldPath;
713+
},
714+
};
715+
}
716+
675717
handleFieldError(
676718
rawError: unknown,
677719
returnType: GraphQLOutputType,
@@ -1418,50 +1460,3 @@ export class Executor<
14181460
function toNodes(fieldDetailsList: FieldDetailsList): ReadonlyArray<FieldNode> {
14191461
return fieldDetailsList.map((fieldDetails) => fieldDetails.node);
14201462
}
1421-
1422-
/**
1423-
* Build a graphql:resolve channel context for a single field invocation.
1424-
*
1425-
* `fieldPath` is exposed as a lazy getter because serializing the response
1426-
* path is O(depth) and APMs that depth-filter or skip trivial resolvers
1427-
* often never read it. `args` is passed through by reference.
1428-
*/
1429-
function buildResolveCtx(
1430-
info: GraphQLResolveInfo,
1431-
args: { readonly [argument: string]: unknown },
1432-
isDefaultResolver: boolean,
1433-
): object {
1434-
let cachedFieldPath: string | undefined;
1435-
return {
1436-
fieldName: info.fieldName,
1437-
parentType: info.parentType.name,
1438-
fieldType: String(info.returnType),
1439-
args,
1440-
isDefaultResolver,
1441-
get fieldPath() {
1442-
cachedFieldPath ??= pathToArray(info.path).join('.');
1443-
return cachedFieldPath;
1444-
},
1445-
};
1446-
}
1447-
1448-
/**
1449-
* Traced path for a single resolver call. Extracted as a module-scope function to increase likelihood of inlining.
1450-
*
1451-
* @internal
1452-
*/
1453-
function invokeResolverWithTracing(
1454-
tracingChannel: MinimalTracingChannel,
1455-
resolveFn: GraphQLFieldResolver<unknown, unknown>,
1456-
source: unknown,
1457-
args: { readonly [argument: string]: unknown },
1458-
contextValue: unknown,
1459-
info: GraphQLResolveInfo,
1460-
isDefaultResolver: boolean,
1461-
): PromiseOrValue<unknown> {
1462-
return traceMixed(
1463-
tracingChannel,
1464-
buildResolveCtx(info, args, isDefaultResolver),
1465-
() => resolveFn(source, args, contextValue, info),
1466-
);
1467-
}

0 commit comments

Comments
 (0)