msw icon indicating copy to clipboard operation
msw copied to clipboard

Support batch GraphQL operations

Open msutkowski opened this issue 5 years ago • 7 comments

Closes #510

msutkowski avatar Dec 15 '20 21:12 msutkowski

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

codesandbox-ci[bot] avatar Dec 15 '20 21:12 codesandbox-ci[bot]

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 avatar Dec 15 '20 23:12 msutkowski

@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

dkhuntrods avatar Jan 28 '21 09:01 dkhuntrods

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.

kettanaito avatar Feb 20 '21 23:02 kettanaito

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.

kettanaito avatar Mar 24 '21 10:03 kettanaito

@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!

kettanaito avatar Feb 08 '22 13:02 kettanaito

Hi all, by the state of this branch can I assume msw currently does not support batch requests?

otaciliolacerda avatar Aug 04 '22 13:08 otaciliolacerda

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.

kettanaito avatar Jan 22 '24 01:01 kettanaito