Skip to content

defaultTypeResolver can result in unhandled promise rejection #4375

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

Open
benjie opened this issue Apr 22, 2025 · 0 comments
Open

defaultTypeResolver can result in unhandled promise rejection #4375

benjie opened this issue Apr 22, 2025 · 0 comments

Comments

@benjie
Copy link
Member

benjie commented Apr 22, 2025

I was just looking over the source code around polymorphism and I think I found an issue here:

const isTypeOfResult = type.isTypeOf(value, contextValue, info);
if (isPromise(isTypeOfResult)) {
promisedIsTypeOfResults[i] = isTypeOfResult;
} else if (isTypeOfResult) {
return type.name;
}
}
}
if (promisedIsTypeOfResults.length) {
return Promise.all(promisedIsTypeOfResults).then((isTypeOfResults) => {
for (let i = 0; i < isTypeOfResults.length; i++) {
if (isTypeOfResults[i]) {
return possibleTypes[i].name;
}
}
});
}

Specifically: if we're looking over types A, B and C, and A yields a promise, and B returns a match, we will return B.name and the promise we added to promisedIsTypeOfResults for A will never be handled. If that promise were to reject then Node would raise an unhandled promise rejection error.

I think we can solve this by adding a line above return type.name:

       } else if (isTypeOfResult) {
+        // Ignore errors from promises already created
+        if (promisedIsTypeOfResults.length) {
+          void Promise.allSettled(promisedIsTypeOfResults);
+        }
         return type.name;
       }
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

No branches or pull requests

1 participant