msw 2.0.14 → 2.1.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.
- package/cli/index.js +11 -3
- package/cli/init.js +126 -73
- package/config/scripts/postinstall.js +8 -20
- package/lib/browser/index.js +111 -176
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +111 -179
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-JB4bsrLF.d.ts → GraphQLHandler-2guuZL5R.d.ts} +1 -1
- package/lib/core/{GraphQLHandler-mT-MmgeB.d.mts → GraphQLHandler-fe5IYUg3.d.mts} +1 -1
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/{RequestHandler-rmY-HeFN.d.ts → RequestHandler-TRh8Eh4H.d.ts} +9 -1
- package/lib/core/{RequestHandler-YiqamK0M.d.mts → RequestHandler-nfjVJ8Tp.d.mts} +9 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/SetupApi.js +5 -0
- package/lib/core/SetupApi.js.map +1 -1
- package/lib/core/SetupApi.mjs +5 -0
- package/lib/core/SetupApi.mjs.map +1 -1
- package/lib/core/delay.js +24 -46
- package/lib/core/delay.js.map +1 -1
- package/lib/core/delay.mjs +24 -46
- package/lib/core/delay.mjs.map +1 -1
- package/lib/core/graphql.d.mts +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/graphql.js +3 -19
- package/lib/core/graphql.js.map +1 -1
- package/lib/core/graphql.mjs +3 -21
- package/lib/core/graphql.mjs.map +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.js +51 -77
- package/lib/core/handlers/GraphQLHandler.js.map +1 -1
- package/lib/core/handlers/GraphQLHandler.mjs +51 -77
- package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.js +29 -55
- package/lib/core/handlers/HttpHandler.js.map +1 -1
- package/lib/core/handlers/HttpHandler.mjs +29 -55
- package/lib/core/handlers/HttpHandler.mjs.map +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +79 -103
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +79 -105
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +2 -2
- package/lib/core/index.d.ts +2 -2
- package/lib/core/sharedOptions.d.mts +1 -1
- package/lib/core/sharedOptions.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.js +7 -24
- package/lib/core/utils/HttpResponse/decorators.js.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.mjs +7 -26
- package/lib/core/utils/HttpResponse/decorators.mjs.map +1 -1
- package/lib/core/utils/getResponse.d.mts +1 -1
- package/lib/core/utils/getResponse.d.ts +1 -1
- package/lib/core/utils/getResponse.js +11 -26
- package/lib/core/utils/getResponse.js.map +1 -1
- package/lib/core/utils/getResponse.mjs +11 -26
- package/lib/core/utils/getResponse.mjs.map +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/handleRequest.js +49 -72
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs +49 -72
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/internal/Disposable.js +3 -27
- package/lib/core/utils/internal/Disposable.js.map +1 -1
- package/lib/core/utils/internal/Disposable.mjs +3 -27
- package/lib/core/utils/internal/Disposable.mjs.map +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.js +72 -112
- package/lib/core/utils/internal/parseGraphQLRequest.js.map +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +72 -113
- package/lib/core/utils/internal/parseGraphQLRequest.mjs.map +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.js +3 -4
- package/lib/core/utils/internal/parseMultipartData.js.map +1 -1
- package/lib/core/utils/internal/parseMultipartData.mjs +3 -4
- package/lib/core/utils/internal/parseMultipartData.mjs.map +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/internal/tryCatch.js +1 -1
- package/lib/core/utils/internal/tryCatch.js.map +1 -1
- package/lib/core/utils/internal/tryCatch.mjs +1 -1
- package/lib/core/utils/internal/tryCatch.mjs.map +1 -1
- package/lib/core/utils/logging/serializeRequest.js +9 -31
- package/lib/core/utils/logging/serializeRequest.js.map +1 -1
- package/lib/core/utils/logging/serializeRequest.mjs +9 -31
- package/lib/core/utils/logging/serializeRequest.mjs.map +1 -1
- package/lib/core/utils/logging/serializeResponse.js +11 -33
- package/lib/core/utils/logging/serializeResponse.js.map +1 -1
- package/lib/core/utils/logging/serializeResponse.mjs +11 -33
- package/lib/core/utils/logging/serializeResponse.mjs.map +1 -1
- package/lib/core/utils/request/getRequestCookies.js +9 -18
- package/lib/core/utils/request/getRequestCookies.js.map +1 -1
- package/lib/core/utils/request/getRequestCookies.mjs +9 -20
- package/lib/core/utils/request/getRequestCookies.mjs.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.d.mts +1 -1
- package/lib/core/utils/request/onUnhandledRequest.d.ts +1 -1
- package/lib/core/utils/request/onUnhandledRequest.js +62 -84
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs +62 -84
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
- package/lib/core/utils/request/readResponseCookies.js +1 -18
- package/lib/core/utils/request/readResponseCookies.js.map +1 -1
- package/lib/core/utils/request/readResponseCookies.mjs +1 -20
- package/lib/core/utils/request/readResponseCookies.mjs.map +1 -1
- package/lib/iife/index.js +678 -958
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +2 -2
- package/lib/native/index.js +5 -23
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +5 -24
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js +5 -23
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +5 -24
- package/lib/node/index.mjs.map +1 -1
- package/package.json +32 -37
- package/src/browser/setupWorker/setupWorker.ts +6 -0
- package/src/browser/setupWorker/start/createStartHandler.ts +0 -8
- package/src/core/handlers/GraphQLHandler.test.ts +7 -3
- package/src/core/handlers/HttpHandler.test.ts +7 -2
- package/src/core/handlers/RequestHandler.ts +24 -4
- package/src/core/utils/getResponse.ts +12 -6
- package/src/core/utils/handleRequest.test.ts +20 -0
- package/src/core/utils/handleRequest.ts +4 -3
package/lib/core/delay.mjs
CHANGED
|
@@ -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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
22
|
+
case "real": {
|
|
23
|
+
delayTime = getRealisticResponseTime();
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
default: {
|
|
57
27
|
throw new Error(
|
|
58
|
-
`Failed to delay a response:
|
|
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
|
-
|
|
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,
|
package/lib/core/delay.mjs.map
CHANGED
|
@@ -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":"
|
|
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":[]}
|
package/lib/core/graphql.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
|
-
import { c as RequestHandlerOptions, a as ResponseResolver } from './RequestHandler-
|
|
3
|
-
import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-
|
|
2
|
+
import { c as RequestHandlerOptions, a as ResponseResolver } from './RequestHandler-nfjVJ8Tp.mjs';
|
|
3
|
+
import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-fe5IYUg3.mjs';
|
|
4
4
|
import { Path } from './utils/matching/matchRequestUrl.mjs';
|
|
5
5
|
import './typeUtils.mjs';
|
|
6
6
|
|
package/lib/core/graphql.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
|
-
import { c as RequestHandlerOptions, a as ResponseResolver } from './RequestHandler-
|
|
3
|
-
import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-
|
|
2
|
+
import { c as RequestHandlerOptions, a as ResponseResolver } from './RequestHandler-TRh8Eh4H.js';
|
|
3
|
+
import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-2guuZL5R.js';
|
|
4
4
|
import { Path } from './utils/matching/matchRequestUrl.js';
|
|
5
5
|
import './typeUtils.js';
|
|
6
6
|
|
package/lib/core/graphql.js
CHANGED
|
@@ -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 =
|
|
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
|
package/lib/core/graphql.js.map
CHANGED
|
@@ -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 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":"
|
|
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":[]}
|
package/lib/core/graphql.mjs
CHANGED
|
@@ -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 =
|
|
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
|
};
|
package/lib/core/graphql.mjs.map
CHANGED
|
@@ -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 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":"
|
|
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-
|
|
2
|
+
import '../RequestHandler-nfjVJ8Tp.mjs';
|
|
3
3
|
import '../utils/matching/matchRequestUrl.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-
|
|
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-fe5IYUg3.mjs';
|
|
5
5
|
import '../typeUtils.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
import '../RequestHandler-
|
|
2
|
+
import '../RequestHandler-TRh8Eh4H.js';
|
|
3
3
|
import '../utils/matching/matchRequestUrl.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-
|
|
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-2guuZL5R.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
|
-
|
|
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,42 +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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
const cookies = (0, import_getRequestCookies.getAllRequestCookies)(args.request);
|
|
113
|
-
if (!match.matches) {
|
|
114
|
-
return { match, cookies };
|
|
115
|
-
}
|
|
116
|
-
const parsedResult = yield this.parseGraphQLRequestOrGetFromCache(
|
|
117
|
-
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
|
+
})
|
|
118
85
|
);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
+
};
|
|
131
109
|
}
|
|
132
110
|
predicate(args) {
|
|
133
111
|
if (args.parsedResult.operationType === void 0) {
|
|
@@ -152,26 +130,22 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
152
130
|
cookies: args.parsedResult.cookies
|
|
153
131
|
};
|
|
154
132
|
}
|
|
155
|
-
log(args) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
console.groupEnd();
|
|
172
|
-
});
|
|
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();
|
|
173
149
|
}
|
|
174
|
-
}
|
|
175
|
-
_GraphQLHandler.parsedRequestCache = /* @__PURE__ */ new WeakMap();
|
|
176
|
-
let GraphQLHandler = _GraphQLHandler;
|
|
150
|
+
}
|
|
177
151
|
//# sourceMappingURL=GraphQLHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/handlers/GraphQLHandler.ts"],"sourcesContent":["import type { DocumentNode, GraphQLError, OperationTypeNode } from 'graphql'\nimport {\n DefaultBodyType,\n RequestHandler,\n RequestHandlerDefaultInfo,\n RequestHandlerOptions,\n ResponseResolver,\n} from './RequestHandler'\nimport { getTimestamp } from '../utils/logging/getTimestamp'\nimport { getStatusCodeColor } from '../utils/logging/getStatusCodeColor'\nimport { serializeRequest } from '../utils/logging/serializeRequest'\nimport { serializeResponse } from '../utils/logging/serializeResponse'\nimport { Match, matchRequestUrl, Path } from '../utils/matching/matchRequestUrl'\nimport {\n ParsedGraphQLRequest,\n GraphQLMultipartRequestBody,\n parseGraphQLRequest,\n parseDocumentNode,\n} from '../utils/internal/parseGraphQLRequest'\nimport { getPublicUrlFromRequest } from '../utils/request/getPublicUrlFromRequest'\nimport { devUtils } from '../utils/internal/devUtils'\nimport { getAllRequestCookies } from '../utils/request/getRequestCookies'\n\nexport type ExpectedOperationTypeNode = OperationTypeNode | 'all'\nexport type GraphQLHandlerNameSelector = DocumentNode | RegExp | string\n\nexport type GraphQLQuery = Record<string, any>\nexport type GraphQLVariables = Record<string, any>\n\nexport interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {\n operationType: ExpectedOperationTypeNode\n operationName: GraphQLHandlerNameSelector\n}\n\nexport type GraphQLRequestParsedResult = {\n match: Match\n cookies: Record<string, string>\n} & (\n | ParsedGraphQLRequest<GraphQLVariables>\n /**\n * An empty version of the ParsedGraphQLRequest\n * which simplifies the return type of the resolver\n * when the request is to a non-matching endpoint\n */\n | {\n operationType?: undefined\n operationName?: undefined\n query?: undefined\n variables?: undefined\n }\n)\n\nexport type GraphQLResolverExtras<Variables extends GraphQLVariables> = {\n query: string\n operationName: string\n variables: Variables\n cookies: Record<string, string>\n}\n\nexport type GraphQLRequestBody<VariablesType extends GraphQLVariables> =\n | GraphQLJsonRequestBody<VariablesType>\n | GraphQLMultipartRequestBody\n | Record<string, any>\n | undefined\n\nexport interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {\n query: string\n variables?: Variables\n}\n\nexport interface GraphQLResponseBody<BodyType extends DefaultBodyType> {\n data?: BodyType | null\n errors?: readonly Partial<GraphQLError>[] | null\n}\n\nexport function isDocumentNode(\n value: DocumentNode | any,\n): value is DocumentNode {\n if (value == null) {\n return false\n }\n\n return typeof value === 'object' && 'kind' in value && 'definitions' in value\n}\n\nexport class GraphQLHandler extends RequestHandler<\n GraphQLHandlerInfo,\n GraphQLRequestParsedResult,\n GraphQLResolverExtras<any>\n> {\n private endpoint: Path\n\n static parsedRequestCache = new WeakMap<\n Request,\n ParsedGraphQLRequest<GraphQLVariables>\n >()\n\n constructor(\n operationType: ExpectedOperationTypeNode,\n operationName: GraphQLHandlerNameSelector,\n endpoint: Path,\n resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>,\n options?: RequestHandlerOptions,\n ) {\n let resolvedOperationName = operationName\n\n if (isDocumentNode(operationName)) {\n const parsedNode = parseDocumentNode(operationName)\n\n if (parsedNode.operationType !== operationType) {\n throw new Error(\n `Failed to create a GraphQL handler: provided a DocumentNode with a mismatched operation type (expected \"${operationType}\", but got \"${parsedNode.operationType}\").`,\n )\n }\n\n if (!parsedNode.operationName) {\n throw new Error(\n `Failed to create a GraphQL handler: provided a DocumentNode with no operation name.`,\n )\n }\n\n resolvedOperationName = parsedNode.operationName\n }\n\n const header =\n operationType === 'all'\n ? `${operationType} (origin: ${endpoint.toString()})`\n : `${operationType} ${resolvedOperationName} (origin: ${endpoint.toString()})`\n\n super({\n info: {\n header,\n operationType,\n operationName: resolvedOperationName,\n },\n resolver,\n options,\n })\n\n this.endpoint = endpoint\n }\n\n /**\n * Parses the request body, once per request, cached across all\n * GraphQL handlers. This is done to avoid multiple parsing of the\n * request body, which each requires a clone of the request.\n */\n async parseGraphQLRequestOrGetFromCache(\n request: Request,\n ): Promise<ParsedGraphQLRequest<GraphQLVariables>> {\n if (!GraphQLHandler.parsedRequestCache.has(request)) {\n GraphQLHandler.parsedRequestCache.set(\n request,\n await parseGraphQLRequest(request).catch((error) => {\n console.error(error)\n return undefined\n }),\n )\n }\n\n return GraphQLHandler.parsedRequestCache.get(request)\n }\n\n async parse(args: { request: Request }): Promise<GraphQLRequestParsedResult> {\n /**\n * If the request doesn't match a specified endpoint, there's no\n * need to parse it since there's no case where we would handle this\n */\n const match = matchRequestUrl(new URL(args.request.url), this.endpoint)\n const cookies = getAllRequestCookies(args.request)\n\n if (!match.matches) {\n return { match, cookies }\n }\n\n const parsedResult = await this.parseGraphQLRequestOrGetFromCache(\n args.request,\n )\n\n if (typeof parsedResult === 'undefined') {\n return { match, cookies }\n }\n\n return {\n match,\n cookies,\n query: parsedResult.query,\n operationType: parsedResult.operationType,\n operationName: parsedResult.operationName,\n variables: parsedResult.variables,\n }\n }\n\n predicate(args: {\n request: Request\n parsedResult: GraphQLRequestParsedResult\n }) {\n if (args.parsedResult.operationType === undefined) {\n return false\n }\n\n if (!args.parsedResult.operationName && this.info.operationType !== 'all') {\n const publicUrl = getPublicUrlFromRequest(args.request)\n\n devUtils.warn(`\\\nFailed to intercept a GraphQL request at \"${args.request.method} ${publicUrl}\": anonymous GraphQL operations are not supported.\n\nConsider naming this operation or using \"graphql.operation()\" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/#graphqloperationresolver`)\n return false\n }\n\n const hasMatchingOperationType =\n this.info.operationType === 'all' ||\n args.parsedResult.operationType === this.info.operationType\n\n const hasMatchingOperationName =\n this.info.operationName instanceof RegExp\n ? this.info.operationName.test(args.parsedResult.operationName || '')\n : args.parsedResult.operationName === this.info.operationName\n\n return (\n args.parsedResult.match.matches &&\n hasMatchingOperationType &&\n hasMatchingOperationName\n )\n }\n\n protected extendResolverArgs(args: {\n request: Request\n parsedResult: GraphQLRequestParsedResult\n }) {\n return {\n query: args.parsedResult.query || '',\n operationName: args.parsedResult.operationName || '',\n variables: args.parsedResult.variables || {},\n cookies: args.parsedResult.cookies,\n }\n }\n\n async log(args: {\n request: Request\n response: Response\n parsedResult: GraphQLRequestParsedResult\n }) {\n const loggedRequest = await serializeRequest(args.request)\n const loggedResponse = await serializeResponse(args.response)\n const statusColor = getStatusCodeColor(loggedResponse.status)\n const requestInfo = args.parsedResult.operationName\n ? `${args.parsedResult.operationType} ${args.parsedResult.operationName}`\n : `anonymous ${args.parsedResult.operationType}`\n\n console.groupCollapsed(\n devUtils.formatMessage(\n `${getTimestamp()} ${requestInfo} (%c${loggedResponse.status} ${\n loggedResponse.statusText\n }%c)`,\n ),\n `color:${statusColor}`,\n 'color:inherit',\n )\n console.log('Request:', loggedRequest)\n console.log('Handler:', this)\n console.log('Response:', loggedResponse)\n console.groupEnd()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,4BAMO;AACP,0BAA6B;AAC7B,gCAAmC;AACnC,8BAAiC;AACjC,+BAAkC;AAClC,6BAA6C;AAC7C,iCAKO;AACP,qCAAwC;AACxC,sBAAyB;AACzB,+BAAqC;AAsD9B,SAAS,eACd,OACuB;AACvB,MAAI,SAAS,MAAM;AACjB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,UAAU,YAAY,UAAU,SAAS,iBAAiB;AAC1E;AAEO,MAAM,kBAAN,MAAM,wBAAuB,qCAIlC;AAAA,EAQA,YACE,eACA,eACA,UACA,UACA,SACA;AACA,QAAI,wBAAwB;AAE5B,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AAK,aAAa,aAAa;AAEhD,cAAQ;AAAA,QACN,yBAAS;AAAA,UACP,OAAG,kCAAa,CAAC,IAAI,WAAW,OAAO,eAAe,MAAM,IAC1D,eAAe,UACjB;AAAA,QACF;AAAA,QACA,SAAS,WAAW;AAAA,QACpB;AAAA,MACF;AACA,cAAQ,IAAI,YAAY,aAAa;AACrC,cAAQ,IAAI,YAAY,IAAI;AAC5B,cAAQ,IAAI,aAAa,cAAc;AACvC,cAAQ,SAAS;AAAA,IACnB;AAAA;AACF;AApLa,gBAOJ,qBAAqB,oBAAI,QAG9B;AAVG,IAAM,iBAAN;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/core/handlers/GraphQLHandler.ts"],"sourcesContent":["import type { DocumentNode, GraphQLError, OperationTypeNode } from 'graphql'\nimport {\n DefaultBodyType,\n RequestHandler,\n RequestHandlerDefaultInfo,\n RequestHandlerOptions,\n ResponseResolver,\n} from './RequestHandler'\nimport { getTimestamp } from '../utils/logging/getTimestamp'\nimport { getStatusCodeColor } from '../utils/logging/getStatusCodeColor'\nimport { serializeRequest } from '../utils/logging/serializeRequest'\nimport { serializeResponse } from '../utils/logging/serializeResponse'\nimport { Match, matchRequestUrl, Path } from '../utils/matching/matchRequestUrl'\nimport {\n ParsedGraphQLRequest,\n GraphQLMultipartRequestBody,\n parseGraphQLRequest,\n parseDocumentNode,\n} from '../utils/internal/parseGraphQLRequest'\nimport { getPublicUrlFromRequest } from '../utils/request/getPublicUrlFromRequest'\nimport { devUtils } from '../utils/internal/devUtils'\nimport { getAllRequestCookies } from '../utils/request/getRequestCookies'\n\nexport type ExpectedOperationTypeNode = OperationTypeNode | 'all'\nexport type GraphQLHandlerNameSelector = DocumentNode | RegExp | string\n\nexport type GraphQLQuery = Record<string, any>\nexport type GraphQLVariables = Record<string, any>\n\nexport interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {\n operationType: ExpectedOperationTypeNode\n operationName: GraphQLHandlerNameSelector\n}\n\nexport type GraphQLRequestParsedResult = {\n match: Match\n cookies: Record<string, string>\n} & (\n | ParsedGraphQLRequest<GraphQLVariables>\n /**\n * An empty version of the ParsedGraphQLRequest\n * which simplifies the return type of the resolver\n * when the request is to a non-matching endpoint\n */\n | {\n operationType?: undefined\n operationName?: undefined\n query?: undefined\n variables?: undefined\n }\n)\n\nexport type GraphQLResolverExtras<Variables extends GraphQLVariables> = {\n query: string\n operationName: string\n variables: Variables\n cookies: Record<string, string>\n}\n\nexport type GraphQLRequestBody<VariablesType extends GraphQLVariables> =\n | GraphQLJsonRequestBody<VariablesType>\n | GraphQLMultipartRequestBody\n | Record<string, any>\n | undefined\n\nexport interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {\n query: string\n variables?: Variables\n}\n\nexport interface GraphQLResponseBody<BodyType extends DefaultBodyType> {\n data?: BodyType | null\n errors?: readonly Partial<GraphQLError>[] | null\n}\n\nexport function isDocumentNode(\n value: DocumentNode | any,\n): value is DocumentNode {\n if (value == null) {\n return false\n }\n\n return typeof value === 'object' && 'kind' in value && 'definitions' in value\n}\n\nexport class GraphQLHandler extends RequestHandler<\n GraphQLHandlerInfo,\n GraphQLRequestParsedResult,\n GraphQLResolverExtras<any>\n> {\n private endpoint: Path\n\n static parsedRequestCache = new WeakMap<\n Request,\n ParsedGraphQLRequest<GraphQLVariables>\n >()\n\n constructor(\n operationType: ExpectedOperationTypeNode,\n operationName: GraphQLHandlerNameSelector,\n endpoint: Path,\n resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>,\n options?: RequestHandlerOptions,\n ) {\n let resolvedOperationName = operationName\n\n if (isDocumentNode(operationName)) {\n const parsedNode = parseDocumentNode(operationName)\n\n if (parsedNode.operationType !== operationType) {\n throw new Error(\n `Failed to create a GraphQL handler: provided a DocumentNode with a mismatched operation type (expected \"${operationType}\", but got \"${parsedNode.operationType}\").`,\n )\n }\n\n if (!parsedNode.operationName) {\n throw new Error(\n `Failed to create a GraphQL handler: provided a DocumentNode with no operation name.`,\n )\n }\n\n resolvedOperationName = parsedNode.operationName\n }\n\n const header =\n operationType === 'all'\n ? `${operationType} (origin: ${endpoint.toString()})`\n : `${operationType} ${resolvedOperationName} (origin: ${endpoint.toString()})`\n\n super({\n info: {\n header,\n operationType,\n operationName: resolvedOperationName,\n },\n resolver,\n options,\n })\n\n this.endpoint = endpoint\n }\n\n /**\n * Parses the request body, once per request, cached across all\n * GraphQL handlers. This is done to avoid multiple parsing of the\n * request body, which each requires a clone of the request.\n */\n async parseGraphQLRequestOrGetFromCache(\n request: Request,\n ): Promise<ParsedGraphQLRequest<GraphQLVariables>> {\n if (!GraphQLHandler.parsedRequestCache.has(request)) {\n GraphQLHandler.parsedRequestCache.set(\n request,\n await parseGraphQLRequest(request).catch((error) => {\n console.error(error)\n return undefined\n }),\n )\n }\n\n return GraphQLHandler.parsedRequestCache.get(request)\n }\n\n async parse(args: { request: Request }): Promise<GraphQLRequestParsedResult> {\n /**\n * If the request doesn't match a specified endpoint, there's no\n * need to parse it since there's no case where we would handle this\n */\n const match = matchRequestUrl(new URL(args.request.url), this.endpoint)\n const cookies = getAllRequestCookies(args.request)\n\n if (!match.matches) {\n return { match, cookies }\n }\n\n const parsedResult = await this.parseGraphQLRequestOrGetFromCache(\n args.request,\n )\n\n if (typeof parsedResult === 'undefined') {\n return { match, cookies }\n }\n\n return {\n match,\n cookies,\n query: parsedResult.query,\n operationType: parsedResult.operationType,\n operationName: parsedResult.operationName,\n variables: parsedResult.variables,\n }\n }\n\n predicate(args: {\n request: Request\n parsedResult: GraphQLRequestParsedResult\n }) {\n if (args.parsedResult.operationType === undefined) {\n return false\n }\n\n if (!args.parsedResult.operationName && this.info.operationType !== 'all') {\n const publicUrl = getPublicUrlFromRequest(args.request)\n\n devUtils.warn(`\\\nFailed to intercept a GraphQL request at \"${args.request.method} ${publicUrl}\": anonymous GraphQL operations are not supported.\n\nConsider naming this operation or using \"graphql.operation()\" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/#graphqloperationresolver`)\n return false\n }\n\n const hasMatchingOperationType =\n this.info.operationType === 'all' ||\n args.parsedResult.operationType === this.info.operationType\n\n const hasMatchingOperationName =\n this.info.operationName instanceof RegExp\n ? this.info.operationName.test(args.parsedResult.operationName || '')\n : args.parsedResult.operationName === this.info.operationName\n\n return (\n args.parsedResult.match.matches &&\n hasMatchingOperationType &&\n hasMatchingOperationName\n )\n }\n\n protected extendResolverArgs(args: {\n request: Request\n parsedResult: GraphQLRequestParsedResult\n }) {\n return {\n query: args.parsedResult.query || '',\n operationName: args.parsedResult.operationName || '',\n variables: args.parsedResult.variables || {},\n cookies: args.parsedResult.cookies,\n }\n }\n\n async log(args: {\n request: Request\n response: Response\n parsedResult: GraphQLRequestParsedResult\n }) {\n const loggedRequest = await serializeRequest(args.request)\n const loggedResponse = await serializeResponse(args.response)\n const statusColor = getStatusCodeColor(loggedResponse.status)\n const requestInfo = args.parsedResult.operationName\n ? `${args.parsedResult.operationType} ${args.parsedResult.operationName}`\n : `anonymous ${args.parsedResult.operationType}`\n\n console.groupCollapsed(\n devUtils.formatMessage(\n `${getTimestamp()} ${requestInfo} (%c${loggedResponse.status} ${\n loggedResponse.statusText\n }%c)`,\n ),\n `color:${statusColor}`,\n 'color:inherit',\n )\n console.log('Request:', loggedRequest)\n console.log('Handler:', this)\n console.log('Response:', loggedResponse)\n console.groupEnd()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,4BAMO;AACP,0BAA6B;AAC7B,gCAAmC;AACnC,8BAAiC;AACjC,+BAAkC;AAClC,6BAA6C;AAC7C,iCAKO;AACP,qCAAwC;AACxC,sBAAyB;AACzB,+BAAqC;AAsD9B,SAAS,eACd,OACuB;AACvB,MAAI,SAAS,MAAM;AACjB,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,UAAU,YAAY,UAAU,SAAS,iBAAiB;AAC1E;AAEO,MAAM,uBAAuB,qCAIlC;AAAA,EACQ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