msw 0.0.0-fetch.rc-16 → 0.0.0-fetch.rc-17
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/README.md +9 -4
- package/lib/core/handlers/GraphQLHandler.js +1 -1
- package/lib/core/handlers/GraphQLHandler.mjs +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.js +4 -3
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +4 -3
- package/lib/core/utils/request/onUnhandledRequest.js +8 -2
- package/lib/core/utils/request/onUnhandledRequest.mjs +8 -2
- package/lib/iife/index.js +31 -24
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -199,7 +199,7 @@ Mock Service Worker is trusted by hundreds of thousands of engineers around the
|
|
|
199
199
|
<a href="https://www.github.com/" target="_blank">
|
|
200
200
|
<picture>
|
|
201
201
|
<source media="(prefers-color-scheme: dark)" srcset="media/sponsors/github-light.svg" />
|
|
202
|
-
<img src="media/sponsors/github.svg" alt="GitHub"
|
|
202
|
+
<img src="media/sponsors/github.svg" alt="GitHub" height="64" />
|
|
203
203
|
</picture>
|
|
204
204
|
</a>
|
|
205
205
|
</td>
|
|
@@ -218,12 +218,12 @@ Mock Service Worker is trusted by hundreds of thousands of engineers around the
|
|
|
218
218
|
<tr>
|
|
219
219
|
<td>
|
|
220
220
|
<a href="https://www.replay.io/" target="_blank">
|
|
221
|
-
<img src="media/sponsors/replay.svg" alt="Replay"
|
|
221
|
+
<img src="media/sponsors/replay.svg" alt="Replay" height="64" />
|
|
222
222
|
</a>
|
|
223
223
|
</td>
|
|
224
224
|
<td>
|
|
225
225
|
<a href="https://www.chromatic.com/" target="_blank">
|
|
226
|
-
<img src="media/sponsors/chromatic.svg" alt="Chromatic"
|
|
226
|
+
<img src="media/sponsors/chromatic.svg" alt="Chromatic" height="64" />
|
|
227
227
|
</a>
|
|
228
228
|
</td>
|
|
229
229
|
</tr>
|
|
@@ -241,7 +241,12 @@ Mock Service Worker is trusted by hundreds of thousands of engineers around the
|
|
|
241
241
|
<tr>
|
|
242
242
|
<td>
|
|
243
243
|
<a href="https://materialize.com/" target="_blank">
|
|
244
|
-
<img src="media/sponsors/materialize.svg" alt="Materialize"
|
|
244
|
+
<img src="media/sponsors/materialize.svg" alt="Materialize" height="64" />
|
|
245
|
+
</a>
|
|
246
|
+
</td>
|
|
247
|
+
<td>
|
|
248
|
+
<a href="https://trigger.dev/" target="_blank">
|
|
249
|
+
<img src="media/sponsors/trigger-dev.png" alt="Trigger.dev" height="64" />
|
|
245
250
|
</a>
|
|
246
251
|
</td>
|
|
247
252
|
</tr>
|
|
@@ -101,7 +101,7 @@ class GraphQLHandler extends import_RequestHandler.RequestHandler {
|
|
|
101
101
|
const publicUrl = (0, import_getPublicUrlFromRequest.getPublicUrlFromRequest)(request);
|
|
102
102
|
import_devUtils.devUtils.warn(`Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
103
103
|
|
|
104
|
-
Consider 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/operation
|
|
104
|
+
Consider 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/operation`);
|
|
105
105
|
return false;
|
|
106
106
|
}
|
|
107
107
|
const hasMatchingUrl = (0, import_matchRequestUrl.matchRequestUrl)(new URL(request.url), this.endpoint);
|
|
@@ -82,7 +82,7 @@ class GraphQLHandler extends RequestHandler {
|
|
|
82
82
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
83
83
|
devUtils.warn(`Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
84
84
|
|
|
85
|
-
Consider 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/operation
|
|
85
|
+
Consider 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/operation`);
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
88
|
const hasMatchingUrl = matchRequestUrl(new URL(request.url), this.endpoint);
|
|
@@ -103,9 +103,9 @@ function extractMultipartVariables(variables, map, files) {
|
|
|
103
103
|
function getGraphQLInput(request) {
|
|
104
104
|
return __async(this, null, function* () {
|
|
105
105
|
var _a;
|
|
106
|
-
const url = new URL(request.url);
|
|
107
106
|
switch (request.method) {
|
|
108
107
|
case "GET": {
|
|
108
|
+
const url = new URL(request.url);
|
|
109
109
|
const query = url.searchParams.get("query");
|
|
110
110
|
const variables = url.searchParams.get("variables") || "";
|
|
111
111
|
return {
|
|
@@ -114,9 +114,10 @@ function getGraphQLInput(request) {
|
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
case "POST": {
|
|
117
|
+
const requestClone = request.clone();
|
|
117
118
|
if ((_a = request.headers.get("content-type")) == null ? void 0 : _a.includes("multipart/form-data")) {
|
|
118
119
|
const responseJson = (0, import_parseMultipartData.parseMultipartData)(
|
|
119
|
-
yield
|
|
120
|
+
yield requestClone.text(),
|
|
120
121
|
request.headers
|
|
121
122
|
);
|
|
122
123
|
if (!responseJson) {
|
|
@@ -140,7 +141,7 @@ function getGraphQLInput(request) {
|
|
|
140
141
|
variables
|
|
141
142
|
};
|
|
142
143
|
}
|
|
143
|
-
const requestJson = yield
|
|
144
|
+
const requestJson = yield requestClone.json().catch(() => null);
|
|
144
145
|
if (requestJson == null ? void 0 : requestJson.query) {
|
|
145
146
|
const { query, variables } = requestJson;
|
|
146
147
|
return {
|
|
@@ -80,9 +80,9 @@ function extractMultipartVariables(variables, map, files) {
|
|
|
80
80
|
function getGraphQLInput(request) {
|
|
81
81
|
return __async(this, null, function* () {
|
|
82
82
|
var _a;
|
|
83
|
-
const url = new URL(request.url);
|
|
84
83
|
switch (request.method) {
|
|
85
84
|
case "GET": {
|
|
85
|
+
const url = new URL(request.url);
|
|
86
86
|
const query = url.searchParams.get("query");
|
|
87
87
|
const variables = url.searchParams.get("variables") || "";
|
|
88
88
|
return {
|
|
@@ -91,9 +91,10 @@ function getGraphQLInput(request) {
|
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
case "POST": {
|
|
94
|
+
const requestClone = request.clone();
|
|
94
95
|
if ((_a = request.headers.get("content-type")) == null ? void 0 : _a.includes("multipart/form-data")) {
|
|
95
96
|
const responseJson = parseMultipartData(
|
|
96
|
-
yield
|
|
97
|
+
yield requestClone.text(),
|
|
97
98
|
request.headers
|
|
98
99
|
);
|
|
99
100
|
if (!responseJson) {
|
|
@@ -117,7 +118,7 @@ function getGraphQLInput(request) {
|
|
|
117
118
|
variables
|
|
118
119
|
};
|
|
119
120
|
}
|
|
120
|
-
const requestJson = yield
|
|
121
|
+
const requestJson = yield requestClone.json().catch(() => null);
|
|
121
122
|
if (requestJson == null ? void 0 : requestJson.query) {
|
|
122
123
|
const { query, variables } = requestJson;
|
|
123
124
|
return {
|
|
@@ -126,6 +126,7 @@ function onUnhandledRequest(request, handlers, strategy = "warn") {
|
|
|
126
126
|
const parsedGraphQLQuery = yield (0, import_parseGraphQLRequest.parseGraphQLRequest)(request).catch(
|
|
127
127
|
() => null
|
|
128
128
|
);
|
|
129
|
+
const publicUrl = (0, import_getPublicUrlFromRequest.getPublicUrlFromRequest)(request);
|
|
129
130
|
function generateHandlerSuggestion() {
|
|
130
131
|
const handlerGroups = groupHandlersByType(handlers);
|
|
131
132
|
const relevantHandlers = parsedGraphQLQuery ? handlerGroups.graphql : handlerGroups.http;
|
|
@@ -136,9 +137,14 @@ function onUnhandledRequest(request, handlers, strategy = "warn") {
|
|
|
136
137
|
);
|
|
137
138
|
return suggestedHandlers.length > 0 ? getSuggestedHandlersMessage(suggestedHandlers) : "";
|
|
138
139
|
}
|
|
140
|
+
function getGraphQLRequestHeader(parsedGraphQLRequest) {
|
|
141
|
+
if (!(parsedGraphQLRequest == null ? void 0 : parsedGraphQLRequest.operationName)) {
|
|
142
|
+
return `anonymous ${parsedGraphQLRequest == null ? void 0 : parsedGraphQLRequest.operationType} (${request.method} ${publicUrl})`;
|
|
143
|
+
}
|
|
144
|
+
return `${parsedGraphQLRequest.operationType} ${parsedGraphQLRequest.operationName} (${request.method} ${publicUrl})`;
|
|
145
|
+
}
|
|
139
146
|
function generateUnhandledRequestMessage() {
|
|
140
|
-
const
|
|
141
|
-
const requestHeader = parsedGraphQLQuery ? `${parsedGraphQLQuery.operationType} ${parsedGraphQLQuery.operationName} (${request.method} ${publicUrl})` : `${request.method} ${publicUrl}`;
|
|
147
|
+
const requestHeader = parsedGraphQLQuery ? getGraphQLRequestHeader(parsedGraphQLQuery) : `${request.method} ${publicUrl}`;
|
|
142
148
|
const handlerSuggestion = generateHandlerSuggestion();
|
|
143
149
|
const messageTemplate = [
|
|
144
150
|
`captured a request without a matching request handler:`,
|
|
@@ -95,6 +95,7 @@ function onUnhandledRequest(request, handlers, strategy = "warn") {
|
|
|
95
95
|
const parsedGraphQLQuery = yield parseGraphQLRequest(request).catch(
|
|
96
96
|
() => null
|
|
97
97
|
);
|
|
98
|
+
const publicUrl = getPublicUrlFromRequest(request);
|
|
98
99
|
function generateHandlerSuggestion() {
|
|
99
100
|
const handlerGroups = groupHandlersByType(handlers);
|
|
100
101
|
const relevantHandlers = parsedGraphQLQuery ? handlerGroups.graphql : handlerGroups.http;
|
|
@@ -105,9 +106,14 @@ function onUnhandledRequest(request, handlers, strategy = "warn") {
|
|
|
105
106
|
);
|
|
106
107
|
return suggestedHandlers.length > 0 ? getSuggestedHandlersMessage(suggestedHandlers) : "";
|
|
107
108
|
}
|
|
109
|
+
function getGraphQLRequestHeader(parsedGraphQLRequest) {
|
|
110
|
+
if (!(parsedGraphQLRequest == null ? void 0 : parsedGraphQLRequest.operationName)) {
|
|
111
|
+
return `anonymous ${parsedGraphQLRequest == null ? void 0 : parsedGraphQLRequest.operationType} (${request.method} ${publicUrl})`;
|
|
112
|
+
}
|
|
113
|
+
return `${parsedGraphQLRequest.operationType} ${parsedGraphQLRequest.operationName} (${request.method} ${publicUrl})`;
|
|
114
|
+
}
|
|
108
115
|
function generateUnhandledRequestMessage() {
|
|
109
|
-
const
|
|
110
|
-
const requestHeader = parsedGraphQLQuery ? `${parsedGraphQLQuery.operationType} ${parsedGraphQLQuery.operationName} (${request.method} ${publicUrl})` : `${request.method} ${publicUrl}`;
|
|
116
|
+
const requestHeader = parsedGraphQLQuery ? getGraphQLRequestHeader(parsedGraphQLQuery) : `${request.method} ${publicUrl}`;
|
|
111
117
|
const handlerSuggestion = generateHandlerSuggestion();
|
|
112
118
|
const messageTemplate = [
|
|
113
119
|
`captured a request without a matching request handler:`,
|
package/lib/iife/index.js
CHANGED
|
@@ -2522,7 +2522,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2522
2522
|
options: createHttpHandler("OPTIONS" /* OPTIONS */)
|
|
2523
2523
|
};
|
|
2524
2524
|
|
|
2525
|
-
// node_modules/.pnpm/graphql@16.
|
|
2525
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/devAssert.mjs
|
|
2526
2526
|
function devAssert(condition, message3) {
|
|
2527
2527
|
const booleanCondition = Boolean(condition);
|
|
2528
2528
|
if (!booleanCondition) {
|
|
@@ -2530,12 +2530,12 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2530
2530
|
}
|
|
2531
2531
|
}
|
|
2532
2532
|
|
|
2533
|
-
// node_modules/.pnpm/graphql@16.
|
|
2533
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/isObjectLike.mjs
|
|
2534
2534
|
function isObjectLike(value) {
|
|
2535
2535
|
return typeof value == "object" && value !== null;
|
|
2536
2536
|
}
|
|
2537
2537
|
|
|
2538
|
-
// node_modules/.pnpm/graphql@16.
|
|
2538
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/invariant.mjs
|
|
2539
2539
|
function invariant2(condition, message3) {
|
|
2540
2540
|
const booleanCondition = Boolean(condition);
|
|
2541
2541
|
if (!booleanCondition) {
|
|
@@ -2545,7 +2545,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2545
2545
|
}
|
|
2546
2546
|
}
|
|
2547
2547
|
|
|
2548
|
-
// node_modules/.pnpm/graphql@16.
|
|
2548
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/location.mjs
|
|
2549
2549
|
var LineRegExp = /\r\n|[\n\r]/g;
|
|
2550
2550
|
function getLocation(source, position) {
|
|
2551
2551
|
let lastLineStart = 0;
|
|
@@ -2564,7 +2564,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2564
2564
|
};
|
|
2565
2565
|
}
|
|
2566
2566
|
|
|
2567
|
-
// node_modules/.pnpm/graphql@16.
|
|
2567
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/printLocation.mjs
|
|
2568
2568
|
function printLocation(location2) {
|
|
2569
2569
|
return printSourceLocation(
|
|
2570
2570
|
location2.source,
|
|
@@ -2611,7 +2611,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2611
2611
|
return existingLines.map(([prefix, line]) => prefix.padStart(padLen) + (line ? " " + line : "")).join("\n");
|
|
2612
2612
|
}
|
|
2613
2613
|
|
|
2614
|
-
// node_modules/.pnpm/graphql@16.
|
|
2614
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/error/GraphQLError.mjs
|
|
2615
2615
|
function toNormalizedOptions(args) {
|
|
2616
2616
|
const firstArg = args[0];
|
|
2617
2617
|
if (firstArg == null || "kind" in firstArg || "length" in firstArg) {
|
|
@@ -2760,7 +2760,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2760
2760
|
return array === void 0 || array.length === 0 ? void 0 : array;
|
|
2761
2761
|
}
|
|
2762
2762
|
|
|
2763
|
-
// node_modules/.pnpm/graphql@16.
|
|
2763
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/error/syntaxError.mjs
|
|
2764
2764
|
function syntaxError(source, position, description) {
|
|
2765
2765
|
return new GraphQLError(`Syntax Error: ${description}`, {
|
|
2766
2766
|
source,
|
|
@@ -2768,7 +2768,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2768
2768
|
});
|
|
2769
2769
|
}
|
|
2770
2770
|
|
|
2771
|
-
// node_modules/.pnpm/graphql@16.
|
|
2771
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/ast.mjs
|
|
2772
2772
|
var Location = class {
|
|
2773
2773
|
/**
|
|
2774
2774
|
* The character offset at which this Node begins.
|
|
@@ -2934,7 +2934,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2934
2934
|
OperationTypeNode2["SUBSCRIPTION"] = "subscription";
|
|
2935
2935
|
})(OperationTypeNode || (OperationTypeNode = {}));
|
|
2936
2936
|
|
|
2937
|
-
// node_modules/.pnpm/graphql@16.
|
|
2937
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/directiveLocation.mjs
|
|
2938
2938
|
var DirectiveLocation;
|
|
2939
2939
|
(function(DirectiveLocation2) {
|
|
2940
2940
|
DirectiveLocation2["QUERY"] = "QUERY";
|
|
@@ -2958,7 +2958,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2958
2958
|
DirectiveLocation2["INPUT_FIELD_DEFINITION"] = "INPUT_FIELD_DEFINITION";
|
|
2959
2959
|
})(DirectiveLocation || (DirectiveLocation = {}));
|
|
2960
2960
|
|
|
2961
|
-
// node_modules/.pnpm/graphql@16.
|
|
2961
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/kinds.mjs
|
|
2962
2962
|
var Kind;
|
|
2963
2963
|
(function(Kind2) {
|
|
2964
2964
|
Kind2["NAME"] = "Name";
|
|
@@ -3006,7 +3006,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3006
3006
|
Kind2["INPUT_OBJECT_TYPE_EXTENSION"] = "InputObjectTypeExtension";
|
|
3007
3007
|
})(Kind || (Kind = {}));
|
|
3008
3008
|
|
|
3009
|
-
// node_modules/.pnpm/graphql@16.
|
|
3009
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/characterClasses.mjs
|
|
3010
3010
|
function isWhiteSpace(code) {
|
|
3011
3011
|
return code === 9 || code === 32;
|
|
3012
3012
|
}
|
|
@@ -3024,7 +3024,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3024
3024
|
return isLetter(code) || isDigit(code) || code === 95;
|
|
3025
3025
|
}
|
|
3026
3026
|
|
|
3027
|
-
// node_modules/.pnpm/graphql@16.
|
|
3027
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/blockString.mjs
|
|
3028
3028
|
function dedentBlockStringLines(lines) {
|
|
3029
3029
|
var _firstNonEmptyLine2;
|
|
3030
3030
|
let commonIndent = Number.MAX_SAFE_INTEGER;
|
|
@@ -3056,7 +3056,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3056
3056
|
return i;
|
|
3057
3057
|
}
|
|
3058
3058
|
|
|
3059
|
-
// node_modules/.pnpm/graphql@16.
|
|
3059
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/tokenKind.mjs
|
|
3060
3060
|
var TokenKind;
|
|
3061
3061
|
(function(TokenKind2) {
|
|
3062
3062
|
TokenKind2["SOF"] = "<SOF>";
|
|
@@ -3083,7 +3083,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3083
3083
|
TokenKind2["COMMENT"] = "Comment";
|
|
3084
3084
|
})(TokenKind || (TokenKind = {}));
|
|
3085
3085
|
|
|
3086
|
-
// node_modules/.pnpm/graphql@16.
|
|
3086
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/lexer.mjs
|
|
3087
3087
|
var Lexer = class {
|
|
3088
3088
|
/**
|
|
3089
3089
|
* The previously focused non-ignored token.
|
|
@@ -3584,7 +3584,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3584
3584
|
);
|
|
3585
3585
|
}
|
|
3586
3586
|
|
|
3587
|
-
// node_modules/.pnpm/graphql@16.
|
|
3587
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/inspect.mjs
|
|
3588
3588
|
var MAX_ARRAY_LENGTH = 10;
|
|
3589
3589
|
var MAX_RECURSIVE_DEPTH = 2;
|
|
3590
3590
|
function inspect(value) {
|
|
@@ -3667,7 +3667,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
3667
3667
|
return tag;
|
|
3668
3668
|
}
|
|
3669
3669
|
|
|
3670
|
-
// node_modules/.pnpm/graphql@16.
|
|
3670
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/instanceOf.mjs
|
|
3671
3671
|
var instanceOf = (
|
|
3672
3672
|
/* c8 ignore next 6 */
|
|
3673
3673
|
// FIXME: https://github.com/graphql/graphql-js/issues/2317
|
|
@@ -3704,7 +3704,7 @@ spurious results.`);
|
|
|
3704
3704
|
}
|
|
3705
3705
|
);
|
|
3706
3706
|
|
|
3707
|
-
// node_modules/.pnpm/graphql@16.
|
|
3707
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/source.mjs
|
|
3708
3708
|
var Source = class {
|
|
3709
3709
|
constructor(body, name = "GraphQL request", locationOffset = {
|
|
3710
3710
|
line: 1,
|
|
@@ -3731,7 +3731,7 @@ spurious results.`);
|
|
|
3731
3731
|
return instanceOf(source, Source);
|
|
3732
3732
|
}
|
|
3733
3733
|
|
|
3734
|
-
// node_modules/.pnpm/graphql@16.
|
|
3734
|
+
// node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/parser.mjs
|
|
3735
3735
|
function parse2(source, options) {
|
|
3736
3736
|
const parser = new Parser(source, options);
|
|
3737
3737
|
return parser.parseDocument();
|
|
@@ -5091,9 +5091,9 @@ spurious results.`);
|
|
|
5091
5091
|
function getGraphQLInput(request) {
|
|
5092
5092
|
return __async(this, null, function* () {
|
|
5093
5093
|
var _a2;
|
|
5094
|
-
const url = new URL(request.url);
|
|
5095
5094
|
switch (request.method) {
|
|
5096
5095
|
case "GET": {
|
|
5096
|
+
const url = new URL(request.url);
|
|
5097
5097
|
const query = url.searchParams.get("query");
|
|
5098
5098
|
const variables = url.searchParams.get("variables") || "";
|
|
5099
5099
|
return {
|
|
@@ -5102,9 +5102,10 @@ spurious results.`);
|
|
|
5102
5102
|
};
|
|
5103
5103
|
}
|
|
5104
5104
|
case "POST": {
|
|
5105
|
+
const requestClone = request.clone();
|
|
5105
5106
|
if ((_a2 = request.headers.get("content-type")) == null ? void 0 : _a2.includes("multipart/form-data")) {
|
|
5106
5107
|
const responseJson = parseMultipartData(
|
|
5107
|
-
yield
|
|
5108
|
+
yield requestClone.text(),
|
|
5108
5109
|
request.headers
|
|
5109
5110
|
);
|
|
5110
5111
|
if (!responseJson) {
|
|
@@ -5128,7 +5129,7 @@ spurious results.`);
|
|
|
5128
5129
|
variables
|
|
5129
5130
|
};
|
|
5130
5131
|
}
|
|
5131
|
-
const requestJson = yield
|
|
5132
|
+
const requestJson = yield requestClone.json().catch(() => null);
|
|
5132
5133
|
if (requestJson == null ? void 0 : requestJson.query) {
|
|
5133
5134
|
const { query, variables } = requestJson;
|
|
5134
5135
|
return {
|
|
@@ -5221,7 +5222,7 @@ spurious results.`);
|
|
|
5221
5222
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
5222
5223
|
devUtils.warn(`Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
5223
5224
|
|
|
5224
|
-
Consider 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/operation
|
|
5225
|
+
Consider 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/operation`);
|
|
5225
5226
|
return false;
|
|
5226
5227
|
}
|
|
5227
5228
|
const hasMatchingUrl = matchRequestUrl(new URL(request.url), this.endpoint);
|
|
@@ -5527,6 +5528,7 @@ ${handlers.map((handler) => ` \u2022 ${handler.info.header}`).join("\n")}`;
|
|
|
5527
5528
|
const parsedGraphQLQuery = yield parseGraphQLRequest(request).catch(
|
|
5528
5529
|
() => null
|
|
5529
5530
|
);
|
|
5531
|
+
const publicUrl = getPublicUrlFromRequest(request);
|
|
5530
5532
|
function generateHandlerSuggestion() {
|
|
5531
5533
|
const handlerGroups = groupHandlersByType(handlers);
|
|
5532
5534
|
const relevantHandlers = parsedGraphQLQuery ? handlerGroups.graphql : handlerGroups.http;
|
|
@@ -5537,9 +5539,14 @@ ${handlers.map((handler) => ` \u2022 ${handler.info.header}`).join("\n")}`;
|
|
|
5537
5539
|
);
|
|
5538
5540
|
return suggestedHandlers.length > 0 ? getSuggestedHandlersMessage(suggestedHandlers) : "";
|
|
5539
5541
|
}
|
|
5542
|
+
function getGraphQLRequestHeader(parsedGraphQLRequest) {
|
|
5543
|
+
if (!(parsedGraphQLRequest == null ? void 0 : parsedGraphQLRequest.operationName)) {
|
|
5544
|
+
return `anonymous ${parsedGraphQLRequest == null ? void 0 : parsedGraphQLRequest.operationType} (${request.method} ${publicUrl})`;
|
|
5545
|
+
}
|
|
5546
|
+
return `${parsedGraphQLRequest.operationType} ${parsedGraphQLRequest.operationName} (${request.method} ${publicUrl})`;
|
|
5547
|
+
}
|
|
5540
5548
|
function generateUnhandledRequestMessage() {
|
|
5541
|
-
const
|
|
5542
|
-
const requestHeader = parsedGraphQLQuery ? `${parsedGraphQLQuery.operationType} ${parsedGraphQLQuery.operationName} (${request.method} ${publicUrl})` : `${request.method} ${publicUrl}`;
|
|
5549
|
+
const requestHeader = parsedGraphQLQuery ? getGraphQLRequestHeader(parsedGraphQLQuery) : `${request.method} ${publicUrl}`;
|
|
5543
5550
|
const handlerSuggestion = generateHandlerSuggestion();
|
|
5544
5551
|
const messageTemplate = [
|
|
5545
5552
|
`captured a request without a matching request handler:`,
|
package/lib/mockServiceWorker.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "0.0.0-fetch.rc-
|
|
3
|
+
"version": "0.0.0-fetch.rc-17",
|
|
4
4
|
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
|
|
5
5
|
"main": "./lib/core/index.js",
|
|
6
6
|
"module": "./lib/core/index.mjs",
|
|
7
7
|
"types": "./lib/core/index.d.ts",
|
|
8
|
+
"packageManager": "pnpm@7.12.2",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"types": "./lib/core/index.d.ts",
|