| Name | Version |
| ------- | ------- |
| msw | 0.24.2 |
| browser | chrome Version 87.0.4280.88 (Official Build) (x86_64) |
| OS | macOS Big Sur 11.0.1 (20B29) |
export const handlers = [
graphql.operation((req, res, ctx) => {
console.log({ req, res, ctx });
return res(
ctx.data({
user: {
username: 'test',
firstName: 'John',
},
})
);
}),
graphql.query('getTest', (req, res, ctx) => {
return res(
ctx.data({
user: {
username: 'test',
firstName: 'John',
},
})
);
}),
];
https://www.apollographql.com/docs/link/links/batch-http/
Using Apollo Client to perform a normal batch query
ie.
import { BatchHttpLink } from "apollo-link-batch-http";
const link = new BatchHttpLink({ uri: "/graphql" });
batch queries are not getting intercepted but if I switch from BatchHttpLink to a regular HttpLink, the interception works as expected.
batch queries get intercepted
the only way I got graphql batch requests to be intercepted, is by using rest with the full request URL, like so:
rest.post('https://my-graphql-server/endpoint', (req, res, ctx) => {
...
}
and then I have to manually analyze the req.body[] and handle/mock the request.
meaning, I lose all the graphql declarative/functionality mswjs provides...
@antoniosZ Do you have a repro for this? I haven't tried this feature myself, but I imagine it might have to be linked? https://mswjs.io/docs/api/graphql/link#examples
@msutkowski I tried linking and that didn't help. I'll see if I can quickly create a repro
@msutkowski Unfortunately, I could not find a public graphql server to use for the repro, that supports query batching. please let me know if you have one available and then I can create the demo project that reproduces it... thank you
I'm not a graphQL user personally but I can try to take a look at this later and set up a server locally. It's possible that somebody will beat me to this but I'll try to get to it by tomorrow
Ah, the issue here is that msw doesn't currently support batch operations. BatchLink is sending over an array of operations, which isn't going to resolve. If you're able to, I'm sure @kettanaito would accept a PR if you have the time to implement this? If not, perhaps someone can jump in :)
@msutkowski this is exactly what is happening. It posts an array, instead of an object...
I wish I could say I have the time to work on it, but I doubt I will be able to get to it.
@antoniosZ can you test it out against this preview of the build? https://ci.codesandbox.io/status/mswjs/msw/pr/513/builds/83287 - or npm i https://pkg.csb.dev/mswjs/msw/commit/d19bb4e8/msw and let me know if it works as expected? thanks!
thank you @msutkowski but unfortunately, it does not work.
It appears that the problem is here:
https://github.com/mswjs/msw/pull/513/files#diff-6178a21f02701c9f8fa7ae2cc995b08165615a3afddac155fb850e355269897aR154
@antoniosZ Sorry about that, there is a little more work to do here for handling the arrays. I'll get it taken care of today :)
thank you for working on this @msutkowski! Is there a new commit that you would like me to test?
Most helpful comment
@antoniosZ Sorry about that, there is a little more work to do here for handling the arrays. I'll get it taken care of today :)