-
Notifications
You must be signed in to change notification settings - Fork 311
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
feat: Allow async requestMiddleware #379
Conversation
Closes #369 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but please add tests.
Nice, I was just now reaching for this, in particular the ability to use the "set One thing I'm curious about is, what version of graphql-request actually supports middleware? The readme confusingly talks about it but the latest stable version 4.3.0—the version mentioned in the readme badge—doesn't seem to have middleware implemented. It seems that one should be using the |
Will cut a release soon |
Sure will try to orientate myself along the existing ones. Or do you have any specific guidelines for test that should be followed? |
As the header function is resolved in a sync function, adding the option to return a promise would require changing the request method substantially. As I don't know anything about the plans for |
My unsolicited/uninformed opinion: like the existing ones but wrap them in promises instead 🤷🏼♂️
That's totally fair! This middleware approach appears to enable what I want to do anyway: asynchronously fetch an authorization token to attach to the request headers. |
Currently, the test setup for middlewares tests both request and response middlewares. I just copied the request part of the other tests and added the async mock. I don't know if that is enough. Maybe after releasing the middleware feature and people find issues, it becomes more clear what needs to be covered by unit tests. |
Currently, it's not possible to pass any async data to request middlewares. For example, fetching and auth token. I think using
Promise.resolve
is the cleanest solution and shouldn't add any noticeable overhead to non async middlewares.