question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Error: Headers x-msw-request-id forbidden"

See original GitHub issue

Environment

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:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ImLuzecommented, Apr 27, 2021

@kettanaito It does! It was simply a misinterpretation on my end. I have a getAlbums.graphql file which looks like this:

query getAlbums {
    albums {
        ...
    }
}

In my handler I was using graphql.query('albums') instead of graphql.query('getAlbums').

2reactions
marcosvega91commented, Apr 27, 2021

Hi @ImLuze, I’m opening a pr in your repo with the fix 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found