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: improve handling of promises in defaultTypeResolver #3494

Merged
merged 1 commit into from
Aug 14, 2024

Conversation

hayes
Copy link
Contributor

@hayes hayes commented Feb 11, 2022

Currently it is possible to have unhandled promise rejections that arise from a mix of sync and async isTypeOf checks.

This should fix that issue.

@yaacovCR
Copy link
Contributor

This means that a mixture of sync/async calls becomes sync unnecessarily, as we return sync value…. Maybe catch handlers should be added to the promises so they reject silently? Is that possible?

@hayes
Copy link
Contributor Author

hayes commented Feb 11, 2022

I had considered that, but silently swallowing errors seems like a bad idea. I think it makes sense for execution to become async if any async functions are called. This should be a pretty rare case, but if these errors were swallowed silently it could become very tricky to debug.

@yaacovCR
Copy link
Contributor

Maybe there should be a side channel for logging these errors then so as they are not silent? In fact, this can be addressed currently in user space, as long as isTypeOf functions catch their errors and log them…

this differs from field or type resolvers which must never reject, but it’s not quite a problem for an isTypeOf resolver fail if another succeeds.

not 100% sure what the right answer is

@yaacovCR
Copy link
Contributor

A side channel might be useful as well in context of #2974 to report the first error to client and potentially log all errors

@yaacovCR
Copy link
Contributor

But as there currently is no side channel, I think I would approve these changes, and then refactor later

@github-actions
Copy link

The latest changes of this PR are available on NPM as
graphql@16.3.0-canary.pr.3494.25e1e8c8de6b13288ac61febf75d6f415f81a044
Note: no gurantees provided so please use your own discretion.

Also you can depend on latest version built from this PR:
npm install --save graphql@canary-pr-3494

@netlify
Copy link

netlify bot commented Sep 10, 2023

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit 3c32518
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/66b38a477eb5d200073f0f89
😎 Deploy Preview https://deploy-preview-3494--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hayes
Copy link
Contributor Author

hayes commented Sep 10, 2023

kinda forgot about this PR, but I think this change would still be good to get in

Copy link
Contributor

@yaacovCR yaacovCR left a comment

Choose a reason for hiding this comment

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

There are 2 different questions:

  1. Should there ever be unhandled promise rejections?
  2. Must all errors be reported?

There probably should never be unhandled promise rejections, but we do not necessarily need to report all errors.

src/execution/execute.ts Show resolved Hide resolved
@hayes hayes force-pushed the main branch 3 times, most recently from d8237f7 to 68a04f2 Compare September 10, 2023 15:21
@hayes
Copy link
Contributor Author

hayes commented Jul 30, 2024

Forgot about this PR, but wanted to check in and see if this can get merged

@Urigo Urigo requested a review from JoviDeCroock August 6, 2024 18:43
Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

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

This looks like the right change to me in terms of error-resilience - there is an unwanted commit in the history here though

@hayes hayes requested a review from a team as a code owner August 7, 2024 14:50
@hayes
Copy link
Contributor Author

hayes commented Aug 7, 2024

Good catch! I removed the extra commit and rebased the pr

@JoviDeCroock
Copy link
Member

@hayes is the intention of landing this in 16? Else we might need to target the 16.x.x branch.

CC @yaacovCR are you okay with the changes as they are currently lined out, wanted to follow up on your concerns.

@JoviDeCroock JoviDeCroock requested a review from yaacovCR August 7, 2024 16:11
@hayes
Copy link
Contributor Author

hayes commented Aug 7, 2024

@JoviDeCroock I don't feel strongly about which release this makes it into, for me its not urgent, it just seems like it would be good to land eventually

src/execution/execute.ts Show resolved Hide resolved
@JoviDeCroock JoviDeCroock merged commit 98b6541 into graphql:main Aug 14, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants