Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): fix broken GraphQL resolver tracing #29015

Merged
merged 2 commits into from
Jan 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/gatsby/src/schema/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,17 @@ export function wrappingResolver<TSource, TArgs>(
)
activity.start()
}
try {
return resolver(parent, args, context, info)
} finally {
const result = resolver(parent, args, context, info)

const endActivity = (): void => {
if (activity) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be dropped since we test and shortcut return above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typescript disagrees.

This file has incomplete typings but if I add proper typings to activity and remove this check I get TS error: TS2339: Property 'end' does not exist on type 'void | IActivity'.   Property 'end' does not exist on type 'void'.

activity.end()
}
}
if (typeof result?.then === `function` && activity) {
result.then(endActivity, endActivity)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this won't swallow the error, I think it will suppress nodejs' builtin reporting for uncaught promises (right? because it sees the error is handled at least somewhere)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's a different promise chain than the one returned. So it is not affecting unhandled rejections. Also double-checked with this example in node:

const foo = new Promise(function (resolve, reject) {
  setTimeout(() => {
    reject(new Error("Err"));
  }, 1000);
});

const func = () => {};

foo.then(func, func);

foo.then(() => { console.log(`test`); });

}
vladar marked this conversation as resolved.
Show resolved Hide resolved
return result
}
}

Expand Down