Closed MikePolen closed 2 years ago
Hey, @MikePolen! Thanks for reporting this.
This issue has a chance of being already fixed. Let us update to the latest @mswjs/interceptors
and test it out.
:tada: This issue has been resolved in version 0.38.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Hey, I'm facing this same issue in version 0.42.1
.
My problem is that I have a handler like this:
graphql.query<CurrentUserQuery>(
"currentUser",
(_req, res, ctx) => {
return res(
ctx.data({
currentUser: user,
}),
)
},
),
Where user
is a mocked object. I also have this to inspect the query.
server.events.on("response:mocked", (args) => {
console.log({ args })
})
This is what I receive from that event:
{
args: {
status: 200,
statusText: 'OK',
headers: HeadersPolyfill { headers: [Object], names: [Map] },
body: '{"data":{"currentUser":{"id":"16bgr10bw0","firstName":"Halie","lastName":"Mollie","email":"Arlo_Sipes@hotmail.com","jobFunction":"Other"}}}'
}
}
And this is what I receive as response from the query:
const res = await apolloClient.query({
query: CurrentUserDocument,
})
console.log(res.data)
{ currentUser: {} }
I'm using @apollo/client - 3.6.5
.
Fixed by using __typename
.
ctx.data({
currentUser: {
__typename: "User",
...user
},
}),
@edwinvrgs, we're mentioning the request integrity with the GraphQL client here. It may not be obvious at first but you need to compose the same response in regards to what the client expects. In the case of Apollo, all fields must have __typename
. Apollo will strip off any fields that don't. This is a behavior not specific to MSW in any way.
@edwinvrgs, we're mentioning the request integrity with the GraphQL client here. It may not be obvious at first but you need to compose the same response in regards to what the client expects. In the case of Apollo, all fields must have
__typename
. Apollo will strip off any fields that don't. This is a behavior not specific to MSW in any way.
Yeah, at the beginning I thought it was related to MSW but I was wrong. Thanks for your comment.
Environment
Request handlers
Actual request
I am using RTK Query
Current behavior
When I run the test it appears to return nothing. when I run the test using the debug package with DEBUG=* I see the following:
At the beginning I see the mock response. Then further down I see "response type blob" then "set response body Blob {}". The UI gets nothing in the data variable. It is undefined which would correspond to the api returning {}.
Expected behavior
I expect the data variable to get
Screenshots