msw: GraphQL version >=16.7.0 throws exceptions about Unexpected string

Prerequisites

Environment check

  • I’m using the latest msw version
  • I’m using Node.js version 14 or higher

Browsers

Chromium (Chrome, Brave, etc.)

Reproduction repository

CodeSandbox link

Reproduction steps

Install any kind of msw version - i have only tested versions newer than 1.0.1

  1. Go to the codesandbox repro
  2. See the page isnt rendering
  3. Open up a codesandbox terminal and make sure deps are installed and run yarn dev
  4. Open up the hosted server in a separate tab and look into the devtools
  5. Chrome will throw about Unexpected string and firefox throws about missing name after . operator

Screenshot: image

It looks like the graphql maintainers already know about this issue as there is a FIXME comment with an issue linked to it on the exact place where it breaks

Current behavior

It took me some digging. since graphql introduced some breaking changes when bumping up the minor version and msw depends on "graphql": "^15.0.0 || ^16.0.0",

Without a lock file, npm will by default install 16.7.1 as it’s peer dependency. Both graphql versions 16.7.0 and 16.7.1 will cause this problem.

If you have a lock file that points to an older version of graphql as msw’s dependency like 16.6.0 it will work just fine.

Expected behavior

MSW should lock its graphql dependency to not include the 16.7.x versions until stable

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 21 (12 by maintainers)

Most upvoted comments

I left a comment on the pnpm version mismatch that prevents me from merging this fix. Please see. Thanks.

@kettanaito should be good now

@bartektelec Just tried with resolutions option in package json and with 16.6.0 it worked!. Cannot say the same about 16.7.0 and 16.7.1 😦

@kettanaito Thanks both for help!

I opened a PR with a fix that pins the graphql dependency to last working version before the breaking change. Sadly doesn’t seem to get any attention from the maintainers

Hey @andyjessop if you take a look at previous comments I managed to narrow down the issue to only occur when using vite@<4.2.1 so if you can, try updating it.

If for some reason you are bound to a lower version of vite, you can change the package-lock file to not download graphql higher than 16.7.0

@bartektelec Just tried with resolutions option in package json and with 16.6.0 it worked!. Cannot say the same about 16.7.0 and 16.7.1 😦

@kettanaito Thanks both for help!

is your project using a bundler like vite or rollup? Could you check what version you are running?

I think I narrowed down the issue to be solved when using vite version higher or equal 4.2.1