From d6b1132a13a1083dba69bcc4f19b4b1771baada1 Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Thu, 14 Jan 2021 03:45:18 +0700 Subject: [PATCH 1/2] fix(gatsby): fix broken GraphQL resolvers tracing --- packages/gatsby/src/schema/resolvers.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/gatsby/src/schema/resolvers.ts b/packages/gatsby/src/schema/resolvers.ts index 1b4014cc8a774..e8b4845f88b67 100644 --- a/packages/gatsby/src/schema/resolvers.ts +++ b/packages/gatsby/src/schema/resolvers.ts @@ -566,13 +566,17 @@ export function wrappingResolver( ) activity.start() } - try { - return resolver(parent, args, context, info) - } finally { + const result = resolver(parent, args, context, info) + + const endActivity = (): void => { if (activity) { activity.end() } } + if (typeof result?.then === `function` && activity) { + result.then(endActivity, endActivity) + } + return result } } From f0235d5f02b8d4650d90a62c8ca5795d4657b2e2 Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Thu, 14 Jan 2021 19:10:12 +0700 Subject: [PATCH 2/2] end activity for sync resolvers --- packages/gatsby/src/schema/resolvers.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/src/schema/resolvers.ts b/packages/gatsby/src/schema/resolvers.ts index e8b4845f88b67..50da84518597f 100644 --- a/packages/gatsby/src/schema/resolvers.ts +++ b/packages/gatsby/src/schema/resolvers.ts @@ -568,13 +568,19 @@ export function wrappingResolver( } const result = resolver(parent, args, context, info) + if (!activity) { + return result + } + const endActivity = (): void => { if (activity) { activity.end() } } - if (typeof result?.then === `function` && activity) { + if (typeof result?.then === `function`) { result.then(endActivity, endActivity) + } else { + endActivity() } return result }