Skip to content

Commit 02a0b9c

Browse files
yaacovCRCopilot
andcommitted
sugg
Co-authored-by: Copilot <copilot@github.com>
1 parent 13ccd02 commit 02a0b9c

3 files changed

Lines changed: 47 additions & 52 deletions

File tree

integrationTests/diagnostics/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function runResolveCase() {
205205
parentType: msg.parentType,
206206
fieldType: msg.fieldType,
207207
fieldPath: msg.fieldPath,
208-
isTrivialResolver: msg.isTrivialResolver,
208+
usesDefaultResolver: msg.usesDefaultResolver,
209209
}),
210210
end: () => events.push({ kind: 'end' }),
211211
asyncStart: () => events.push({ kind: 'asyncStart' }),
@@ -228,7 +228,7 @@ function runResolveCase() {
228228
assert.equal(hello.parentType, 'Query');
229229
assert.equal(hello.fieldType, 'String');
230230
// buildSchema never attaches field.resolve; all fields report as trivial.
231-
assert.equal(hello.isTrivialResolver, true);
231+
assert.equal(hello.usesDefaultResolver, true);
232232
} finally {
233233
channel.unsubscribe(handler);
234234
}

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+
usesDefaultResolver: 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+
usesDefaultResolver,
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-
isTrivialResolver: 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-
isTrivialResolver,
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-
isTrivialResolver: boolean,
1461-
): PromiseOrValue<unknown> {
1462-
return traceMixed(
1463-
tracingChannel,
1464-
buildResolveCtx(info, args, isTrivialResolver),
1465-
() => resolveFn(source, args, contextValue, info),
1466-
);
1467-
}

src/execution/__tests__/resolve-diagnostics-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('resolve diagnostics channel', () => {
116116
);
117117
});
118118

119-
it('reports isTrivialResolver based on field.resolve presence', () => {
119+
it('reports usesDefaultResolver based on field.resolve presence', () => {
120120
const trivialSchema = new GraphQLSchema({
121121
query: new GraphQLObjectType({
122122
name: 'Query',
@@ -141,7 +141,7 @@ describe('resolve diagnostics channel', () => {
141141

142142
const starts = active.events.filter((e) => e.kind === 'start');
143143
const byField = new Map(
144-
starts.map((e) => [e.ctx.fieldName, e.ctx.isTrivialResolver]),
144+
starts.map((e) => [e.ctx.fieldName, e.ctx.usesDefaultResolver]),
145145
);
146146
expect(byField.get('trivial')).to.equal(true);
147147
expect(byField.get('custom')).to.equal(false);

0 commit comments

Comments
 (0)