mswjs / data

Data modeling and relation library for testing JavaScript applications.

Home Page:https://npm.im/@mswjs/data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error on Response Header Graphql

tafuri-m opened this issue · comments

I have got this error using "db.js" with factory and create to use automatic GraphQL CRUD handlers,
and setupWorker using toHandlers function in GraphQL Mode.

Using the manual Handler "graphql.query('Users'..." the problem is not present.

This is the error:

Uncaught TypeError: list.forEach is not a function
    at Object.listToHeaders (fetch-deps.js:504)
    at prepareResponse (RequestHandler-deps.js:1529)
    at GraphQLHandler.log (graphql-deps.js:3279)
    at Object.onMockedResponseSent (index.js:1520)
    at _c (index.js:1490)

Here the browser.js:

import { setupWorker } from 'msw'
import { factory, primaryKey } from '@mswjs/data';

 const db = factory({
	user: {
	  id: primaryKey(String),
	  username: String,
	  email: String,
	},
  });
  db.user.create({
    id: '1',
    username: 'Alice',
    email: 'alice@aol.com',
  })
  export const worker = setupWorker(...db.user.toHandlers('graphql', 'http://localhost:8000/api'));

Hey, @tafuri-m. Thanks for reporting this.

There appears to be an issue in serializing response headers (.listToHeaders) when printing the mocked response preview in the browser's console. I'll update you when I find the culprit.

Edit: I confirm that I can reproduce this issue in a minimal usage example.

The issue has been related to different versions of msw being installed.

Please update to @mswjs/data@0.4.2 and the issue should be gone.