"Error: Headers x-msw-request-id forbidden"
See original GitHub issueEnvironment
Name | Version |
---|---|
msw | 0.28.0 |
node | 14.16.0 |
OS | Mac OS Big Sur |
Testing against Apollo (inside a Gatsby app, if that helps) using Jest and react-testing-library.
Request handlers
import { graphql } from 'msw';
export const handlers = [
graphql.query('myThing', (req, res, ctx) => {
console.log('getting here');
console.log(req);
console.log(ctx);
return res(
ctx.data({
myThingRoot: {
edges: [],
},
})
);
}),
];
import { setupServer } from 'msw/node';
import { handlers } from './handlers';
export const server = setupServer(...handlers);
// In the Spec file itself
import React from 'react';
import { server } from '../../../../test/mocks/server';
import { render, fireEvent, waitFor, screen } from 'test-utils';
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
Actual request
const { loading, error, data } = useQuery(MY_QUERY, {
variables: {
aVar: value,
},
});
Current behavior
I can verify that the execution is reaching the mock resolver, because the console.log in the handler is printing in the Jest console output. However, the response is never sent back to the client. Instead I get the following error in the console.
at dispatchError (/Users/giantrobotbee/dev/gatsby-test/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:62:19)
at validCORSPreflightHeaders (/Users/giantrobotbee/dev/gatsby-test/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:99:5)
at Request.<anonymous> (/Users/giantrobotbee/dev/gatsby-test/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:367:12)
at Request.emit (events.js:315:20)
at Request.onRequestResponse (/Users/giantrobotbee/dev/gatsby-test/node_modules/request/request.js:1059:10)
at ClientRequestOverride.emit (events.js:315:20)
at ClientRequest.<anonymous> (/Users/giantrobotbee/dev/gatsby-test/node_modules/@mswjs/interceptors/src/interceptors/ClientRequest/createClientRequestOverride.ts:324:14)
at ClientRequest.emit (events.js:327:22)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:641:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17) undefined```
## Expected behavior
I expect the response to be sent back to the requester.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Request header field x-ms-request-root-id is not allowed by ...
I set both the projects as startup project. Not an issue. It's calling the Api method and returning the data. But some times...
Read more >CORS issue: Request header field x-msw-request-id is not ...
The issue is caused by the CORS policy of your server not accepting custom x- request headers. Due to that, the request is...
Read more >Request header field content-type is not allowed by Access ...
my project in blazor webassebly and asp.net core web api. errror : blocked by Cors Request header field content-type is not allowed by...
Read more >Error Request header field X-Requested-With is not allowed ...
I have a simple PHP script that I am attempting a cross-domain CORS request:
Read more >Request and response behavior for custom origins
The X-Forwarded-For header contains IPv4 addresses (such as 192.0.2.44) and ... the first request is identified as a Miss in the x-edge-result-type field, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kettanaito It does! It was simply a misinterpretation on my end. I have a
getAlbums.graphql
file which looks like this:In my
handler
I was usinggraphql.query('albums')
instead ofgraphql.query('getAlbums')
.Hi @ImLuze, I’m opening a pr in your repo with the fix 😃