urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.57k stars 445 forks source link

fix(auth): Catch unexpected errors during initialization #3343

Closed kitten closed 1 year ago

kitten commented 1 year ago

See: https://github.com/vercel/next.js/issues/49373

Summary

It's unexpected and undefined behaviour to throw/reject in the initialization function passed to the authExchange() and any rejections will be uncaught. This can make thes situations hard to debug, as the promise will be uncaught.

Instead, errors during initialization will now be caught, queued up Operations will be fulfilled with an OperationResult with their error populated to the caught error, and a warning will be output in development that tells users what's going on.

This essentially allows uncaught errors in the initialization function to be discovered and handled properly. At worst, it'll fail all operations coming in and will retry the initialization function if the operations are retried.

Set of changes