msw 2.0.5 → 2.0.6
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/lib/core/{GraphQLHandler-d46c4f60.d.ts → GraphQLHandler-074ec9e5.d.ts} +3 -1
- package/lib/core/graphql.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.js +19 -5
- package/lib/core/handlers/GraphQLHandler.mjs +19 -5
- package/lib/core/index.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
- package/lib/iife/index.js +18 -5
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +1 -1
|
@@ -35,6 +35,7 @@ type GraphQLResolverExtras<Variables extends GraphQLVariables> = {
|
|
|
35
35
|
query: string;
|
|
36
36
|
operationName: string;
|
|
37
37
|
variables: Variables;
|
|
38
|
+
cookies: Record<string, string | Array<string>>;
|
|
38
39
|
};
|
|
39
40
|
type GraphQLRequestBody<VariablesType extends GraphQLVariables> = GraphQLJsonRequestBody<VariablesType> | GraphQLMultipartRequestBody | Record<string, any> | undefined;
|
|
40
41
|
interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {
|
|
@@ -54,7 +55,7 @@ declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, ParsedGr
|
|
|
54
55
|
}): Promise<ParsedGraphQLRequest<GraphQLVariables>>;
|
|
55
56
|
predicate(args: {
|
|
56
57
|
request: Request;
|
|
57
|
-
parsedResult: ParsedGraphQLRequest
|
|
58
|
+
parsedResult: ParsedGraphQLRequest<GraphQLVariables>;
|
|
58
59
|
}): boolean;
|
|
59
60
|
protected extendResolverArgs(args: {
|
|
60
61
|
request: Request;
|
|
@@ -63,6 +64,7 @@ declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, ParsedGr
|
|
|
63
64
|
query: string;
|
|
64
65
|
operationName: string;
|
|
65
66
|
variables: GraphQLVariables;
|
|
67
|
+
cookies: Record<string, string>;
|
|
66
68
|
};
|
|
67
69
|
log(args: {
|
|
68
70
|
request: Request;
|
package/lib/core/graphql.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
2
|
import { a as ResponseResolver, c as RequestHandlerOptions } from './RequestHandler-bb5cbb8f.js';
|
|
3
|
-
import { a as GraphQLVariables, d as GraphQLHandlerNameSelector, e as GraphQLResolverExtras, f as GraphQLResponseBody, G as GraphQLHandler } from './GraphQLHandler-
|
|
3
|
+
import { a as GraphQLVariables, d as GraphQLHandlerNameSelector, e as GraphQLResolverExtras, f as GraphQLResponseBody, G as GraphQLHandler } from './GraphQLHandler-074ec9e5.js';
|
|
4
4
|
import { Path } from './utils/matching/matchRequestUrl.js';
|
|
5
5
|
import './typeUtils.js';
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
2
|
import '../RequestHandler-bb5cbb8f.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, e as GraphQLResolverExtras, f as GraphQLResponseBody, a as GraphQLVariables, l as isDocumentNode } from '../GraphQLHandler-
|
|
4
|
+
export { E as ExpectedOperationTypeNode, G as GraphQLHandler, k as GraphQLHandlerInfo, d as GraphQLHandlerNameSelector, c as GraphQLJsonRequestBody, b as GraphQLRequestBody, e as GraphQLResolverExtras, f as GraphQLResponseBody, a as GraphQLVariables, l as isDocumentNode } from '../GraphQLHandler-074ec9e5.js';
|
|
5
5
|
import '../typeUtils.js';
|
|
@@ -51,6 +51,7 @@ var import_matchRequestUrl = require("../utils/matching/matchRequestUrl.js");
|
|
|
51
51
|
var import_parseGraphQLRequest = require("../utils/internal/parseGraphQLRequest.js");
|
|
52
52
|
var import_getPublicUrlFromRequest = require("../utils/request/getPublicUrlFromRequest.js");
|
|
53
53
|
var import_devUtils = require("../utils/internal/devUtils.js");
|
|
54
|
+
var import_getRequestCookies = require("../utils/request/getRequestCookies.js");
|
|
54
55
|
function isDocumentNode(value) {
|
|
55
56
|
if (value == null) {
|
|
56
57
|
return false;
|
|
@@ -88,10 +89,21 @@ class GraphQLHandler extends import_RequestHandler.RequestHandler {
|
|
|
88
89
|
}
|
|
89
90
|
parse(args) {
|
|
90
91
|
return __async(this, null, function* () {
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
const parsedResult = yield (0, import_parseGraphQLRequest.parseGraphQLRequest)(args.request).catch(
|
|
93
|
+
(error) => {
|
|
94
|
+
console.error(error);
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
if (typeof parsedResult === "undefined") {
|
|
93
99
|
return void 0;
|
|
94
|
-
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
query: parsedResult.query,
|
|
103
|
+
operationType: parsedResult.operationType,
|
|
104
|
+
operationName: parsedResult.operationName,
|
|
105
|
+
variables: parsedResult.variables
|
|
106
|
+
};
|
|
95
107
|
});
|
|
96
108
|
}
|
|
97
109
|
predicate(args) {
|
|
@@ -102,7 +114,7 @@ class GraphQLHandler extends import_RequestHandler.RequestHandler {
|
|
|
102
114
|
const publicUrl = (0, import_getPublicUrlFromRequest.getPublicUrlFromRequest)(args.request);
|
|
103
115
|
import_devUtils.devUtils.warn(`Failed to intercept a GraphQL request at "${args.request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
104
116
|
|
|
105
|
-
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
|
|
117
|
+
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/#graphqloperationresolver`);
|
|
106
118
|
return false;
|
|
107
119
|
}
|
|
108
120
|
const hasMatchingUrl = (0, import_matchRequestUrl.matchRequestUrl)(
|
|
@@ -115,10 +127,12 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
115
127
|
}
|
|
116
128
|
extendResolverArgs(args) {
|
|
117
129
|
var _a, _b, _c;
|
|
130
|
+
const cookies = (0, import_getRequestCookies.getAllRequestCookies)(args.request);
|
|
118
131
|
return {
|
|
119
132
|
query: ((_a = args.parsedResult) == null ? void 0 : _a.query) || "",
|
|
120
133
|
operationName: ((_b = args.parsedResult) == null ? void 0 : _b.operationName) || "",
|
|
121
|
-
variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {}
|
|
134
|
+
variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {},
|
|
135
|
+
cookies
|
|
122
136
|
};
|
|
123
137
|
}
|
|
124
138
|
log(args) {
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
} from '../utils/internal/parseGraphQLRequest.mjs';
|
|
33
33
|
import { getPublicUrlFromRequest } from '../utils/request/getPublicUrlFromRequest.mjs';
|
|
34
34
|
import { devUtils } from '../utils/internal/devUtils.mjs';
|
|
35
|
+
import { getAllRequestCookies } from '../utils/request/getRequestCookies.mjs';
|
|
35
36
|
function isDocumentNode(value) {
|
|
36
37
|
if (value == null) {
|
|
37
38
|
return false;
|
|
@@ -69,10 +70,21 @@ class GraphQLHandler extends RequestHandler {
|
|
|
69
70
|
}
|
|
70
71
|
parse(args) {
|
|
71
72
|
return __async(this, null, function* () {
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
const parsedResult = yield parseGraphQLRequest(args.request).catch(
|
|
74
|
+
(error) => {
|
|
75
|
+
console.error(error);
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
if (typeof parsedResult === "undefined") {
|
|
74
80
|
return void 0;
|
|
75
|
-
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
query: parsedResult.query,
|
|
84
|
+
operationType: parsedResult.operationType,
|
|
85
|
+
operationName: parsedResult.operationName,
|
|
86
|
+
variables: parsedResult.variables
|
|
87
|
+
};
|
|
76
88
|
});
|
|
77
89
|
}
|
|
78
90
|
predicate(args) {
|
|
@@ -83,7 +95,7 @@ class GraphQLHandler extends RequestHandler {
|
|
|
83
95
|
const publicUrl = getPublicUrlFromRequest(args.request);
|
|
84
96
|
devUtils.warn(`Failed to intercept a GraphQL request at "${args.request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
85
97
|
|
|
86
|
-
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
|
|
98
|
+
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/#graphqloperationresolver`);
|
|
87
99
|
return false;
|
|
88
100
|
}
|
|
89
101
|
const hasMatchingUrl = matchRequestUrl(
|
|
@@ -96,10 +108,12 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
96
108
|
}
|
|
97
109
|
extendResolverArgs(args) {
|
|
98
110
|
var _a, _b, _c;
|
|
111
|
+
const cookies = getAllRequestCookies(args.request);
|
|
99
112
|
return {
|
|
100
113
|
query: ((_a = args.parsedResult) == null ? void 0 : _a.query) || "",
|
|
101
114
|
operationName: ((_b = args.parsedResult) == null ? void 0 : _b.operationName) || "",
|
|
102
|
-
variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {}
|
|
115
|
+
variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {},
|
|
116
|
+
cookies
|
|
103
117
|
};
|
|
104
118
|
}
|
|
105
119
|
log(args) {
|
package/lib/core/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as Defaul
|
|
|
3
3
|
export { http } from './http.js';
|
|
4
4
|
export { HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.js';
|
|
5
5
|
export { graphql } from './graphql.js';
|
|
6
|
-
export { G as GraphQLHandler, c as GraphQLJsonRequestBody, b as GraphQLRequestBody, a as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-
|
|
6
|
+
export { G as GraphQLHandler, c as GraphQLJsonRequestBody, b as GraphQLRequestBody, a as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-074ec9e5.js';
|
|
7
7
|
export { Match, Path, PathParams, matchRequestUrl } from './utils/matching/matchRequestUrl.js';
|
|
8
8
|
export { HandleRequestOptions, handleRequest } from './utils/handleRequest.js';
|
|
9
9
|
export { cleanUrl } from './utils/url/cleanUrl.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { i as GraphQLMultipartRequestBody, h as GraphQLParsedOperationsMap, g as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, j as parseGraphQLRequest } from '../../GraphQLHandler-
|
|
2
|
+
export { i as GraphQLMultipartRequestBody, h as GraphQLParsedOperationsMap, g as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, j as parseGraphQLRequest } from '../../GraphQLHandler-074ec9e5.js';
|
|
3
3
|
import '../../RequestHandler-bb5cbb8f.js';
|
|
4
4
|
import '../../typeUtils.js';
|
|
5
5
|
import '../matching/matchRequestUrl.js';
|
package/lib/iife/index.js
CHANGED
|
@@ -5639,10 +5639,21 @@ spurious results.`);
|
|
|
5639
5639
|
}
|
|
5640
5640
|
parse(args) {
|
|
5641
5641
|
return __async(this, null, function* () {
|
|
5642
|
-
|
|
5643
|
-
|
|
5642
|
+
const parsedResult = yield parseGraphQLRequest(args.request).catch(
|
|
5643
|
+
(error3) => {
|
|
5644
|
+
console.error(error3);
|
|
5645
|
+
return void 0;
|
|
5646
|
+
}
|
|
5647
|
+
);
|
|
5648
|
+
if (typeof parsedResult === "undefined") {
|
|
5644
5649
|
return void 0;
|
|
5645
|
-
}
|
|
5650
|
+
}
|
|
5651
|
+
return {
|
|
5652
|
+
query: parsedResult.query,
|
|
5653
|
+
operationType: parsedResult.operationType,
|
|
5654
|
+
operationName: parsedResult.operationName,
|
|
5655
|
+
variables: parsedResult.variables
|
|
5656
|
+
};
|
|
5646
5657
|
});
|
|
5647
5658
|
}
|
|
5648
5659
|
predicate(args) {
|
|
@@ -5653,7 +5664,7 @@ spurious results.`);
|
|
|
5653
5664
|
const publicUrl = getPublicUrlFromRequest(args.request);
|
|
5654
5665
|
devUtils.warn(`Failed to intercept a GraphQL request at "${args.request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
5655
5666
|
|
|
5656
|
-
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
|
|
5667
|
+
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/#graphqloperationresolver`);
|
|
5657
5668
|
return false;
|
|
5658
5669
|
}
|
|
5659
5670
|
const hasMatchingUrl = matchRequestUrl(
|
|
@@ -5666,10 +5677,12 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5666
5677
|
}
|
|
5667
5678
|
extendResolverArgs(args) {
|
|
5668
5679
|
var _a3, _b2, _c;
|
|
5680
|
+
const cookies = getAllRequestCookies(args.request);
|
|
5669
5681
|
return {
|
|
5670
5682
|
query: ((_a3 = args.parsedResult) == null ? void 0 : _a3.query) || "",
|
|
5671
5683
|
operationName: ((_b2 = args.parsedResult) == null ? void 0 : _b2.operationName) || "",
|
|
5672
|
-
variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {}
|
|
5684
|
+
variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {},
|
|
5685
|
+
cookies
|
|
5673
5686
|
};
|
|
5674
5687
|
}
|
|
5675
5688
|
log(args) {
|
package/lib/mockServiceWorker.js
CHANGED