Support batch GraphQL operations
Closes #510
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit d9d5a70ab328f04c4705845d86e8d635b23ed680:
| Sandbox | Source |
|---|---|
| MSW React | Configuration |
This actually needs more work. I finally set up an environment to actually test the batch link behavior and ran into issues. Will update later on :)
@msutkowski 👋
I've done some work on this (branched from an earlier version as we need to support older TS versions) as we needed the functionality ASAP.
Hopefully it's of help - we'd much rather to be able to use and support original package!
/cc @kettanaito
Thank you for providing that implementation reference, @dkhuntrods!
With the recent changes to the request handlers, this pull request needs a little adjustment. I've tried to structure the steps that a request handler performs, so the new logic we add will fall under one of the steps (most likely a parsing phase). I'd be happy to give a hand in aligning these changes with the latest state of the repository.
A huge thank you, @msutkowski, for preparing this. Let me know if you need help with rebasing this branch.
Hey, @msutkowski. During our discussion, I've mentioned a utility that can differentiate between REST and GraphQL requests. Here it is:
https://github.com/mswjs/msw/blob/655c93f83b7fcebe9a9093cacd7d891939028d29/src/utils/internal/parseGraphQLRequest.ts#L139-L172
We are already using it in the GraphQL request handler during the parsing phase:
https://github.com/mswjs/msw/blob/655c93f83b7fcebe9a9093cacd7d891939028d29/src/handlers/GraphQLHandler.ts#L107-L109
That parsing result is later taken into account in the predicate step that decides whether a request should be treated as a GraphQL request and be handled by the respective handler:
https://github.com/mswjs/msw/blob/655c93f83b7fcebe9a9093cacd7d891939028d29/src/handlers/GraphQLHandler.ts#L121-L124
It seems that no extra logic should be necessary as a part of the batched GraphQL queries support. As always, I may be wriong. Would appreciate your expertise on this. Thank you.
@msutkowski, hey 👋 Quite a bunch of things has changed around request handlers since this improvement was opened. I think you are right to consider opening a new pull request, it'll be less hassle than trying to migrate the current state.
Thank you so much for working on this one!
Hi all, by the state of this branch can I assume msw currently does not support batch requests?
Released: v2.1.3 🎉
This has been released in v2.1.3!
Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.
Predictable release automation by @ossjs/release.