msw 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@
8
8
  * - Please do NOT serve this file on production.
9
9
  */
10
10
 
11
- const PACKAGE_VERSION = '2.4.0'
11
+ const PACKAGE_VERSION = '2.4.1'
12
12
  const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
13
13
  const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
14
14
  const activeClientIds = new Set()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "msw",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
5
5
  "main": "./lib/core/index.js",
6
6
  "module": "./lib/core/index.mjs",
@@ -180,6 +180,7 @@
180
180
  "webpack-http-server": "^0.5.0"
181
181
  },
182
182
  "peerDependencies": {
183
+ "graphql": ">= 16.8.x",
183
184
  "typescript": ">= 4.7.x"
184
185
  },
185
186
  "peerDependenciesMeta": {
@@ -3,7 +3,6 @@ import type {
3
3
  OperationDefinitionNode,
4
4
  OperationTypeNode,
5
5
  } from 'graphql'
6
- import { parse } from 'graphql'
7
6
  import type { GraphQLVariables } from '../../handlers/GraphQLHandler'
8
7
  import { toPublicUrl } from '../request/toPublicUrl'
9
8
  import { devUtils } from './devUtils'
@@ -40,7 +39,14 @@ export function parseDocumentNode(node: DocumentNode): ParsedGraphQLQuery {
40
39
  }
41
40
  }
42
41
 
43
- function parseQuery(query: string): ParsedGraphQLQuery | Error {
42
+ async function parseQuery(query: string): Promise<ParsedGraphQLQuery | Error> {
43
+ const { parse } = await import('graphql').catch((error) => {
44
+ devUtils.error(
45
+ 'Failed to parse a GraphQL query: cannot import the "graphql" module. Please make sure you install it if you wish to intercept GraphQL requests. See the original import error below.',
46
+ )
47
+ throw error
48
+ })
49
+
44
50
  try {
45
51
  const ast = parse(query)
46
52
  return parseDocumentNode(ast)
@@ -181,7 +187,7 @@ export async function parseGraphQLRequest(
181
187
  }
182
188
 
183
189
  const { query, variables } = input
184
- const parsedResult = parseQuery(query)
190
+ const parsedResult = await parseQuery(query)
185
191
 
186
192
  if (parsedResult instanceof Error) {
187
193
  const requestPublicUrl = toPublicUrl(request.url)