msw 0.0.0-fetch.rc-19 → 0.0.0-fetch.rc-21
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 +5 -2
- package/lib/browser/index.d.ts +21 -8
- package/lib/browser/index.js +14 -6
- package/lib/browser/index.mjs +14 -6
- package/lib/core/{GraphQLHandler-2e60cda6.d.ts → GraphQLHandler-a441dd03.d.ts} +19 -7
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/{RequestHandler-e964183f.d.ts → RequestHandler-b59044ae.d.ts} +44 -17
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/bypass.d.ts +7 -7
- package/lib/core/bypass.js +10 -68
- package/lib/core/bypass.mjs +10 -68
- package/lib/core/delay.d.ts +3 -0
- package/lib/core/graphql.d.ts +62 -30
- package/lib/core/graphql.js +38 -16
- package/lib/core/graphql.mjs +38 -16
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.js +26 -20
- package/lib/core/handlers/GraphQLHandler.mjs +26 -20
- package/lib/core/handlers/HttpHandler.d.ts +18 -6
- package/lib/core/handlers/HttpHandler.js +17 -16
- package/lib/core/handlers/HttpHandler.mjs +17 -16
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +43 -35
- package/lib/core/handlers/RequestHandler.mjs +43 -35
- package/lib/core/http.d.ts +18 -9
- package/lib/core/index.d.ts +2 -2
- package/lib/core/passthrough.d.ts +3 -1
- package/lib/core/sharedOptions.d.ts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/getResponse.d.ts +1 -1
- package/lib/core/utils/getResponse.js +2 -2
- package/lib/core/utils/getResponse.mjs +2 -2
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +2 -2
- package/lib/core/utils/logging/serializeRequest.d.ts +1 -3
- package/lib/core/utils/logging/serializeRequest.js +1 -2
- package/lib/core/utils/logging/serializeRequest.mjs +1 -2
- package/lib/core/utils/logging/serializeResponse.d.ts +1 -3
- package/lib/core/utils/logging/serializeResponse.js +1 -2
- package/lib/core/utils/logging/serializeResponse.mjs +1 -2
- package/lib/core/utils/request/onUnhandledRequest.d.ts +1 -1
- package/lib/core/utils/request/onUnhandledRequest.js +1 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs +1 -1
- package/lib/core/utils/toResponseInit.js +1 -2
- package/lib/core/utils/toResponseInit.mjs +1 -2
- package/lib/iife/index.js +2182 -2094
- package/lib/mockServiceWorker.js +4 -17
- package/lib/native/index.d.ts +20 -7
- package/lib/native/index.js +5 -0
- package/lib/native/index.mjs +5 -0
- package/lib/node/index.d.ts +20 -7
- package/lib/node/index.js +5 -0
- package/lib/node/index.mjs +5 -0
- package/package.json +5 -6
package/lib/core/graphql.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DocumentNode } from 'graphql';
|
|
2
|
-
import { a as ResponseResolver } from './RequestHandler-
|
|
3
|
-
import { a as GraphQLVariables, d as
|
|
2
|
+
import { a as ResponseResolver, f as RequestHandlerOptions } from './RequestHandler-b59044ae.js';
|
|
3
|
+
import { a as GraphQLVariables, d as GraphQLHandlerNameSelector, e as GraphQLResolverExtras, f as GraphQLResponseBody, G as GraphQLHandler } from './GraphQLHandler-a441dd03.js';
|
|
4
4
|
import { Path } from './utils/matching/matchRequestUrl.js';
|
|
5
5
|
import './typeUtils.js';
|
|
6
6
|
|
|
@@ -15,63 +15,95 @@ interface TypedDocumentNode<Result = {
|
|
|
15
15
|
}
|
|
16
16
|
declare const standardGraphQLHandlers: {
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* graphql.operation(() => {
|
|
21
|
-
* return HttpResponse.json({ data: { name: 'John' } })
|
|
22
|
-
* })
|
|
23
|
-
* @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
|
|
24
|
-
*/
|
|
25
|
-
operation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>) => GraphQLHandler;
|
|
26
|
-
/**
|
|
27
|
-
* Captures a GraphQL query by a given name.
|
|
18
|
+
* Intercepts a GraphQL query by a given name.
|
|
19
|
+
*
|
|
28
20
|
* @example
|
|
29
21
|
* graphql.query('GetUser', () => {
|
|
30
22
|
* return HttpResponse.json({ data: { user: { name: 'John' } } })
|
|
31
23
|
* })
|
|
32
|
-
*
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
|
|
33
26
|
*/
|
|
34
|
-
query: <
|
|
27
|
+
query: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
35
28
|
/**
|
|
36
|
-
*
|
|
29
|
+
* Intercepts a GraphQL mutation by its name.
|
|
30
|
+
*
|
|
37
31
|
* @example
|
|
38
32
|
* graphql.mutation('SavePost', () => {
|
|
39
33
|
* return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
|
|
40
34
|
* })
|
|
41
|
-
*
|
|
35
|
+
*
|
|
36
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
|
|
37
|
+
*
|
|
42
38
|
*/
|
|
43
|
-
mutation: <
|
|
44
|
-
};
|
|
45
|
-
declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
|
|
46
|
-
declare const graphql: {
|
|
47
|
-
link: typeof createGraphQLLink;
|
|
39
|
+
mutation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
48
40
|
/**
|
|
49
|
-
*
|
|
41
|
+
* Intercepts any GraphQL operation, regardless of its type or name.
|
|
42
|
+
*
|
|
50
43
|
* @example
|
|
51
44
|
* graphql.operation(() => {
|
|
52
45
|
* return HttpResponse.json({ data: { name: 'John' } })
|
|
53
46
|
* })
|
|
54
|
-
*
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
|
|
55
49
|
*/
|
|
56
|
-
operation: <
|
|
50
|
+
operation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables_1>, null, GraphQLResponseBody<Query_1>>) => GraphQLHandler;
|
|
51
|
+
};
|
|
52
|
+
declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
|
|
53
|
+
/**
|
|
54
|
+
* A namespace to intercept and mock GraphQL operations
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* graphql.query('GetUser', resolver)
|
|
58
|
+
* graphql.mutation('DeletePost', resolver)
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}
|
|
61
|
+
*/
|
|
62
|
+
declare const graphql: {
|
|
63
|
+
/**
|
|
64
|
+
* Intercepts GraphQL operations scoped by the given URL.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* const github = graphql.link('https://api.github.com/graphql')
|
|
68
|
+
* github.query('GetRepo', resolver)
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
71
|
+
*/
|
|
72
|
+
link: typeof createGraphQLLink;
|
|
57
73
|
/**
|
|
58
|
-
*
|
|
74
|
+
* Intercepts a GraphQL query by a given name.
|
|
75
|
+
*
|
|
59
76
|
* @example
|
|
60
77
|
* graphql.query('GetUser', () => {
|
|
61
78
|
* return HttpResponse.json({ data: { user: { name: 'John' } } })
|
|
62
79
|
* })
|
|
63
|
-
*
|
|
80
|
+
*
|
|
81
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
|
|
64
82
|
*/
|
|
65
|
-
query: <
|
|
83
|
+
query: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
66
84
|
/**
|
|
67
|
-
*
|
|
85
|
+
* Intercepts a GraphQL mutation by its name.
|
|
86
|
+
*
|
|
68
87
|
* @example
|
|
69
88
|
* graphql.mutation('SavePost', () => {
|
|
70
89
|
* return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
|
|
71
90
|
* })
|
|
72
|
-
*
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
mutation: <Query extends Record<string, any>, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | TypedDocumentNode<Query, Variables>, resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
96
|
+
/**
|
|
97
|
+
* Intercepts any GraphQL operation, regardless of its type or name.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* graphql.operation(() => {
|
|
101
|
+
* return HttpResponse.json({ data: { name: 'John' } })
|
|
102
|
+
* })
|
|
103
|
+
*
|
|
104
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
|
|
73
105
|
*/
|
|
74
|
-
|
|
106
|
+
operation: <Query_1 extends Record<string, any>, Variables_1 extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables_1>, null, GraphQLResponseBody<Query_1>>) => GraphQLHandler;
|
|
75
107
|
};
|
|
76
108
|
|
|
77
109
|
export { TypedDocumentNode, graphql };
|
package/lib/core/graphql.js
CHANGED
|
@@ -40,8 +40,14 @@ __export(graphql_exports, {
|
|
|
40
40
|
module.exports = __toCommonJS(graphql_exports);
|
|
41
41
|
var import_GraphQLHandler = require("./handlers/GraphQLHandler.js");
|
|
42
42
|
function createScopedGraphQLHandler(operationType, url) {
|
|
43
|
-
return (operationName, resolver) => {
|
|
44
|
-
return new import_GraphQLHandler.GraphQLHandler(
|
|
43
|
+
return (operationName, resolver, options = {}) => {
|
|
44
|
+
return new import_GraphQLHandler.GraphQLHandler(
|
|
45
|
+
operationType,
|
|
46
|
+
operationName,
|
|
47
|
+
url,
|
|
48
|
+
resolver,
|
|
49
|
+
options
|
|
50
|
+
);
|
|
45
51
|
};
|
|
46
52
|
}
|
|
47
53
|
function createGraphQLOperationHandler(url) {
|
|
@@ -51,32 +57,39 @@ function createGraphQLOperationHandler(url) {
|
|
|
51
57
|
}
|
|
52
58
|
const standardGraphQLHandlers = {
|
|
53
59
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* graphql.operation(() => {
|
|
57
|
-
* return HttpResponse.json({ data: { name: 'John' } })
|
|
58
|
-
* })
|
|
59
|
-
* @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
|
|
60
|
-
*/
|
|
61
|
-
operation: createGraphQLOperationHandler("*"),
|
|
62
|
-
/**
|
|
63
|
-
* Captures a GraphQL query by a given name.
|
|
60
|
+
* Intercepts a GraphQL query by a given name.
|
|
61
|
+
*
|
|
64
62
|
* @example
|
|
65
63
|
* graphql.query('GetUser', () => {
|
|
66
64
|
* return HttpResponse.json({ data: { user: { name: 'John' } } })
|
|
67
65
|
* })
|
|
68
|
-
*
|
|
66
|
+
*
|
|
67
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
|
|
69
68
|
*/
|
|
70
69
|
query: createScopedGraphQLHandler("query", "*"),
|
|
71
70
|
/**
|
|
72
|
-
*
|
|
71
|
+
* Intercepts a GraphQL mutation by its name.
|
|
72
|
+
*
|
|
73
73
|
* @example
|
|
74
74
|
* graphql.mutation('SavePost', () => {
|
|
75
75
|
* return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
|
|
76
76
|
* })
|
|
77
|
-
*
|
|
77
|
+
*
|
|
78
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
|
|
79
|
+
*
|
|
78
80
|
*/
|
|
79
|
-
mutation: createScopedGraphQLHandler("mutation", "*")
|
|
81
|
+
mutation: createScopedGraphQLHandler("mutation", "*"),
|
|
82
|
+
/**
|
|
83
|
+
* Intercepts any GraphQL operation, regardless of its type or name.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* graphql.operation(() => {
|
|
87
|
+
* return HttpResponse.json({ data: { name: 'John' } })
|
|
88
|
+
* })
|
|
89
|
+
*
|
|
90
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
|
|
91
|
+
*/
|
|
92
|
+
operation: createGraphQLOperationHandler("*")
|
|
80
93
|
};
|
|
81
94
|
function createGraphQLLink(url) {
|
|
82
95
|
return {
|
|
@@ -86,5 +99,14 @@ function createGraphQLLink(url) {
|
|
|
86
99
|
};
|
|
87
100
|
}
|
|
88
101
|
const graphql = __spreadProps(__spreadValues({}, standardGraphQLHandlers), {
|
|
102
|
+
/**
|
|
103
|
+
* Intercepts GraphQL operations scoped by the given URL.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* const github = graphql.link('https://api.github.com/graphql')
|
|
107
|
+
* github.query('GetRepo', resolver)
|
|
108
|
+
*
|
|
109
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
110
|
+
*/
|
|
89
111
|
link: createGraphQLLink
|
|
90
112
|
});
|
package/lib/core/graphql.mjs
CHANGED
|
@@ -21,8 +21,14 @@ import {
|
|
|
21
21
|
GraphQLHandler
|
|
22
22
|
} from './handlers/GraphQLHandler.mjs';
|
|
23
23
|
function createScopedGraphQLHandler(operationType, url) {
|
|
24
|
-
return (operationName, resolver) => {
|
|
25
|
-
return new GraphQLHandler(
|
|
24
|
+
return (operationName, resolver, options = {}) => {
|
|
25
|
+
return new GraphQLHandler(
|
|
26
|
+
operationType,
|
|
27
|
+
operationName,
|
|
28
|
+
url,
|
|
29
|
+
resolver,
|
|
30
|
+
options
|
|
31
|
+
);
|
|
26
32
|
};
|
|
27
33
|
}
|
|
28
34
|
function createGraphQLOperationHandler(url) {
|
|
@@ -32,32 +38,39 @@ function createGraphQLOperationHandler(url) {
|
|
|
32
38
|
}
|
|
33
39
|
const standardGraphQLHandlers = {
|
|
34
40
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* graphql.operation(() => {
|
|
38
|
-
* return HttpResponse.json({ data: { name: 'John' } })
|
|
39
|
-
* })
|
|
40
|
-
* @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
|
|
41
|
-
*/
|
|
42
|
-
operation: createGraphQLOperationHandler("*"),
|
|
43
|
-
/**
|
|
44
|
-
* Captures a GraphQL query by a given name.
|
|
41
|
+
* Intercepts a GraphQL query by a given name.
|
|
42
|
+
*
|
|
45
43
|
* @example
|
|
46
44
|
* graphql.query('GetUser', () => {
|
|
47
45
|
* return HttpResponse.json({ data: { user: { name: 'John' } } })
|
|
48
46
|
* })
|
|
49
|
-
*
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
|
|
50
49
|
*/
|
|
51
50
|
query: createScopedGraphQLHandler("query", "*"),
|
|
52
51
|
/**
|
|
53
|
-
*
|
|
52
|
+
* Intercepts a GraphQL mutation by its name.
|
|
53
|
+
*
|
|
54
54
|
* @example
|
|
55
55
|
* graphql.mutation('SavePost', () => {
|
|
56
56
|
* return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
|
|
57
57
|
* })
|
|
58
|
-
*
|
|
58
|
+
*
|
|
59
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
|
|
60
|
+
*
|
|
59
61
|
*/
|
|
60
|
-
mutation: createScopedGraphQLHandler("mutation", "*")
|
|
62
|
+
mutation: createScopedGraphQLHandler("mutation", "*"),
|
|
63
|
+
/**
|
|
64
|
+
* Intercepts any GraphQL operation, regardless of its type or name.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* graphql.operation(() => {
|
|
68
|
+
* return HttpResponse.json({ data: { name: 'John' } })
|
|
69
|
+
* })
|
|
70
|
+
*
|
|
71
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
|
|
72
|
+
*/
|
|
73
|
+
operation: createGraphQLOperationHandler("*")
|
|
61
74
|
};
|
|
62
75
|
function createGraphQLLink(url) {
|
|
63
76
|
return {
|
|
@@ -67,6 +80,15 @@ function createGraphQLLink(url) {
|
|
|
67
80
|
};
|
|
68
81
|
}
|
|
69
82
|
const graphql = __spreadProps(__spreadValues({}, standardGraphQLHandlers), {
|
|
83
|
+
/**
|
|
84
|
+
* Intercepts GraphQL operations scoped by the given URL.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* const github = graphql.link('https://api.github.com/graphql')
|
|
88
|
+
* github.query('GetRepo', resolver)
|
|
89
|
+
*
|
|
90
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
91
|
+
*/
|
|
70
92
|
link: createGraphQLLink
|
|
71
93
|
});
|
|
72
94
|
export {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
import '../RequestHandler-
|
|
2
|
+
import '../RequestHandler-b59044ae.js';
|
|
3
3
|
import '../utils/matching/matchRequestUrl.js';
|
|
4
|
-
export { E as ExpectedOperationTypeNode, G as GraphQLHandler, k as GraphQLHandlerInfo,
|
|
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-a441dd03.js';
|
|
5
5
|
import '../typeUtils.js';
|
|
@@ -58,7 +58,7 @@ function isDocumentNode(value) {
|
|
|
58
58
|
return typeof value === "object" && "kind" in value && "definitions" in value;
|
|
59
59
|
}
|
|
60
60
|
class GraphQLHandler extends import_RequestHandler.RequestHandler {
|
|
61
|
-
constructor(operationType, operationName, endpoint, resolver) {
|
|
61
|
+
constructor(operationType, operationName, endpoint, resolver, options) {
|
|
62
62
|
let resolvedOperationName = operationName;
|
|
63
63
|
if (isDocumentNode(operationName)) {
|
|
64
64
|
const parsedNode = (0, import_parseGraphQLRequest.parseDocumentNode)(operationName);
|
|
@@ -81,47 +81,53 @@ class GraphQLHandler extends import_RequestHandler.RequestHandler {
|
|
|
81
81
|
operationType,
|
|
82
82
|
operationName: resolvedOperationName
|
|
83
83
|
},
|
|
84
|
-
resolver
|
|
84
|
+
resolver,
|
|
85
|
+
options
|
|
85
86
|
});
|
|
86
87
|
this.endpoint = endpoint;
|
|
87
88
|
}
|
|
88
|
-
parse(
|
|
89
|
+
parse(args) {
|
|
89
90
|
return __async(this, null, function* () {
|
|
90
|
-
return (0, import_parseGraphQLRequest.parseGraphQLRequest)(request).catch((error) => {
|
|
91
|
+
return (0, import_parseGraphQLRequest.parseGraphQLRequest)(args.request).catch((error) => {
|
|
91
92
|
console.error(error);
|
|
92
93
|
return void 0;
|
|
93
94
|
});
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
|
-
predicate(
|
|
97
|
-
if (!parsedResult) {
|
|
97
|
+
predicate(args) {
|
|
98
|
+
if (!args.parsedResult) {
|
|
98
99
|
return false;
|
|
99
100
|
}
|
|
100
|
-
if (!parsedResult.operationName && this.info.operationType !== "all") {
|
|
101
|
-
const publicUrl = (0, import_getPublicUrlFromRequest.getPublicUrlFromRequest)(request);
|
|
102
|
-
import_devUtils.devUtils.warn(`Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
101
|
+
if (!args.parsedResult.operationName && this.info.operationType !== "all") {
|
|
102
|
+
const publicUrl = (0, import_getPublicUrlFromRequest.getPublicUrlFromRequest)(args.request);
|
|
103
|
+
import_devUtils.devUtils.warn(`Failed to intercept a GraphQL request at "${args.request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
103
104
|
|
|
104
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/operation`);
|
|
105
106
|
return false;
|
|
106
107
|
}
|
|
107
|
-
const hasMatchingUrl = (0, import_matchRequestUrl.matchRequestUrl)(
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
const hasMatchingUrl = (0, import_matchRequestUrl.matchRequestUrl)(
|
|
109
|
+
new URL(args.request.url),
|
|
110
|
+
this.endpoint
|
|
111
|
+
);
|
|
112
|
+
const hasMatchingOperationType = this.info.operationType === "all" || args.parsedResult.operationType === this.info.operationType;
|
|
113
|
+
const hasMatchingOperationName = this.info.operationName instanceof RegExp ? this.info.operationName.test(args.parsedResult.operationName || "") : args.parsedResult.operationName === this.info.operationName;
|
|
110
114
|
return hasMatchingUrl.matches && hasMatchingOperationType && hasMatchingOperationName;
|
|
111
115
|
}
|
|
112
|
-
|
|
116
|
+
extendResolverArgs(args) {
|
|
117
|
+
var _a, _b, _c;
|
|
113
118
|
return {
|
|
114
|
-
query: (parsedResult == null ? void 0 :
|
|
115
|
-
operationName: (parsedResult == null ? void 0 :
|
|
116
|
-
variables: (parsedResult == null ? void 0 :
|
|
119
|
+
query: ((_a = args.parsedResult) == null ? void 0 : _a.query) || "",
|
|
120
|
+
operationName: ((_b = args.parsedResult) == null ? void 0 : _b.operationName) || "",
|
|
121
|
+
variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {}
|
|
117
122
|
};
|
|
118
123
|
}
|
|
119
|
-
log(
|
|
124
|
+
log(args) {
|
|
120
125
|
return __async(this, null, function* () {
|
|
121
|
-
|
|
122
|
-
const
|
|
126
|
+
var _a, _b, _c, _d;
|
|
127
|
+
const loggedRequest = yield (0, import_serializeRequest.serializeRequest)(args.request);
|
|
128
|
+
const loggedResponse = yield (0, import_serializeResponse.serializeResponse)(args.response);
|
|
123
129
|
const statusColor = (0, import_getStatusCodeColor.getStatusCodeColor)(loggedResponse.status);
|
|
124
|
-
const requestInfo = (
|
|
130
|
+
const requestInfo = ((_a = args.parsedResult) == null ? void 0 : _a.operationName) ? `${(_b = args.parsedResult) == null ? void 0 : _b.operationType} ${(_c = args.parsedResult) == null ? void 0 : _c.operationName}` : `anonymous ${(_d = args.parsedResult) == null ? void 0 : _d.operationType}`;
|
|
125
131
|
console.groupCollapsed(
|
|
126
132
|
import_devUtils.devUtils.formatMessage("%s %s (%c%s%c)"),
|
|
127
133
|
(0, import_getTimestamp.getTimestamp)(),
|
|
@@ -39,7 +39,7 @@ function isDocumentNode(value) {
|
|
|
39
39
|
return typeof value === "object" && "kind" in value && "definitions" in value;
|
|
40
40
|
}
|
|
41
41
|
class GraphQLHandler extends RequestHandler {
|
|
42
|
-
constructor(operationType, operationName, endpoint, resolver) {
|
|
42
|
+
constructor(operationType, operationName, endpoint, resolver, options) {
|
|
43
43
|
let resolvedOperationName = operationName;
|
|
44
44
|
if (isDocumentNode(operationName)) {
|
|
45
45
|
const parsedNode = parseDocumentNode(operationName);
|
|
@@ -62,47 +62,53 @@ class GraphQLHandler extends RequestHandler {
|
|
|
62
62
|
operationType,
|
|
63
63
|
operationName: resolvedOperationName
|
|
64
64
|
},
|
|
65
|
-
resolver
|
|
65
|
+
resolver,
|
|
66
|
+
options
|
|
66
67
|
});
|
|
67
68
|
this.endpoint = endpoint;
|
|
68
69
|
}
|
|
69
|
-
parse(
|
|
70
|
+
parse(args) {
|
|
70
71
|
return __async(this, null, function* () {
|
|
71
|
-
return parseGraphQLRequest(request).catch((error) => {
|
|
72
|
+
return parseGraphQLRequest(args.request).catch((error) => {
|
|
72
73
|
console.error(error);
|
|
73
74
|
return void 0;
|
|
74
75
|
});
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
|
-
predicate(
|
|
78
|
-
if (!parsedResult) {
|
|
78
|
+
predicate(args) {
|
|
79
|
+
if (!args.parsedResult) {
|
|
79
80
|
return false;
|
|
80
81
|
}
|
|
81
|
-
if (!parsedResult.operationName && this.info.operationType !== "all") {
|
|
82
|
-
const publicUrl = getPublicUrlFromRequest(request);
|
|
83
|
-
devUtils.warn(`Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
82
|
+
if (!args.parsedResult.operationName && this.info.operationType !== "all") {
|
|
83
|
+
const publicUrl = getPublicUrlFromRequest(args.request);
|
|
84
|
+
devUtils.warn(`Failed to intercept a GraphQL request at "${args.request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
84
85
|
|
|
85
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/operation`);
|
|
86
87
|
return false;
|
|
87
88
|
}
|
|
88
|
-
const hasMatchingUrl = matchRequestUrl(
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
const hasMatchingUrl = matchRequestUrl(
|
|
90
|
+
new URL(args.request.url),
|
|
91
|
+
this.endpoint
|
|
92
|
+
);
|
|
93
|
+
const hasMatchingOperationType = this.info.operationType === "all" || args.parsedResult.operationType === this.info.operationType;
|
|
94
|
+
const hasMatchingOperationName = this.info.operationName instanceof RegExp ? this.info.operationName.test(args.parsedResult.operationName || "") : args.parsedResult.operationName === this.info.operationName;
|
|
91
95
|
return hasMatchingUrl.matches && hasMatchingOperationType && hasMatchingOperationName;
|
|
92
96
|
}
|
|
93
|
-
|
|
97
|
+
extendResolverArgs(args) {
|
|
98
|
+
var _a, _b, _c;
|
|
94
99
|
return {
|
|
95
|
-
query: (parsedResult == null ? void 0 :
|
|
96
|
-
operationName: (parsedResult == null ? void 0 :
|
|
97
|
-
variables: (parsedResult == null ? void 0 :
|
|
100
|
+
query: ((_a = args.parsedResult) == null ? void 0 : _a.query) || "",
|
|
101
|
+
operationName: ((_b = args.parsedResult) == null ? void 0 : _b.operationName) || "",
|
|
102
|
+
variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {}
|
|
98
103
|
};
|
|
99
104
|
}
|
|
100
|
-
log(
|
|
105
|
+
log(args) {
|
|
101
106
|
return __async(this, null, function* () {
|
|
102
|
-
|
|
103
|
-
const
|
|
107
|
+
var _a, _b, _c, _d;
|
|
108
|
+
const loggedRequest = yield serializeRequest(args.request);
|
|
109
|
+
const loggedResponse = yield serializeResponse(args.response);
|
|
104
110
|
const statusColor = getStatusCodeColor(loggedResponse.status);
|
|
105
|
-
const requestInfo = (
|
|
111
|
+
const requestInfo = ((_a = args.parsedResult) == null ? void 0 : _a.operationName) ? `${(_b = args.parsedResult) == null ? void 0 : _b.operationType} ${(_c = args.parsedResult) == null ? void 0 : _c.operationName}` : `anonymous ${(_d = args.parsedResult) == null ? void 0 : _d.operationType}`;
|
|
106
112
|
console.groupCollapsed(
|
|
107
113
|
devUtils.formatMessage("%s %s (%c%s%c)"),
|
|
108
114
|
getTimestamp(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as RequestHandlerDefaultInfo, R as RequestHandler, a as ResponseResolver, f as
|
|
1
|
+
import { g as RequestHandlerDefaultInfo, R as RequestHandler, a as ResponseResolver, f as RequestHandlerOptions, i as ResponseResolutionContext } from '../RequestHandler-b59044ae.js';
|
|
2
2
|
import { Path, Match, PathParams } from '../utils/matching/matchRequestUrl.js';
|
|
3
3
|
import '../typeUtils.js';
|
|
4
4
|
|
|
@@ -32,19 +32,31 @@ type HttpRequestResolverExtras<Params extends PathParams> = {
|
|
|
32
32
|
* Provides request matching based on method and URL.
|
|
33
33
|
*/
|
|
34
34
|
declare class HttpHandler extends RequestHandler<HttpHandlerInfo, HttpRequestParsedResult, HttpRequestResolverExtras<any>> {
|
|
35
|
-
constructor(method: HttpHandlerMethod, path: Path, resolver: ResponseResolver<HttpRequestResolverExtras<any>, any, any>, options?:
|
|
35
|
+
constructor(method: HttpHandlerMethod, path: Path, resolver: ResponseResolver<HttpRequestResolverExtras<any>, any, any>, options?: RequestHandlerOptions);
|
|
36
36
|
private checkRedundantQueryParameters;
|
|
37
|
-
parse(
|
|
37
|
+
parse(args: {
|
|
38
|
+
request: Request;
|
|
39
|
+
resolutionContext?: ResponseResolutionContext;
|
|
40
|
+
}): Promise<{
|
|
38
41
|
match: Match;
|
|
39
42
|
cookies: Record<string, string>;
|
|
40
43
|
}>;
|
|
41
|
-
predicate(
|
|
44
|
+
predicate(args: {
|
|
45
|
+
request: Request;
|
|
46
|
+
parsedResult: HttpRequestParsedResult;
|
|
47
|
+
}): boolean;
|
|
42
48
|
private matchMethod;
|
|
43
|
-
protected
|
|
49
|
+
protected extendResolverArgs(args: {
|
|
50
|
+
request: Request;
|
|
51
|
+
parsedResult: HttpRequestParsedResult;
|
|
52
|
+
}): {
|
|
44
53
|
params: PathParams<string>;
|
|
45
54
|
cookies: Record<string, string>;
|
|
46
55
|
};
|
|
47
|
-
log(
|
|
56
|
+
log(args: {
|
|
57
|
+
request: Request;
|
|
58
|
+
response: Response;
|
|
59
|
+
}): Promise<void>;
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
export { HttpHandler, HttpHandlerInfo, HttpMethods, HttpRequestParsedResult, HttpRequestResolverExtras, RequestQuery };
|
|
@@ -72,7 +72,7 @@ class HttpHandler extends import_RequestHandler.RequestHandler {
|
|
|
72
72
|
method
|
|
73
73
|
},
|
|
74
74
|
resolver,
|
|
75
|
-
|
|
75
|
+
options
|
|
76
76
|
});
|
|
77
77
|
this.checkRedundantQueryParameters();
|
|
78
78
|
}
|
|
@@ -94,46 +94,47 @@ class HttpHandler extends import_RequestHandler.RequestHandler {
|
|
|
94
94
|
`Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead and access query parameters in the response resolver function using "req.url.searchParams".`
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
|
-
parse(
|
|
97
|
+
parse(args) {
|
|
98
98
|
return __async(this, null, function* () {
|
|
99
|
-
|
|
99
|
+
var _a;
|
|
100
|
+
const url = new URL(args.request.url);
|
|
100
101
|
const match = (0, import_matchRequestUrl.matchRequestUrl)(
|
|
101
102
|
url,
|
|
102
103
|
this.info.path,
|
|
103
|
-
resolutionContext == null ? void 0 :
|
|
104
|
+
(_a = args.resolutionContext) == null ? void 0 : _a.baseUrl
|
|
104
105
|
);
|
|
105
|
-
const cookies = (0, import_getRequestCookies.getAllRequestCookies)(request);
|
|
106
|
+
const cookies = (0, import_getRequestCookies.getAllRequestCookies)(args.request);
|
|
106
107
|
return {
|
|
107
108
|
match,
|
|
108
109
|
cookies
|
|
109
110
|
};
|
|
110
111
|
});
|
|
111
112
|
}
|
|
112
|
-
predicate(
|
|
113
|
-
const hasMatchingMethod = this.matchMethod(request.method);
|
|
114
|
-
const hasMatchingUrl = parsedResult.match.matches;
|
|
113
|
+
predicate(args) {
|
|
114
|
+
const hasMatchingMethod = this.matchMethod(args.request.method);
|
|
115
|
+
const hasMatchingUrl = args.parsedResult.match.matches;
|
|
115
116
|
return hasMatchingMethod && hasMatchingUrl;
|
|
116
117
|
}
|
|
117
118
|
matchMethod(actualMethod) {
|
|
118
119
|
return this.info.method instanceof RegExp ? this.info.method.test(actualMethod) : (0, import_isStringEqual.isStringEqual)(this.info.method, actualMethod);
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
+
extendResolverArgs(args) {
|
|
121
122
|
var _a;
|
|
122
123
|
return {
|
|
123
|
-
params: ((_a = parsedResult.match) == null ? void 0 : _a.params) || {},
|
|
124
|
-
cookies: parsedResult.cookies
|
|
124
|
+
params: ((_a = args.parsedResult.match) == null ? void 0 : _a.params) || {},
|
|
125
|
+
cookies: args.parsedResult.cookies
|
|
125
126
|
};
|
|
126
127
|
}
|
|
127
|
-
log(
|
|
128
|
+
log(args) {
|
|
128
129
|
return __async(this, null, function* () {
|
|
129
|
-
const publicUrl = (0, import_getPublicUrlFromRequest.getPublicUrlFromRequest)(request);
|
|
130
|
-
const loggedRequest = yield (0, import_serializeRequest.serializeRequest)(request);
|
|
131
|
-
const loggedResponse = yield (0, import_serializeResponse.serializeResponse)(response);
|
|
130
|
+
const publicUrl = (0, import_getPublicUrlFromRequest.getPublicUrlFromRequest)(args.request);
|
|
131
|
+
const loggedRequest = yield (0, import_serializeRequest.serializeRequest)(args.request);
|
|
132
|
+
const loggedResponse = yield (0, import_serializeResponse.serializeResponse)(args.response);
|
|
132
133
|
const statusColor = (0, import_getStatusCodeColor.getStatusCodeColor)(loggedResponse.status);
|
|
133
134
|
console.groupCollapsed(
|
|
134
135
|
import_devUtils.devUtils.formatMessage("%s %s %s (%c%s%c)"),
|
|
135
136
|
(0, import_getTimestamp.getTimestamp)(),
|
|
136
|
-
request.method,
|
|
137
|
+
args.request.method,
|
|
137
138
|
publicUrl,
|
|
138
139
|
`color:${statusColor}`,
|
|
139
140
|
`${loggedResponse.status} ${loggedResponse.statusText}`,
|