msw 2.0.13 → 2.1.0

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.
Files changed (142) hide show
  1. package/cli/index.js +11 -3
  2. package/cli/init.js +126 -73
  3. package/config/scripts/postinstall.js +8 -20
  4. package/lib/browser/index.js +111 -176
  5. package/lib/browser/index.js.map +1 -1
  6. package/lib/browser/index.mjs +111 -179
  7. package/lib/browser/index.mjs.map +1 -1
  8. package/lib/core/{GraphQLHandler-SHlRCcy4.d.ts → GraphQLHandler-LZ8jH42-.d.ts} +4 -2
  9. package/lib/core/{GraphQLHandler-zlmUDnN6.d.mts → GraphQLHandler-c0pfLv8e.d.mts} +4 -2
  10. package/lib/core/HttpResponse.d.mts +1 -1
  11. package/lib/core/HttpResponse.d.ts +1 -1
  12. package/lib/core/{RequestHandler-rBDJQrEf.d.ts → RequestHandler-SdFwV297.d.ts} +11 -4
  13. package/lib/core/{RequestHandler-vxZdj6Tw.d.mts → RequestHandler-hEwneHZE.d.mts} +11 -4
  14. package/lib/core/SetupApi.d.mts +1 -1
  15. package/lib/core/SetupApi.d.ts +1 -1
  16. package/lib/core/SetupApi.js +5 -0
  17. package/lib/core/SetupApi.js.map +1 -1
  18. package/lib/core/SetupApi.mjs +5 -0
  19. package/lib/core/SetupApi.mjs.map +1 -1
  20. package/lib/core/delay.js +24 -46
  21. package/lib/core/delay.js.map +1 -1
  22. package/lib/core/delay.mjs +24 -46
  23. package/lib/core/delay.mjs.map +1 -1
  24. package/lib/core/graphql.d.mts +11 -9
  25. package/lib/core/graphql.d.ts +11 -9
  26. package/lib/core/graphql.js +3 -19
  27. package/lib/core/graphql.js.map +1 -1
  28. package/lib/core/graphql.mjs +3 -21
  29. package/lib/core/graphql.mjs.map +1 -1
  30. package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
  31. package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
  32. package/lib/core/handlers/GraphQLHandler.js +52 -77
  33. package/lib/core/handlers/GraphQLHandler.js.map +1 -1
  34. package/lib/core/handlers/GraphQLHandler.mjs +52 -77
  35. package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
  36. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  37. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  38. package/lib/core/handlers/HttpHandler.js +29 -55
  39. package/lib/core/handlers/HttpHandler.js.map +1 -1
  40. package/lib/core/handlers/HttpHandler.mjs +29 -55
  41. package/lib/core/handlers/HttpHandler.mjs.map +1 -1
  42. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  43. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  44. package/lib/core/handlers/RequestHandler.js +79 -103
  45. package/lib/core/handlers/RequestHandler.js.map +1 -1
  46. package/lib/core/handlers/RequestHandler.mjs +79 -105
  47. package/lib/core/handlers/RequestHandler.mjs.map +1 -1
  48. package/lib/core/http.d.mts +13 -11
  49. package/lib/core/http.d.ts +13 -11
  50. package/lib/core/http.js.map +1 -1
  51. package/lib/core/http.mjs.map +1 -1
  52. package/lib/core/index.d.mts +4 -4
  53. package/lib/core/index.d.ts +4 -4
  54. package/lib/core/index.js.map +1 -1
  55. package/lib/core/index.mjs.map +1 -1
  56. package/lib/core/sharedOptions.d.mts +1 -1
  57. package/lib/core/sharedOptions.d.ts +1 -1
  58. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  59. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  60. package/lib/core/utils/HttpResponse/decorators.js +7 -24
  61. package/lib/core/utils/HttpResponse/decorators.js.map +1 -1
  62. package/lib/core/utils/HttpResponse/decorators.mjs +7 -26
  63. package/lib/core/utils/HttpResponse/decorators.mjs.map +1 -1
  64. package/lib/core/utils/getResponse.d.mts +1 -1
  65. package/lib/core/utils/getResponse.d.ts +1 -1
  66. package/lib/core/utils/getResponse.js +11 -26
  67. package/lib/core/utils/getResponse.js.map +1 -1
  68. package/lib/core/utils/getResponse.mjs +11 -26
  69. package/lib/core/utils/getResponse.mjs.map +1 -1
  70. package/lib/core/utils/handleRequest.d.mts +1 -1
  71. package/lib/core/utils/handleRequest.d.ts +1 -1
  72. package/lib/core/utils/handleRequest.js +49 -72
  73. package/lib/core/utils/handleRequest.js.map +1 -1
  74. package/lib/core/utils/handleRequest.mjs +49 -72
  75. package/lib/core/utils/handleRequest.mjs.map +1 -1
  76. package/lib/core/utils/internal/Disposable.js +3 -27
  77. package/lib/core/utils/internal/Disposable.js.map +1 -1
  78. package/lib/core/utils/internal/Disposable.mjs +3 -27
  79. package/lib/core/utils/internal/Disposable.mjs.map +1 -1
  80. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
  81. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
  82. package/lib/core/utils/internal/parseGraphQLRequest.js +72 -112
  83. package/lib/core/utils/internal/parseGraphQLRequest.js.map +1 -1
  84. package/lib/core/utils/internal/parseGraphQLRequest.mjs +72 -113
  85. package/lib/core/utils/internal/parseGraphQLRequest.mjs.map +1 -1
  86. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  87. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  88. package/lib/core/utils/internal/parseMultipartData.js +3 -4
  89. package/lib/core/utils/internal/parseMultipartData.js.map +1 -1
  90. package/lib/core/utils/internal/parseMultipartData.mjs +3 -4
  91. package/lib/core/utils/internal/parseMultipartData.mjs.map +1 -1
  92. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  93. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  94. package/lib/core/utils/internal/tryCatch.js +1 -1
  95. package/lib/core/utils/internal/tryCatch.js.map +1 -1
  96. package/lib/core/utils/internal/tryCatch.mjs +1 -1
  97. package/lib/core/utils/internal/tryCatch.mjs.map +1 -1
  98. package/lib/core/utils/logging/serializeRequest.js +9 -31
  99. package/lib/core/utils/logging/serializeRequest.js.map +1 -1
  100. package/lib/core/utils/logging/serializeRequest.mjs +9 -31
  101. package/lib/core/utils/logging/serializeRequest.mjs.map +1 -1
  102. package/lib/core/utils/logging/serializeResponse.js +11 -33
  103. package/lib/core/utils/logging/serializeResponse.js.map +1 -1
  104. package/lib/core/utils/logging/serializeResponse.mjs +11 -33
  105. package/lib/core/utils/logging/serializeResponse.mjs.map +1 -1
  106. package/lib/core/utils/request/getRequestCookies.js +9 -18
  107. package/lib/core/utils/request/getRequestCookies.js.map +1 -1
  108. package/lib/core/utils/request/getRequestCookies.mjs +9 -20
  109. package/lib/core/utils/request/getRequestCookies.mjs.map +1 -1
  110. package/lib/core/utils/request/onUnhandledRequest.d.mts +1 -1
  111. package/lib/core/utils/request/onUnhandledRequest.d.ts +1 -1
  112. package/lib/core/utils/request/onUnhandledRequest.js +62 -84
  113. package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
  114. package/lib/core/utils/request/onUnhandledRequest.mjs +62 -84
  115. package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
  116. package/lib/core/utils/request/readResponseCookies.js +1 -18
  117. package/lib/core/utils/request/readResponseCookies.js.map +1 -1
  118. package/lib/core/utils/request/readResponseCookies.mjs +1 -20
  119. package/lib/core/utils/request/readResponseCookies.mjs.map +1 -1
  120. package/lib/iife/index.js +679 -958
  121. package/lib/iife/index.js.map +1 -1
  122. package/lib/mockServiceWorker.js +2 -2
  123. package/lib/native/index.js +5 -23
  124. package/lib/native/index.js.map +1 -1
  125. package/lib/native/index.mjs +5 -24
  126. package/lib/native/index.mjs.map +1 -1
  127. package/lib/node/index.js +5 -23
  128. package/lib/node/index.js.map +1 -1
  129. package/lib/node/index.mjs +5 -24
  130. package/lib/node/index.mjs.map +1 -1
  131. package/package.json +32 -37
  132. package/src/browser/setupWorker/setupWorker.ts +6 -0
  133. package/src/browser/setupWorker/start/createStartHandler.ts +0 -8
  134. package/src/core/graphql.ts +24 -16
  135. package/src/core/handlers/GraphQLHandler.test.ts +15 -0
  136. package/src/core/handlers/GraphQLHandler.ts +8 -5
  137. package/src/core/handlers/RequestHandler.ts +37 -13
  138. package/src/core/http.ts +27 -14
  139. package/src/core/index.ts +3 -0
  140. package/src/core/utils/getResponse.ts +12 -6
  141. package/src/core/utils/handleRequest.test.ts +20 -0
  142. package/src/core/utils/handleRequest.ts +4 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/delay.ts"],"sourcesContent":["import { isNodeProcess } from 'is-node-process'\n\nexport const SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647\nexport const MIN_SERVER_RESPONSE_TIME = 100\nexport const MAX_SERVER_RESPONSE_TIME = 400\nexport const NODE_SERVER_RESPONSE_TIME = 5\n\nfunction getRealisticResponseTime(): number {\n if (isNodeProcess()) {\n return NODE_SERVER_RESPONSE_TIME\n }\n\n return Math.floor(\n Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) +\n MIN_SERVER_RESPONSE_TIME,\n )\n}\n\nexport type DelayMode = 'real' | 'infinite'\n\n/**\n * Delays the response by the given duration (ms).\n *\n * @example\n * await delay() // emulate realistic server response time\n * await delay(1200) // delay response by 1200ms\n * await delay('infinite') // delay response infinitely\n *\n * @see {@link https://mswjs.io/docs/api/delay `delay()` API reference}\n */\nexport async function delay(\n durationOrMode?: DelayMode | number,\n): Promise<void> {\n let delayTime: number\n\n if (typeof durationOrMode === 'string') {\n switch (durationOrMode) {\n case 'infinite': {\n // Using `Infinity` as a delay value executes the response timeout immediately.\n // Instead, use the maximum allowed integer for `setTimeout`.\n delayTime = SET_TIMEOUT_MAX_ALLOWED_INT\n break\n }\n case 'real': {\n delayTime = getRealisticResponseTime()\n break\n }\n default: {\n throw new Error(\n `Failed to delay a response: unknown delay mode \"${durationOrMode}\". Please make sure you provide one of the supported modes (\"real\", \"infinite\") or a number.`,\n )\n }\n }\n } else if (typeof durationOrMode === 'undefined') {\n // Use random realistic server response time when no explicit delay duration was provided.\n delayTime = getRealisticResponseTime()\n } else {\n // Guard against passing values like `Infinity` or `Number.MAX_VALUE`\n // as the response delay duration. They don't produce the result you may expect.\n if (durationOrMode > SET_TIMEOUT_MAX_ALLOWED_INT) {\n throw new Error(\n `Failed to delay a response: provided delay duration (${durationOrMode}) exceeds the maximum allowed duration for \"setTimeout\" (${SET_TIMEOUT_MAX_ALLOWED_INT}). This will cause the response to be returned immediately. Please use a number within the allowed range to delay the response by exact duration, or consider the \"infinite\" delay mode to delay the response indefinitely.`,\n )\n }\n\n delayTime = durationOrMode\n }\n\n return new Promise((resolve) => setTimeout(resolve, delayTime))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA8B;AAEvB,MAAM,8BAA8B;AACpC,MAAM,2BAA2B;AACjC,MAAM,2BAA2B;AACjC,MAAM,4BAA4B;AAEzC,SAAS,2BAAmC;AAC1C,UAAI,sCAAc,GAAG;AACnB,WAAO;AAAA,EACT;AAEA,SAAO,KAAK;AAAA,IACV,KAAK,OAAO,KAAK,2BAA2B,4BAC1C;AAAA,EACJ;AACF;AAcA,SAAsB,MACpB,gBACe;AAAA;AACf,QAAI;AAEJ,QAAI,OAAO,mBAAmB,UAAU;AACtC,cAAQ,gBAAgB;AAAA,QACtB,KAAK,YAAY;AAGf,sBAAY;AACZ;AAAA,QACF;AAAA,QACA,KAAK,QAAQ;AACX,sBAAY,yBAAyB;AACrC;AAAA,QACF;AAAA,QACA,SAAS;AACP,gBAAM,IAAI;AAAA,YACR,mDAAmD,cAAc;AAAA,UACnE;AAAA,QACF;AAAA,MACF;AAAA,IACF,WAAW,OAAO,mBAAmB,aAAa;AAEhD,kBAAY,yBAAyB;AAAA,IACvC,OAAO;AAGL,UAAI,iBAAiB,6BAA6B;AAChD,cAAM,IAAI;AAAA,UACR,wDAAwD,cAAc,4DAA4D,2BAA2B;AAAA,QAC/J;AAAA,MACF;AAEA,kBAAY;AAAA,IACd;AAEA,WAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,SAAS,CAAC;AAAA,EAChE;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/core/delay.ts"],"sourcesContent":["import { isNodeProcess } from 'is-node-process'\n\nexport const SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647\nexport const MIN_SERVER_RESPONSE_TIME = 100\nexport const MAX_SERVER_RESPONSE_TIME = 400\nexport const NODE_SERVER_RESPONSE_TIME = 5\n\nfunction getRealisticResponseTime(): number {\n if (isNodeProcess()) {\n return NODE_SERVER_RESPONSE_TIME\n }\n\n return Math.floor(\n Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) +\n MIN_SERVER_RESPONSE_TIME,\n )\n}\n\nexport type DelayMode = 'real' | 'infinite'\n\n/**\n * Delays the response by the given duration (ms).\n *\n * @example\n * await delay() // emulate realistic server response time\n * await delay(1200) // delay response by 1200ms\n * await delay('infinite') // delay response infinitely\n *\n * @see {@link https://mswjs.io/docs/api/delay `delay()` API reference}\n */\nexport async function delay(\n durationOrMode?: DelayMode | number,\n): Promise<void> {\n let delayTime: number\n\n if (typeof durationOrMode === 'string') {\n switch (durationOrMode) {\n case 'infinite': {\n // Using `Infinity` as a delay value executes the response timeout immediately.\n // Instead, use the maximum allowed integer for `setTimeout`.\n delayTime = SET_TIMEOUT_MAX_ALLOWED_INT\n break\n }\n case 'real': {\n delayTime = getRealisticResponseTime()\n break\n }\n default: {\n throw new Error(\n `Failed to delay a response: unknown delay mode \"${durationOrMode}\". Please make sure you provide one of the supported modes (\"real\", \"infinite\") or a number.`,\n )\n }\n }\n } else if (typeof durationOrMode === 'undefined') {\n // Use random realistic server response time when no explicit delay duration was provided.\n delayTime = getRealisticResponseTime()\n } else {\n // Guard against passing values like `Infinity` or `Number.MAX_VALUE`\n // as the response delay duration. They don't produce the result you may expect.\n if (durationOrMode > SET_TIMEOUT_MAX_ALLOWED_INT) {\n throw new Error(\n `Failed to delay a response: provided delay duration (${durationOrMode}) exceeds the maximum allowed duration for \"setTimeout\" (${SET_TIMEOUT_MAX_ALLOWED_INT}). This will cause the response to be returned immediately. Please use a number within the allowed range to delay the response by exact duration, or consider the \"infinite\" delay mode to delay the response indefinitely.`,\n )\n }\n\n delayTime = durationOrMode\n }\n\n return new Promise((resolve) => setTimeout(resolve, delayTime))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA8B;AAEvB,MAAM,8BAA8B;AACpC,MAAM,2BAA2B;AACjC,MAAM,2BAA2B;AACjC,MAAM,4BAA4B;AAEzC,SAAS,2BAAmC;AAC1C,UAAI,sCAAc,GAAG;AACnB,WAAO;AAAA,EACT;AAEA,SAAO,KAAK;AAAA,IACV,KAAK,OAAO,KAAK,2BAA2B,4BAC1C;AAAA,EACJ;AACF;AAcA,eAAsB,MACpB,gBACe;AACf,MAAI;AAEJ,MAAI,OAAO,mBAAmB,UAAU;AACtC,YAAQ,gBAAgB;AAAA,MACtB,KAAK,YAAY;AAGf,oBAAY;AACZ;AAAA,MACF;AAAA,MACA,KAAK,QAAQ;AACX,oBAAY,yBAAyB;AACrC;AAAA,MACF;AAAA,MACA,SAAS;AACP,cAAM,IAAI;AAAA,UACR,mDAAmD,cAAc;AAAA,QACnE;AAAA,MACF;AAAA,IACF;AAAA,EACF,WAAW,OAAO,mBAAmB,aAAa;AAEhD,gBAAY,yBAAyB;AAAA,EACvC,OAAO;AAGL,QAAI,iBAAiB,6BAA6B;AAChD,YAAM,IAAI;AAAA,QACR,wDAAwD,cAAc,4DAA4D,2BAA2B;AAAA,MAC/J;AAAA,IACF;AAEA,gBAAY;AAAA,EACd;AAEA,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,SAAS,CAAC;AAChE;","names":[]}
@@ -1,23 +1,3 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
1
  import { isNodeProcess } from "is-node-process";
22
2
  const SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647;
23
3
  const MIN_SERVER_RESPONSE_TIME = 100;
@@ -31,37 +11,35 @@ function getRealisticResponseTime() {
31
11
  Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) + MIN_SERVER_RESPONSE_TIME
32
12
  );
33
13
  }
34
- function delay(durationOrMode) {
35
- return __async(this, null, function* () {
36
- let delayTime;
37
- if (typeof durationOrMode === "string") {
38
- switch (durationOrMode) {
39
- case "infinite": {
40
- delayTime = SET_TIMEOUT_MAX_ALLOWED_INT;
41
- break;
42
- }
43
- case "real": {
44
- delayTime = getRealisticResponseTime();
45
- break;
46
- }
47
- default: {
48
- throw new Error(
49
- `Failed to delay a response: unknown delay mode "${durationOrMode}". Please make sure you provide one of the supported modes ("real", "infinite") or a number.`
50
- );
51
- }
14
+ async function delay(durationOrMode) {
15
+ let delayTime;
16
+ if (typeof durationOrMode === "string") {
17
+ switch (durationOrMode) {
18
+ case "infinite": {
19
+ delayTime = SET_TIMEOUT_MAX_ALLOWED_INT;
20
+ break;
52
21
  }
53
- } else if (typeof durationOrMode === "undefined") {
54
- delayTime = getRealisticResponseTime();
55
- } else {
56
- if (durationOrMode > SET_TIMEOUT_MAX_ALLOWED_INT) {
22
+ case "real": {
23
+ delayTime = getRealisticResponseTime();
24
+ break;
25
+ }
26
+ default: {
57
27
  throw new Error(
58
- `Failed to delay a response: provided delay duration (${durationOrMode}) exceeds the maximum allowed duration for "setTimeout" (${SET_TIMEOUT_MAX_ALLOWED_INT}). This will cause the response to be returned immediately. Please use a number within the allowed range to delay the response by exact duration, or consider the "infinite" delay mode to delay the response indefinitely.`
28
+ `Failed to delay a response: unknown delay mode "${durationOrMode}". Please make sure you provide one of the supported modes ("real", "infinite") or a number.`
59
29
  );
60
30
  }
61
- delayTime = durationOrMode;
62
31
  }
63
- return new Promise((resolve) => setTimeout(resolve, delayTime));
64
- });
32
+ } else if (typeof durationOrMode === "undefined") {
33
+ delayTime = getRealisticResponseTime();
34
+ } else {
35
+ if (durationOrMode > SET_TIMEOUT_MAX_ALLOWED_INT) {
36
+ throw new Error(
37
+ `Failed to delay a response: provided delay duration (${durationOrMode}) exceeds the maximum allowed duration for "setTimeout" (${SET_TIMEOUT_MAX_ALLOWED_INT}). This will cause the response to be returned immediately. Please use a number within the allowed range to delay the response by exact duration, or consider the "infinite" delay mode to delay the response indefinitely.`
38
+ );
39
+ }
40
+ delayTime = durationOrMode;
41
+ }
42
+ return new Promise((resolve) => setTimeout(resolve, delayTime));
65
43
  }
66
44
  export {
67
45
  MAX_SERVER_RESPONSE_TIME,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/delay.ts"],"sourcesContent":["import { isNodeProcess } from 'is-node-process'\n\nexport const SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647\nexport const MIN_SERVER_RESPONSE_TIME = 100\nexport const MAX_SERVER_RESPONSE_TIME = 400\nexport const NODE_SERVER_RESPONSE_TIME = 5\n\nfunction getRealisticResponseTime(): number {\n if (isNodeProcess()) {\n return NODE_SERVER_RESPONSE_TIME\n }\n\n return Math.floor(\n Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) +\n MIN_SERVER_RESPONSE_TIME,\n )\n}\n\nexport type DelayMode = 'real' | 'infinite'\n\n/**\n * Delays the response by the given duration (ms).\n *\n * @example\n * await delay() // emulate realistic server response time\n * await delay(1200) // delay response by 1200ms\n * await delay('infinite') // delay response infinitely\n *\n * @see {@link https://mswjs.io/docs/api/delay `delay()` API reference}\n */\nexport async function delay(\n durationOrMode?: DelayMode | number,\n): Promise<void> {\n let delayTime: number\n\n if (typeof durationOrMode === 'string') {\n switch (durationOrMode) {\n case 'infinite': {\n // Using `Infinity` as a delay value executes the response timeout immediately.\n // Instead, use the maximum allowed integer for `setTimeout`.\n delayTime = SET_TIMEOUT_MAX_ALLOWED_INT\n break\n }\n case 'real': {\n delayTime = getRealisticResponseTime()\n break\n }\n default: {\n throw new Error(\n `Failed to delay a response: unknown delay mode \"${durationOrMode}\". Please make sure you provide one of the supported modes (\"real\", \"infinite\") or a number.`,\n )\n }\n }\n } else if (typeof durationOrMode === 'undefined') {\n // Use random realistic server response time when no explicit delay duration was provided.\n delayTime = getRealisticResponseTime()\n } else {\n // Guard against passing values like `Infinity` or `Number.MAX_VALUE`\n // as the response delay duration. They don't produce the result you may expect.\n if (durationOrMode > SET_TIMEOUT_MAX_ALLOWED_INT) {\n throw new Error(\n `Failed to delay a response: provided delay duration (${durationOrMode}) exceeds the maximum allowed duration for \"setTimeout\" (${SET_TIMEOUT_MAX_ALLOWED_INT}). This will cause the response to be returned immediately. Please use a number within the allowed range to delay the response by exact duration, or consider the \"infinite\" delay mode to delay the response indefinitely.`,\n )\n }\n\n delayTime = durationOrMode\n }\n\n return new Promise((resolve) => setTimeout(resolve, delayTime))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAEvB,MAAM,8BAA8B;AACpC,MAAM,2BAA2B;AACjC,MAAM,2BAA2B;AACjC,MAAM,4BAA4B;AAEzC,SAAS,2BAAmC;AAC1C,MAAI,cAAc,GAAG;AACnB,WAAO;AAAA,EACT;AAEA,SAAO,KAAK;AAAA,IACV,KAAK,OAAO,KAAK,2BAA2B,4BAC1C;AAAA,EACJ;AACF;AAcA,SAAsB,MACpB,gBACe;AAAA;AACf,QAAI;AAEJ,QAAI,OAAO,mBAAmB,UAAU;AACtC,cAAQ,gBAAgB;AAAA,QACtB,KAAK,YAAY;AAGf,sBAAY;AACZ;AAAA,QACF;AAAA,QACA,KAAK,QAAQ;AACX,sBAAY,yBAAyB;AACrC;AAAA,QACF;AAAA,QACA,SAAS;AACP,gBAAM,IAAI;AAAA,YACR,mDAAmD,cAAc;AAAA,UACnE;AAAA,QACF;AAAA,MACF;AAAA,IACF,WAAW,OAAO,mBAAmB,aAAa;AAEhD,kBAAY,yBAAyB;AAAA,IACvC,OAAO;AAGL,UAAI,iBAAiB,6BAA6B;AAChD,cAAM,IAAI;AAAA,UACR,wDAAwD,cAAc,4DAA4D,2BAA2B;AAAA,QAC/J;AAAA,MACF;AAEA,kBAAY;AAAA,IACd;AAEA,WAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,SAAS,CAAC;AAAA,EAChE;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/core/delay.ts"],"sourcesContent":["import { isNodeProcess } from 'is-node-process'\n\nexport const SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647\nexport const MIN_SERVER_RESPONSE_TIME = 100\nexport const MAX_SERVER_RESPONSE_TIME = 400\nexport const NODE_SERVER_RESPONSE_TIME = 5\n\nfunction getRealisticResponseTime(): number {\n if (isNodeProcess()) {\n return NODE_SERVER_RESPONSE_TIME\n }\n\n return Math.floor(\n Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) +\n MIN_SERVER_RESPONSE_TIME,\n )\n}\n\nexport type DelayMode = 'real' | 'infinite'\n\n/**\n * Delays the response by the given duration (ms).\n *\n * @example\n * await delay() // emulate realistic server response time\n * await delay(1200) // delay response by 1200ms\n * await delay('infinite') // delay response infinitely\n *\n * @see {@link https://mswjs.io/docs/api/delay `delay()` API reference}\n */\nexport async function delay(\n durationOrMode?: DelayMode | number,\n): Promise<void> {\n let delayTime: number\n\n if (typeof durationOrMode === 'string') {\n switch (durationOrMode) {\n case 'infinite': {\n // Using `Infinity` as a delay value executes the response timeout immediately.\n // Instead, use the maximum allowed integer for `setTimeout`.\n delayTime = SET_TIMEOUT_MAX_ALLOWED_INT\n break\n }\n case 'real': {\n delayTime = getRealisticResponseTime()\n break\n }\n default: {\n throw new Error(\n `Failed to delay a response: unknown delay mode \"${durationOrMode}\". Please make sure you provide one of the supported modes (\"real\", \"infinite\") or a number.`,\n )\n }\n }\n } else if (typeof durationOrMode === 'undefined') {\n // Use random realistic server response time when no explicit delay duration was provided.\n delayTime = getRealisticResponseTime()\n } else {\n // Guard against passing values like `Infinity` or `Number.MAX_VALUE`\n // as the response delay duration. They don't produce the result you may expect.\n if (durationOrMode > SET_TIMEOUT_MAX_ALLOWED_INT) {\n throw new Error(\n `Failed to delay a response: provided delay duration (${durationOrMode}) exceeds the maximum allowed duration for \"setTimeout\" (${SET_TIMEOUT_MAX_ALLOWED_INT}). This will cause the response to be returned immediately. Please use a number within the allowed range to delay the response by exact duration, or consider the \"infinite\" delay mode to delay the response indefinitely.`,\n )\n }\n\n delayTime = durationOrMode\n }\n\n return new Promise((resolve) => setTimeout(resolve, delayTime))\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAEvB,MAAM,8BAA8B;AACpC,MAAM,2BAA2B;AACjC,MAAM,2BAA2B;AACjC,MAAM,4BAA4B;AAEzC,SAAS,2BAAmC;AAC1C,MAAI,cAAc,GAAG;AACnB,WAAO;AAAA,EACT;AAEA,SAAO,KAAK;AAAA,IACV,KAAK,OAAO,KAAK,2BAA2B,4BAC1C;AAAA,EACJ;AACF;AAcA,eAAsB,MACpB,gBACe;AACf,MAAI;AAEJ,MAAI,OAAO,mBAAmB,UAAU;AACtC,YAAQ,gBAAgB;AAAA,MACtB,KAAK,YAAY;AAGf,oBAAY;AACZ;AAAA,MACF;AAAA,MACA,KAAK,QAAQ;AACX,oBAAY,yBAAyB;AACrC;AAAA,MACF;AAAA,MACA,SAAS;AACP,cAAM,IAAI;AAAA,UACR,mDAAmD,cAAc;AAAA,QACnE;AAAA,MACF;AAAA,IACF;AAAA,EACF,WAAW,OAAO,mBAAmB,aAAa;AAEhD,gBAAY,yBAAyB;AAAA,EACvC,OAAO;AAGL,QAAI,iBAAiB,6BAA6B;AAChD,YAAM,IAAI;AAAA,QACR,wDAAwD,cAAc,4DAA4D,2BAA2B;AAAA,MAC/J;AAAA,IACF;AAEA,gBAAY;AAAA,EACd;AAEA,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,SAAS,CAAC;AAChE;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import { DocumentNode } from 'graphql';
2
- import { a as ResponseResolver, c as RequestHandlerOptions } from './RequestHandler-vxZdj6Tw.mjs';
3
- import { a as GraphQLVariables, d as GraphQLHandlerNameSelector, e as GraphQLResolverExtras, f as GraphQLResponseBody, G as GraphQLHandler } from './GraphQLHandler-zlmUDnN6.mjs';
2
+ import { c as RequestHandlerOptions, a as ResponseResolver } from './RequestHandler-hEwneHZE.mjs';
3
+ import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-c0pfLv8e.mjs';
4
4
  import { Path } from './utils/matching/matchRequestUrl.mjs';
5
5
  import './typeUtils.mjs';
6
6
 
@@ -13,6 +13,8 @@ interface TypedDocumentNode<Result = {
13
13
  __resultType?: Result;
14
14
  __variablesType?: Variables;
15
15
  }
16
+ type GraphQLRequestHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | DocumentNode | TypedDocumentNode<Query, Variables>, resolver: GraphQLResponseResolver<Query, Variables>, options?: RequestHandlerOptions) => GraphQLHandler;
17
+ type GraphQLResponseResolver<Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables> = ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>;
16
18
  declare const standardGraphQLHandlers: {
17
19
  /**
18
20
  * Intercepts a GraphQL query by a given name.
@@ -24,7 +26,7 @@ declare const standardGraphQLHandlers: {
24
26
  *
25
27
  * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
26
28
  */
27
- query: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
29
+ query: GraphQLRequestHandler;
28
30
  /**
29
31
  * Intercepts a GraphQL mutation by its name.
30
32
  *
@@ -36,7 +38,7 @@ declare const standardGraphQLHandlers: {
36
38
  * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
37
39
  *
38
40
  */
39
- mutation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
41
+ mutation: GraphQLRequestHandler;
40
42
  /**
41
43
  * Intercepts any GraphQL operation, regardless of its type or name.
42
44
  *
@@ -47,7 +49,7 @@ declare const standardGraphQLHandlers: {
47
49
  *
48
50
  * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
49
51
  */
50
- operation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables_1>, null, GraphQLResponseBody<Query_1>>) => GraphQLHandler;
52
+ operation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>) => GraphQLHandler;
51
53
  };
52
54
  declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
53
55
  /**
@@ -80,7 +82,7 @@ declare const graphql: {
80
82
  *
81
83
  * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
82
84
  */
83
- query: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
85
+ query: GraphQLRequestHandler;
84
86
  /**
85
87
  * Intercepts a GraphQL mutation by its name.
86
88
  *
@@ -92,7 +94,7 @@ declare const graphql: {
92
94
  * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
93
95
  *
94
96
  */
95
- mutation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
97
+ mutation: GraphQLRequestHandler;
96
98
  /**
97
99
  * Intercepts any GraphQL operation, regardless of its type or name.
98
100
  *
@@ -103,7 +105,7 @@ declare const graphql: {
103
105
  *
104
106
  * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
105
107
  */
106
- operation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables_1>, null, GraphQLResponseBody<Query_1>>) => GraphQLHandler;
108
+ operation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>) => GraphQLHandler;
107
109
  };
108
110
 
109
- export { type TypedDocumentNode, graphql };
111
+ export { type GraphQLRequestHandler, type GraphQLResponseResolver, type TypedDocumentNode, graphql };
@@ -1,6 +1,6 @@
1
1
  import { DocumentNode } from 'graphql';
2
- import { a as ResponseResolver, c as RequestHandlerOptions } from './RequestHandler-rBDJQrEf.js';
3
- import { a as GraphQLVariables, d as GraphQLHandlerNameSelector, e as GraphQLResolverExtras, f as GraphQLResponseBody, G as GraphQLHandler } from './GraphQLHandler-SHlRCcy4.js';
2
+ import { c as RequestHandlerOptions, a as ResponseResolver } from './RequestHandler-SdFwV297.js';
3
+ import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-LZ8jH42-.js';
4
4
  import { Path } from './utils/matching/matchRequestUrl.js';
5
5
  import './typeUtils.js';
6
6
 
@@ -13,6 +13,8 @@ interface TypedDocumentNode<Result = {
13
13
  __resultType?: Result;
14
14
  __variablesType?: Variables;
15
15
  }
16
+ type GraphQLRequestHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | DocumentNode | TypedDocumentNode<Query, Variables>, resolver: GraphQLResponseResolver<Query, Variables>, options?: RequestHandlerOptions) => GraphQLHandler;
17
+ type GraphQLResponseResolver<Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables> = ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>;
16
18
  declare const standardGraphQLHandlers: {
17
19
  /**
18
20
  * Intercepts a GraphQL query by a given name.
@@ -24,7 +26,7 @@ declare const standardGraphQLHandlers: {
24
26
  *
25
27
  * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
26
28
  */
27
- query: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
29
+ query: GraphQLRequestHandler;
28
30
  /**
29
31
  * Intercepts a GraphQL mutation by its name.
30
32
  *
@@ -36,7 +38,7 @@ declare const standardGraphQLHandlers: {
36
38
  * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
37
39
  *
38
40
  */
39
- mutation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
41
+ mutation: GraphQLRequestHandler;
40
42
  /**
41
43
  * Intercepts any GraphQL operation, regardless of its type or name.
42
44
  *
@@ -47,7 +49,7 @@ declare const standardGraphQLHandlers: {
47
49
  *
48
50
  * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
49
51
  */
50
- operation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables_1>, null, GraphQLResponseBody<Query_1>>) => GraphQLHandler;
52
+ operation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>) => GraphQLHandler;
51
53
  };
52
54
  declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
53
55
  /**
@@ -80,7 +82,7 @@ declare const graphql: {
80
82
  *
81
83
  * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
82
84
  */
83
- query: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
85
+ query: GraphQLRequestHandler;
84
86
  /**
85
87
  * Intercepts a GraphQL mutation by its name.
86
88
  *
@@ -92,7 +94,7 @@ declare const graphql: {
92
94
  * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
93
95
  *
94
96
  */
95
- mutation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
97
+ mutation: GraphQLRequestHandler;
96
98
  /**
97
99
  * Intercepts any GraphQL operation, regardless of its type or name.
98
100
  *
@@ -103,7 +105,7 @@ declare const graphql: {
103
105
  *
104
106
  * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
105
107
  */
106
- operation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables_1>, null, GraphQLResponseBody<Query_1>>) => GraphQLHandler;
108
+ operation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>) => GraphQLHandler;
107
109
  };
108
110
 
109
- export { type TypedDocumentNode, graphql };
111
+ export { type GraphQLRequestHandler, type GraphQLResponseResolver, type TypedDocumentNode, graphql };
@@ -1,25 +1,8 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
6
  var __export = (target, all) => {
24
7
  for (var name in all)
25
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -98,7 +81,8 @@ function createGraphQLLink(url) {
98
81
  mutation: createScopedGraphQLHandler("mutation", url)
99
82
  };
100
83
  }
101
- const graphql = __spreadProps(__spreadValues({}, standardGraphQLHandlers), {
84
+ const graphql = {
85
+ ...standardGraphQLHandlers,
102
86
  /**
103
87
  * Intercepts GraphQL operations scoped by the given URL.
104
88
  *
@@ -109,5 +93,5 @@ const graphql = __spreadProps(__spreadValues({}, standardGraphQLHandlers), {
109
93
  * @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
110
94
  */
111
95
  link: createGraphQLLink
112
- });
96
+ };
113
97
  //# sourceMappingURL=graphql.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type { DocumentNode, OperationTypeNode } from 'graphql'\nimport {\n ResponseResolver,\n RequestHandlerOptions,\n} from './handlers/RequestHandler'\nimport {\n GraphQLHandler,\n GraphQLVariables,\n ExpectedOperationTypeNode,\n GraphQLHandlerNameSelector,\n GraphQLResolverExtras,\n GraphQLResponseBody,\n} from './handlers/GraphQLHandler'\nimport type { Path } from './utils/matching/matchRequestUrl'\n\nexport interface TypedDocumentNode<\n Result = { [key: string]: any },\n Variables = { [key: string]: any },\n> extends DocumentNode {\n __apiType?: (variables: Variables) => Result\n __resultType?: Result\n __variablesType?: Variables\n}\n\nfunction createScopedGraphQLHandler(\n operationType: ExpectedOperationTypeNode,\n url: Path,\n) {\n return <\n Query extends Record<string, any>,\n Variables extends GraphQLVariables = GraphQLVariables,\n >(\n operationName:\n | GraphQLHandlerNameSelector\n | DocumentNode\n | TypedDocumentNode<Query, Variables>,\n resolver: ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<Query>\n >,\n options: RequestHandlerOptions = {},\n ) => {\n return new GraphQLHandler(\n operationType,\n operationName,\n url,\n resolver,\n options,\n )\n }\n}\n\nfunction createGraphQLOperationHandler(url: Path) {\n return <\n Query extends Record<string, any>,\n Variables extends GraphQLVariables = GraphQLVariables,\n >(\n resolver: ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<Query>\n >,\n ) => {\n return new GraphQLHandler('all', new RegExp('.*'), url, resolver)\n }\n}\n\nconst standardGraphQLHandlers = {\n /**\n * Intercepts a GraphQL query by a given name.\n *\n * @example\n * graphql.query('GetUser', () => {\n * return HttpResponse.json({ data: { user: { name: 'John' } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}\n */\n query: createScopedGraphQLHandler('query' as OperationTypeNode, '*'),\n\n /**\n * Intercepts a GraphQL mutation by its name.\n *\n * @example\n * graphql.mutation('SavePost', () => {\n * return HttpResponse.json({ data: { post: { id: 'abc-123 } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}\n *\n */\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, '*'),\n\n /**\n * Intercepts any GraphQL operation, regardless of its type or name.\n *\n * @example\n * graphql.operation(() => {\n * return HttpResponse.json({ data: { name: 'John' } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}\n */\n operation: createGraphQLOperationHandler('*'),\n}\n\nfunction createGraphQLLink(url: Path): typeof standardGraphQLHandlers {\n return {\n operation: createGraphQLOperationHandler(url),\n query: createScopedGraphQLHandler('query' as OperationTypeNode, url),\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, url),\n }\n}\n\n/**\n * A namespace to intercept and mock GraphQL operations\n *\n * @example\n * graphql.query('GetUser', resolver)\n * graphql.mutation('DeletePost', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}\n */\nexport const graphql = {\n ...standardGraphQLHandlers,\n\n /**\n * Intercepts GraphQL operations scoped by the given URL.\n *\n * @example\n * const github = graphql.link('https://api.github.com/graphql')\n * github.query('GetRepo', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}\n */\n link: createGraphQLLink,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,4BAOO;AAYP,SAAS,2BACP,eACA,KACA;AACA,SAAO,CAIL,eAIA,UAKA,UAAiC,CAAC,MAC/B;AACH,WAAO,IAAI;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,8BAA8B,KAAW;AAChD,SAAO,CAIL,aAKG;AACH,WAAO,IAAI,qCAAe,OAAO,IAAI,OAAO,IAAI,GAAG,KAAK,QAAQ;AAAA,EAClE;AACF;AAEA,MAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW9B,OAAO,2BAA2B,SAA8B,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAanE,UAAU,2BAA2B,YAAiC,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYzE,WAAW,8BAA8B,GAAG;AAC9C;AAEA,SAAS,kBAAkB,KAA2C;AACpE,SAAO;AAAA,IACL,WAAW,8BAA8B,GAAG;AAAA,IAC5C,OAAO,2BAA2B,SAA8B,GAAG;AAAA,IACnE,UAAU,2BAA2B,YAAiC,GAAG;AAAA,EAC3E;AACF;AAWO,MAAM,UAAU,iCAClB,0BADkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYrB,MAAM;AACR;","names":[]}
1
+ {"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type { DocumentNode, OperationTypeNode } from 'graphql'\nimport {\n ResponseResolver,\n RequestHandlerOptions,\n} from './handlers/RequestHandler'\nimport {\n GraphQLHandler,\n GraphQLVariables,\n ExpectedOperationTypeNode,\n GraphQLHandlerNameSelector,\n GraphQLResolverExtras,\n GraphQLResponseBody,\n GraphQLQuery,\n} from './handlers/GraphQLHandler'\nimport type { Path } from './utils/matching/matchRequestUrl'\n\nexport interface TypedDocumentNode<\n Result = { [key: string]: any },\n Variables = { [key: string]: any },\n> extends DocumentNode {\n __apiType?: (variables: Variables) => Result\n __resultType?: Result\n __variablesType?: Variables\n}\n\nexport type GraphQLRequestHandler = <\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n>(\n operationName:\n | GraphQLHandlerNameSelector\n | DocumentNode\n | TypedDocumentNode<Query, Variables>,\n resolver: GraphQLResponseResolver<Query, Variables>,\n options?: RequestHandlerOptions,\n) => GraphQLHandler\n\nexport type GraphQLResponseResolver<\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n> = ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<Query>\n>\n\nfunction createScopedGraphQLHandler(\n operationType: ExpectedOperationTypeNode,\n url: Path,\n): GraphQLRequestHandler {\n return (operationName, resolver, options = {}) => {\n return new GraphQLHandler(\n operationType,\n operationName,\n url,\n resolver,\n options,\n )\n }\n}\n\nfunction createGraphQLOperationHandler(url: Path) {\n return <\n Query extends Record<string, any>,\n Variables extends GraphQLVariables = GraphQLVariables,\n >(\n resolver: ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<Query>\n >,\n ) => {\n return new GraphQLHandler('all', new RegExp('.*'), url, resolver)\n }\n}\n\nconst standardGraphQLHandlers = {\n /**\n * Intercepts a GraphQL query by a given name.\n *\n * @example\n * graphql.query('GetUser', () => {\n * return HttpResponse.json({ data: { user: { name: 'John' } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}\n */\n query: createScopedGraphQLHandler('query' as OperationTypeNode, '*'),\n\n /**\n * Intercepts a GraphQL mutation by its name.\n *\n * @example\n * graphql.mutation('SavePost', () => {\n * return HttpResponse.json({ data: { post: { id: 'abc-123 } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}\n *\n */\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, '*'),\n\n /**\n * Intercepts any GraphQL operation, regardless of its type or name.\n *\n * @example\n * graphql.operation(() => {\n * return HttpResponse.json({ data: { name: 'John' } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}\n */\n operation: createGraphQLOperationHandler('*'),\n}\n\nfunction createGraphQLLink(url: Path): typeof standardGraphQLHandlers {\n return {\n operation: createGraphQLOperationHandler(url),\n query: createScopedGraphQLHandler('query' as OperationTypeNode, url),\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, url),\n }\n}\n\n/**\n * A namespace to intercept and mock GraphQL operations\n *\n * @example\n * graphql.query('GetUser', resolver)\n * graphql.mutation('DeletePost', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}\n */\nexport const graphql = {\n ...standardGraphQLHandlers,\n\n /**\n * Intercepts GraphQL operations scoped by the given URL.\n *\n * @example\n * const github = graphql.link('https://api.github.com/graphql')\n * github.query('GetRepo', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}\n */\n link: createGraphQLLink,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,4BAQO;AAiCP,SAAS,2BACP,eACA,KACuB;AACvB,SAAO,CAAC,eAAe,UAAU,UAAU,CAAC,MAAM;AAChD,WAAO,IAAI;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,8BAA8B,KAAW;AAChD,SAAO,CAIL,aAKG;AACH,WAAO,IAAI,qCAAe,OAAO,IAAI,OAAO,IAAI,GAAG,KAAK,QAAQ;AAAA,EAClE;AACF;AAEA,MAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW9B,OAAO,2BAA2B,SAA8B,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAanE,UAAU,2BAA2B,YAAiC,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYzE,WAAW,8BAA8B,GAAG;AAC9C;AAEA,SAAS,kBAAkB,KAA2C;AACpE,SAAO;AAAA,IACL,WAAW,8BAA8B,GAAG;AAAA,IAC5C,OAAO,2BAA2B,SAA8B,GAAG;AAAA,IACnE,UAAU,2BAA2B,YAAiC,GAAG;AAAA,EAC3E;AACF;AAWO,MAAM,UAAU;AAAA,EACrB,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWH,MAAM;AACR;","names":[]}
@@ -1,22 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
1
  import {
21
2
  GraphQLHandler
22
3
  } from './handlers/GraphQLHandler.mjs';
@@ -79,7 +60,8 @@ function createGraphQLLink(url) {
79
60
  mutation: createScopedGraphQLHandler("mutation", url)
80
61
  };
81
62
  }
82
- const graphql = __spreadProps(__spreadValues({}, standardGraphQLHandlers), {
63
+ const graphql = {
64
+ ...standardGraphQLHandlers,
83
65
  /**
84
66
  * Intercepts GraphQL operations scoped by the given URL.
85
67
  *
@@ -90,7 +72,7 @@ const graphql = __spreadProps(__spreadValues({}, standardGraphQLHandlers), {
90
72
  * @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
91
73
  */
92
74
  link: createGraphQLLink
93
- });
75
+ };
94
76
  export {
95
77
  graphql
96
78
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type { DocumentNode, OperationTypeNode } from 'graphql'\nimport {\n ResponseResolver,\n RequestHandlerOptions,\n} from './handlers/RequestHandler'\nimport {\n GraphQLHandler,\n GraphQLVariables,\n ExpectedOperationTypeNode,\n GraphQLHandlerNameSelector,\n GraphQLResolverExtras,\n GraphQLResponseBody,\n} from './handlers/GraphQLHandler'\nimport type { Path } from './utils/matching/matchRequestUrl'\n\nexport interface TypedDocumentNode<\n Result = { [key: string]: any },\n Variables = { [key: string]: any },\n> extends DocumentNode {\n __apiType?: (variables: Variables) => Result\n __resultType?: Result\n __variablesType?: Variables\n}\n\nfunction createScopedGraphQLHandler(\n operationType: ExpectedOperationTypeNode,\n url: Path,\n) {\n return <\n Query extends Record<string, any>,\n Variables extends GraphQLVariables = GraphQLVariables,\n >(\n operationName:\n | GraphQLHandlerNameSelector\n | DocumentNode\n | TypedDocumentNode<Query, Variables>,\n resolver: ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<Query>\n >,\n options: RequestHandlerOptions = {},\n ) => {\n return new GraphQLHandler(\n operationType,\n operationName,\n url,\n resolver,\n options,\n )\n }\n}\n\nfunction createGraphQLOperationHandler(url: Path) {\n return <\n Query extends Record<string, any>,\n Variables extends GraphQLVariables = GraphQLVariables,\n >(\n resolver: ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<Query>\n >,\n ) => {\n return new GraphQLHandler('all', new RegExp('.*'), url, resolver)\n }\n}\n\nconst standardGraphQLHandlers = {\n /**\n * Intercepts a GraphQL query by a given name.\n *\n * @example\n * graphql.query('GetUser', () => {\n * return HttpResponse.json({ data: { user: { name: 'John' } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}\n */\n query: createScopedGraphQLHandler('query' as OperationTypeNode, '*'),\n\n /**\n * Intercepts a GraphQL mutation by its name.\n *\n * @example\n * graphql.mutation('SavePost', () => {\n * return HttpResponse.json({ data: { post: { id: 'abc-123 } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}\n *\n */\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, '*'),\n\n /**\n * Intercepts any GraphQL operation, regardless of its type or name.\n *\n * @example\n * graphql.operation(() => {\n * return HttpResponse.json({ data: { name: 'John' } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}\n */\n operation: createGraphQLOperationHandler('*'),\n}\n\nfunction createGraphQLLink(url: Path): typeof standardGraphQLHandlers {\n return {\n operation: createGraphQLOperationHandler(url),\n query: createScopedGraphQLHandler('query' as OperationTypeNode, url),\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, url),\n }\n}\n\n/**\n * A namespace to intercept and mock GraphQL operations\n *\n * @example\n * graphql.query('GetUser', resolver)\n * graphql.mutation('DeletePost', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}\n */\nexport const graphql = {\n ...standardGraphQLHandlers,\n\n /**\n * Intercepts GraphQL operations scoped by the given URL.\n *\n * @example\n * const github = graphql.link('https://api.github.com/graphql')\n * github.query('GetRepo', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}\n */\n link: createGraphQLLink,\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAKA;AAAA,EACE;AAAA,OAMK;AAYP,SAAS,2BACP,eACA,KACA;AACA,SAAO,CAIL,eAIA,UAKA,UAAiC,CAAC,MAC/B;AACH,WAAO,IAAI;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,8BAA8B,KAAW;AAChD,SAAO,CAIL,aAKG;AACH,WAAO,IAAI,eAAe,OAAO,IAAI,OAAO,IAAI,GAAG,KAAK,QAAQ;AAAA,EAClE;AACF;AAEA,MAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW9B,OAAO,2BAA2B,SAA8B,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAanE,UAAU,2BAA2B,YAAiC,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYzE,WAAW,8BAA8B,GAAG;AAC9C;AAEA,SAAS,kBAAkB,KAA2C;AACpE,SAAO;AAAA,IACL,WAAW,8BAA8B,GAAG;AAAA,IAC5C,OAAO,2BAA2B,SAA8B,GAAG;AAAA,IACnE,UAAU,2BAA2B,YAAiC,GAAG;AAAA,EAC3E;AACF;AAWO,MAAM,UAAU,iCAClB,0BADkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYrB,MAAM;AACR;","names":[]}
1
+ {"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type { DocumentNode, OperationTypeNode } from 'graphql'\nimport {\n ResponseResolver,\n RequestHandlerOptions,\n} from './handlers/RequestHandler'\nimport {\n GraphQLHandler,\n GraphQLVariables,\n ExpectedOperationTypeNode,\n GraphQLHandlerNameSelector,\n GraphQLResolverExtras,\n GraphQLResponseBody,\n GraphQLQuery,\n} from './handlers/GraphQLHandler'\nimport type { Path } from './utils/matching/matchRequestUrl'\n\nexport interface TypedDocumentNode<\n Result = { [key: string]: any },\n Variables = { [key: string]: any },\n> extends DocumentNode {\n __apiType?: (variables: Variables) => Result\n __resultType?: Result\n __variablesType?: Variables\n}\n\nexport type GraphQLRequestHandler = <\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n>(\n operationName:\n | GraphQLHandlerNameSelector\n | DocumentNode\n | TypedDocumentNode<Query, Variables>,\n resolver: GraphQLResponseResolver<Query, Variables>,\n options?: RequestHandlerOptions,\n) => GraphQLHandler\n\nexport type GraphQLResponseResolver<\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n> = ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<Query>\n>\n\nfunction createScopedGraphQLHandler(\n operationType: ExpectedOperationTypeNode,\n url: Path,\n): GraphQLRequestHandler {\n return (operationName, resolver, options = {}) => {\n return new GraphQLHandler(\n operationType,\n operationName,\n url,\n resolver,\n options,\n )\n }\n}\n\nfunction createGraphQLOperationHandler(url: Path) {\n return <\n Query extends Record<string, any>,\n Variables extends GraphQLVariables = GraphQLVariables,\n >(\n resolver: ResponseResolver<\n GraphQLResolverExtras<Variables>,\n null,\n GraphQLResponseBody<Query>\n >,\n ) => {\n return new GraphQLHandler('all', new RegExp('.*'), url, resolver)\n }\n}\n\nconst standardGraphQLHandlers = {\n /**\n * Intercepts a GraphQL query by a given name.\n *\n * @example\n * graphql.query('GetUser', () => {\n * return HttpResponse.json({ data: { user: { name: 'John' } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}\n */\n query: createScopedGraphQLHandler('query' as OperationTypeNode, '*'),\n\n /**\n * Intercepts a GraphQL mutation by its name.\n *\n * @example\n * graphql.mutation('SavePost', () => {\n * return HttpResponse.json({ data: { post: { id: 'abc-123 } } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}\n *\n */\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, '*'),\n\n /**\n * Intercepts any GraphQL operation, regardless of its type or name.\n *\n * @example\n * graphql.operation(() => {\n * return HttpResponse.json({ data: { name: 'John' } })\n * })\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}\n */\n operation: createGraphQLOperationHandler('*'),\n}\n\nfunction createGraphQLLink(url: Path): typeof standardGraphQLHandlers {\n return {\n operation: createGraphQLOperationHandler(url),\n query: createScopedGraphQLHandler('query' as OperationTypeNode, url),\n mutation: createScopedGraphQLHandler('mutation' as OperationTypeNode, url),\n }\n}\n\n/**\n * A namespace to intercept and mock GraphQL operations\n *\n * @example\n * graphql.query('GetUser', resolver)\n * graphql.mutation('DeletePost', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}\n */\nexport const graphql = {\n ...standardGraphQLHandlers,\n\n /**\n * Intercepts GraphQL operations scoped by the given URL.\n *\n * @example\n * const github = graphql.link('https://api.github.com/graphql')\n * github.query('GetRepo', resolver)\n *\n * @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}\n */\n link: createGraphQLLink,\n}\n"],"mappings":"AAKA;AAAA,EACE;AAAA,OAOK;AAiCP,SAAS,2BACP,eACA,KACuB;AACvB,SAAO,CAAC,eAAe,UAAU,UAAU,CAAC,MAAM;AAChD,WAAO,IAAI;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,8BAA8B,KAAW;AAChD,SAAO,CAIL,aAKG;AACH,WAAO,IAAI,eAAe,OAAO,IAAI,OAAO,IAAI,GAAG,KAAK,QAAQ;AAAA,EAClE;AACF;AAEA,MAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW9B,OAAO,2BAA2B,SAA8B,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAanE,UAAU,2BAA2B,YAAiC,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYzE,WAAW,8BAA8B,GAAG;AAC9C;AAEA,SAAS,kBAAkB,KAA2C;AACpE,SAAO;AAAA,IACL,WAAW,8BAA8B,GAAG;AAAA,IAC5C,OAAO,2BAA2B,SAA8B,GAAG;AAAA,IACnE,UAAU,2BAA2B,YAAiC,GAAG;AAAA,EAC3E;AACF;AAWO,MAAM,UAAU;AAAA,EACrB,GAAG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWH,MAAM;AACR;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import 'graphql';
2
- import '../RequestHandler-vxZdj6Tw.mjs';
2
+ import '../RequestHandler-hEwneHZE.mjs';
3
3
  import '../utils/matching/matchRequestUrl.mjs';
4
- export { E as ExpectedOperationTypeNode, G as GraphQLHandler, k as GraphQLHandlerInfo, d as GraphQLHandlerNameSelector, c as GraphQLJsonRequestBody, b as GraphQLRequestBody, l as GraphQLRequestParsedResult, e as GraphQLResolverExtras, f as GraphQLResponseBody, a as GraphQLVariables, m as isDocumentNode } from '../GraphQLHandler-zlmUDnN6.mjs';
4
+ export { E as ExpectedOperationTypeNode, G as GraphQLHandler, l as GraphQLHandlerInfo, e as GraphQLHandlerNameSelector, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, m as GraphQLRequestParsedResult, f as GraphQLResolverExtras, g as GraphQLResponseBody, b as GraphQLVariables, n as isDocumentNode } from '../GraphQLHandler-c0pfLv8e.mjs';
5
5
  import '../typeUtils.mjs';
@@ -1,5 +1,5 @@
1
1
  import 'graphql';
2
- import '../RequestHandler-rBDJQrEf.js';
2
+ import '../RequestHandler-SdFwV297.js';
3
3
  import '../utils/matching/matchRequestUrl.js';
4
- export { E as ExpectedOperationTypeNode, G as GraphQLHandler, k as GraphQLHandlerInfo, d as GraphQLHandlerNameSelector, c as GraphQLJsonRequestBody, b as GraphQLRequestBody, l as GraphQLRequestParsedResult, e as GraphQLResolverExtras, f as GraphQLResponseBody, a as GraphQLVariables, m as isDocumentNode } from '../GraphQLHandler-SHlRCcy4.js';
4
+ export { E as ExpectedOperationTypeNode, G as GraphQLHandler, l as GraphQLHandlerInfo, e as GraphQLHandlerNameSelector, d as GraphQLJsonRequestBody, a as GraphQLQuery, c as GraphQLRequestBody, m as GraphQLRequestParsedResult, f as GraphQLResolverExtras, g as GraphQLResponseBody, b as GraphQLVariables, n as isDocumentNode } from '../GraphQLHandler-LZ8jH42-.js';
5
5
  import '../typeUtils.js';
@@ -16,26 +16,6 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __async = (__this, __arguments, generator) => {
20
- return new Promise((resolve, reject) => {
21
- var fulfilled = (value) => {
22
- try {
23
- step(generator.next(value));
24
- } catch (e) {
25
- reject(e);
26
- }
27
- };
28
- var rejected = (value) => {
29
- try {
30
- step(generator.throw(value));
31
- } catch (e) {
32
- reject(e);
33
- }
34
- };
35
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
- step((generator = generator.apply(__this, __arguments)).next());
37
- });
38
- };
39
19
  var GraphQLHandler_exports = {};
40
20
  __export(GraphQLHandler_exports, {
41
21
  GraphQLHandler: () => GraphQLHandler,
@@ -58,7 +38,9 @@ function isDocumentNode(value) {
58
38
  }
59
39
  return typeof value === "object" && "kind" in value && "definitions" in value;
60
40
  }
61
- const _GraphQLHandler = class _GraphQLHandler extends import_RequestHandler.RequestHandler {
41
+ class GraphQLHandler extends import_RequestHandler.RequestHandler {
42
+ endpoint;
43
+ static parsedRequestCache = /* @__PURE__ */ new WeakMap();
62
44
  constructor(operationType, operationName, endpoint, resolver, options) {
63
45
  let resolvedOperationName = operationName;
64
46
  if (isDocumentNode(operationName)) {
@@ -92,40 +74,38 @@ const _GraphQLHandler = class _GraphQLHandler extends import_RequestHandler.Requ
92
74
  * GraphQL handlers. This is done to avoid multiple parsing of the
93
75
  * request body, which each requires a clone of the request.
94
76
  */
95
- parseGraphQLRequestOrGetFromCache(request) {
96
- return __async(this, null, function* () {
97
- if (!_GraphQLHandler.parsedRequestCache.has(request)) {
98
- _GraphQLHandler.parsedRequestCache.set(
99
- request,
100
- yield (0, import_parseGraphQLRequest.parseGraphQLRequest)(request).catch((error) => {
101
- console.error(error);
102
- return void 0;
103
- })
104
- );
105
- }
106
- return _GraphQLHandler.parsedRequestCache.get(request);
107
- });
108
- }
109
- parse(args) {
110
- return __async(this, null, function* () {
111
- const match = (0, import_matchRequestUrl.matchRequestUrl)(new URL(args.request.url), this.endpoint);
112
- if (!match.matches) {
113
- return { match };
114
- }
115
- const parsedResult = yield this.parseGraphQLRequestOrGetFromCache(
116
- args.request
77
+ async parseGraphQLRequestOrGetFromCache(request) {
78
+ if (!GraphQLHandler.parsedRequestCache.has(request)) {
79
+ GraphQLHandler.parsedRequestCache.set(
80
+ request,
81
+ await (0, import_parseGraphQLRequest.parseGraphQLRequest)(request).catch((error) => {
82
+ console.error(error);
83
+ return void 0;
84
+ })
117
85
  );
118
- if (typeof parsedResult === "undefined") {
119
- return { match };
120
- }
121
- return {
122
- match,
123
- query: parsedResult.query,
124
- operationType: parsedResult.operationType,
125
- operationName: parsedResult.operationName,
126
- variables: parsedResult.variables
127
- };
128
- });
86
+ }
87
+ return GraphQLHandler.parsedRequestCache.get(request);
88
+ }
89
+ async parse(args) {
90
+ const match = (0, import_matchRequestUrl.matchRequestUrl)(new URL(args.request.url), this.endpoint);
91
+ const cookies = (0, import_getRequestCookies.getAllRequestCookies)(args.request);
92
+ if (!match.matches) {
93
+ return { match, cookies };
94
+ }
95
+ const parsedResult = await this.parseGraphQLRequestOrGetFromCache(
96
+ args.request
97
+ );
98
+ if (typeof parsedResult === "undefined") {
99
+ return { match, cookies };
100
+ }
101
+ return {
102
+ match,
103
+ cookies,
104
+ query: parsedResult.query,
105
+ operationType: parsedResult.operationType,
106
+ operationName: parsedResult.operationName,
107
+ variables: parsedResult.variables
108
+ };
129
109
  }
130
110
  predicate(args) {
131
111
  if (args.parsedResult.operationType === void 0) {
@@ -143,34 +123,29 @@ Consider naming this operation or using "graphql.operation()" request handler to
143
123
  return args.parsedResult.match.matches && hasMatchingOperationType && hasMatchingOperationName;
144
124
  }
145
125
  extendResolverArgs(args) {
146
- const cookies = (0, import_getRequestCookies.getAllRequestCookies)(args.request);
147
126
  return {
148
127
  query: args.parsedResult.query || "",
149
128
  operationName: args.parsedResult.operationName || "",
150
129
  variables: args.parsedResult.variables || {},
151
- cookies
130
+ cookies: args.parsedResult.cookies
152
131
  };
153
132
  }
154
- log(args) {
155
- return __async(this, null, function* () {
156
- const loggedRequest = yield (0, import_serializeRequest.serializeRequest)(args.request);
157
- const loggedResponse = yield (0, import_serializeResponse.serializeResponse)(args.response);
158
- const statusColor = (0, import_getStatusCodeColor.getStatusCodeColor)(loggedResponse.status);
159
- const requestInfo = args.parsedResult.operationName ? `${args.parsedResult.operationType} ${args.parsedResult.operationName}` : `anonymous ${args.parsedResult.operationType}`;
160
- console.groupCollapsed(
161
- import_devUtils.devUtils.formatMessage(
162
- `${(0, import_getTimestamp.getTimestamp)()} ${requestInfo} (%c${loggedResponse.status} ${loggedResponse.statusText}%c)`
163
- ),
164
- `color:${statusColor}`,
165
- "color:inherit"
166
- );
167
- console.log("Request:", loggedRequest);
168
- console.log("Handler:", this);
169
- console.log("Response:", loggedResponse);
170
- console.groupEnd();
171
- });
133
+ async log(args) {
134
+ const loggedRequest = await (0, import_serializeRequest.serializeRequest)(args.request);
135
+ const loggedResponse = await (0, import_serializeResponse.serializeResponse)(args.response);
136
+ const statusColor = (0, import_getStatusCodeColor.getStatusCodeColor)(loggedResponse.status);
137
+ const requestInfo = args.parsedResult.operationName ? `${args.parsedResult.operationType} ${args.parsedResult.operationName}` : `anonymous ${args.parsedResult.operationType}`;
138
+ console.groupCollapsed(
139
+ import_devUtils.devUtils.formatMessage(
140
+ `${(0, import_getTimestamp.getTimestamp)()} ${requestInfo} (%c${loggedResponse.status} ${loggedResponse.statusText}%c)`
141
+ ),
142
+ `color:${statusColor}`,
143
+ "color:inherit"
144
+ );
145
+ console.log("Request:", loggedRequest);
146
+ console.log("Handler:", this);
147
+ console.log("Response:", loggedResponse);
148
+ console.groupEnd();
172
149
  }
173
- };
174
- _GraphQLHandler.parsedRequestCache = /* @__PURE__ */ new WeakMap();
175
- let GraphQLHandler = _GraphQLHandler;
150
+ }
176
151
  //# sourceMappingURL=GraphQLHandler.js.map