FormidableLabs / next-urql

Convenience utilities for using urql with NextJS.
MIT License
56 stars 7 forks source link

Add support for accessing Next context to configure urql Client. #4

Closed parkerziegler closed 4 years ago

parkerziegler commented 4 years ago

Fix #3.

This PR adds support for exposing the Next context object from getInitialProps in the setup for the urql Client in withUrqlClient. If users want to, they can now access ctx directly like so:

export default withUrqlClient(ctx => {
   // You can now access ctx when creating your client options.
   return {
      url: 'http://localhost:3000',
      fetchOptions: {
         headers: {
            Authorization: ctx.token
         }
      }
   };
})(Component);

I also added a whole bunch of unit tests with enzyme for withUrqlClient to give us some assurances around how this API is working. The previous API will still work, so this change is fully backwards compatible and can be released in 0.2.0. There are some more specifics I'll call out in the PR for interested parties // reviewers.