msw 2.12.6 → 2.12.7
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/{HttpResponse-DM21DMt_.d.ts → HttpResponse-CVs3ngx3.d.ts} +12 -2
- package/lib/core/{HttpResponse-C86fdZzb.d.mts → HttpResponse-Cw4ELwIN.d.mts} +12 -2
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +21 -59
- package/lib/core/graphql.d.ts +21 -59
- package/lib/core/graphql.js +14 -15
- package/lib/core/graphql.js.map +1 -1
- package/lib/core/graphql.mjs +14 -15
- package/lib/core/graphql.mjs.map +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.js +42 -17
- package/lib/core/handlers/GraphQLHandler.js.map +1 -1
- package/lib/core/handlers/GraphQLHandler.mjs +44 -17
- 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/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +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/index.js.map +1 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/sse.d.mts +1 -1
- package/lib/core/sse.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/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
- package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +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/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/iife/index.js +57 -32
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/graphql.ts +43 -52
- package/src/core/handlers/GraphQLHandler.test.ts +1 -1
- package/src/core/handlers/GraphQLHandler.ts +73 -25
- package/src/core/index.ts +6 -1
|
@@ -52,6 +52,15 @@ type GraphQLMultipartRequestBody = {
|
|
|
52
52
|
*/
|
|
53
53
|
declare function parseGraphQLRequest(request: Request): Promise<ParsedGraphQLRequest>;
|
|
54
54
|
|
|
55
|
+
interface DocumentTypeDecoration<Result = {
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
}, Variables = {
|
|
58
|
+
[key: string]: any;
|
|
59
|
+
}> {
|
|
60
|
+
__apiType?: (variables: Variables) => Result;
|
|
61
|
+
__resultType?: Result;
|
|
62
|
+
__variablesType?: Variables;
|
|
63
|
+
}
|
|
55
64
|
type GraphQLOperationType = OperationTypeNode | 'all';
|
|
56
65
|
type GraphQLHandlerNameSelector = DocumentNode | RegExp | string;
|
|
57
66
|
type GraphQLQuery = Record<string, any> | null;
|
|
@@ -102,9 +111,10 @@ type GraphQLCustomPredicate = (args: {
|
|
|
102
111
|
type GraphQLCustomPredicateResult = boolean | {
|
|
103
112
|
matches: boolean;
|
|
104
113
|
};
|
|
105
|
-
type GraphQLPredicate = GraphQLHandlerNameSelector | GraphQLCustomPredicate;
|
|
114
|
+
type GraphQLPredicate<Query = any, Variables = any> = GraphQLHandlerNameSelector | DocumentTypeDecoration<Query, Variables> | GraphQLCustomPredicate;
|
|
106
115
|
declare function isDocumentNode(value: DocumentNode | any): value is DocumentNode;
|
|
107
116
|
declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, GraphQLRequestParsedResult, GraphQLResolverExtras<any>> {
|
|
117
|
+
#private;
|
|
108
118
|
private endpoint;
|
|
109
119
|
static parsedRequestCache: WeakMap<Request, ParsedGraphQLRequest<GraphQLVariables>>;
|
|
110
120
|
constructor(operationType: GraphQLOperationType, predicate: GraphQLPredicate, endpoint: Path, resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>, options?: RequestHandlerOptions);
|
|
@@ -319,4 +329,4 @@ declare class HttpResponse<BodyType extends DefaultBodyType> extends FetchRespon
|
|
|
319
329
|
static formData(body?: FormData, init?: HttpResponseInit): HttpResponse<FormData>;
|
|
320
330
|
}
|
|
321
331
|
|
|
322
|
-
export { type AsyncResponseResolverReturnType as A, parseGraphQLRequest as B, type
|
|
332
|
+
export { type AsyncResponseResolverReturnType as A, parseGraphQLRequest as B, type DocumentTypeDecoration as C, type DefaultBodyType as D, type GraphQLHandlerNameSelector as E, type GraphQLHandlerInfo as F, GraphQLHandler as G, type HttpResponseInit as H, type GraphQLRequestParsedResult as I, type JsonBodyType as J, type GraphQLCustomPredicateResult as K, isDocumentNode as L, type RequestHandlerInternalInfo as M, type MaybeAsyncResponseResolverReturnType as N, type RequestHandlerArgs as O, type ParsedGraphQLRequest as P, type RequestHandlerExecutionResult as Q, RequestHandler as R, type StrictRequest as S, type ResponseResolver as a, type ResponseResolverReturnType as b, type RequestHandlerOptions as c, type DefaultRequestMultipartBody as d, type ResponseResolverInfo as e, type GraphQLQuery as f, type GraphQLVariables as g, type GraphQLRequestBody as h, type GraphQLResponseBody as i, type GraphQLJsonRequestBody as j, type GraphQLOperationType as k, type GraphQLCustomPredicate as l, type ResponseResolutionContext as m, bodyType as n, type DefaultUnsafeFetchResponse as o, type StrictResponse as p, HttpResponse as q, type GraphQLPredicate as r, type GraphQLResolverExtras as s, type RequestHandlerDefaultInfo as t, type HandlersExecutionResult as u, executeHandlers as v, type ParsedGraphQLQuery as w, parseDocumentNode as x, type GraphQLParsedOperationsMap as y, type GraphQLMultipartRequestBody as z };
|
|
@@ -52,6 +52,15 @@ type GraphQLMultipartRequestBody = {
|
|
|
52
52
|
*/
|
|
53
53
|
declare function parseGraphQLRequest(request: Request): Promise<ParsedGraphQLRequest>;
|
|
54
54
|
|
|
55
|
+
interface DocumentTypeDecoration<Result = {
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
}, Variables = {
|
|
58
|
+
[key: string]: any;
|
|
59
|
+
}> {
|
|
60
|
+
__apiType?: (variables: Variables) => Result;
|
|
61
|
+
__resultType?: Result;
|
|
62
|
+
__variablesType?: Variables;
|
|
63
|
+
}
|
|
55
64
|
type GraphQLOperationType = OperationTypeNode | 'all';
|
|
56
65
|
type GraphQLHandlerNameSelector = DocumentNode | RegExp | string;
|
|
57
66
|
type GraphQLQuery = Record<string, any> | null;
|
|
@@ -102,9 +111,10 @@ type GraphQLCustomPredicate = (args: {
|
|
|
102
111
|
type GraphQLCustomPredicateResult = boolean | {
|
|
103
112
|
matches: boolean;
|
|
104
113
|
};
|
|
105
|
-
type GraphQLPredicate = GraphQLHandlerNameSelector | GraphQLCustomPredicate;
|
|
114
|
+
type GraphQLPredicate<Query = any, Variables = any> = GraphQLHandlerNameSelector | DocumentTypeDecoration<Query, Variables> | GraphQLCustomPredicate;
|
|
106
115
|
declare function isDocumentNode(value: DocumentNode | any): value is DocumentNode;
|
|
107
116
|
declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, GraphQLRequestParsedResult, GraphQLResolverExtras<any>> {
|
|
117
|
+
#private;
|
|
108
118
|
private endpoint;
|
|
109
119
|
static parsedRequestCache: WeakMap<Request, ParsedGraphQLRequest<GraphQLVariables>>;
|
|
110
120
|
constructor(operationType: GraphQLOperationType, predicate: GraphQLPredicate, endpoint: Path, resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>, options?: RequestHandlerOptions);
|
|
@@ -319,4 +329,4 @@ declare class HttpResponse<BodyType extends DefaultBodyType> extends FetchRespon
|
|
|
319
329
|
static formData(body?: FormData, init?: HttpResponseInit): HttpResponse<FormData>;
|
|
320
330
|
}
|
|
321
331
|
|
|
322
|
-
export { type AsyncResponseResolverReturnType as A, parseGraphQLRequest as B, type
|
|
332
|
+
export { type AsyncResponseResolverReturnType as A, parseGraphQLRequest as B, type DocumentTypeDecoration as C, type DefaultBodyType as D, type GraphQLHandlerNameSelector as E, type GraphQLHandlerInfo as F, GraphQLHandler as G, type HttpResponseInit as H, type GraphQLRequestParsedResult as I, type JsonBodyType as J, type GraphQLCustomPredicateResult as K, isDocumentNode as L, type RequestHandlerInternalInfo as M, type MaybeAsyncResponseResolverReturnType as N, type RequestHandlerArgs as O, type ParsedGraphQLRequest as P, type RequestHandlerExecutionResult as Q, RequestHandler as R, type StrictRequest as S, type ResponseResolver as a, type ResponseResolverReturnType as b, type RequestHandlerOptions as c, type DefaultRequestMultipartBody as d, type ResponseResolverInfo as e, type GraphQLQuery as f, type GraphQLVariables as g, type GraphQLRequestBody as h, type GraphQLResponseBody as i, type GraphQLJsonRequestBody as j, type GraphQLOperationType as k, type GraphQLCustomPredicate as l, type ResponseResolutionContext as m, bodyType as n, type DefaultUnsafeFetchResponse as o, type StrictResponse as p, HttpResponse as q, type GraphQLPredicate as r, type GraphQLResolverExtras as s, type RequestHandlerDefaultInfo as t, type HandlersExecutionResult as u, executeHandlers as v, type ParsedGraphQLQuery as w, parseDocumentNode as x, type GraphQLParsedOperationsMap as y, type GraphQLMultipartRequestBody as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@mswjs/interceptors';
|
|
2
|
-
export { o as DefaultUnsafeFetchResponse, q as HttpResponse, H as HttpResponseInit, S as StrictRequest, p as StrictResponse, n as bodyType } from './HttpResponse-
|
|
2
|
+
export { o as DefaultUnsafeFetchResponse, q as HttpResponse, H as HttpResponseInit, S as StrictRequest, p as StrictResponse, n as bodyType } from './HttpResponse-Cw4ELwIN.mjs';
|
|
3
3
|
import './typeUtils.mjs';
|
|
4
4
|
import './utils/internal/isIterable.mjs';
|
|
5
5
|
import 'graphql';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@mswjs/interceptors';
|
|
2
|
-
export { o as DefaultUnsafeFetchResponse, q as HttpResponse, H as HttpResponseInit, S as StrictRequest, p as StrictResponse, n as bodyType } from './HttpResponse-
|
|
2
|
+
export { o as DefaultUnsafeFetchResponse, q as HttpResponse, H as HttpResponseInit, S as StrictRequest, p as StrictResponse, n as bodyType } from './HttpResponse-CVs3ngx3.js';
|
|
3
3
|
import './typeUtils.js';
|
|
4
4
|
import './utils/internal/isIterable.js';
|
|
5
5
|
import 'graphql';
|
package/lib/core/SetupApi.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventMap, Emitter } from 'strict-event-emitter';
|
|
2
|
-
import { R as RequestHandler } from './HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from './HttpResponse-Cw4ELwIN.mjs';
|
|
3
3
|
import { LifeCycleEventEmitter } from './sharedOptions.mjs';
|
|
4
4
|
import { Disposable } from './utils/internal/Disposable.mjs';
|
|
5
5
|
import { WebSocketHandler } from './handlers/WebSocketHandler.mjs';
|
package/lib/core/SetupApi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventMap, Emitter } from 'strict-event-emitter';
|
|
2
|
-
import { R as RequestHandler } from './HttpResponse-
|
|
2
|
+
import { R as RequestHandler } from './HttpResponse-CVs3ngx3.js';
|
|
3
3
|
import { LifeCycleEventEmitter } from './sharedOptions.js';
|
|
4
4
|
import { Disposable } from './utils/internal/Disposable.js';
|
|
5
5
|
import { WebSocketHandler } from './handlers/WebSocketHandler.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler, m as ResponseResolutionContext } from './HttpResponse-
|
|
1
|
+
import { R as RequestHandler, m as ResponseResolutionContext } from './HttpResponse-Cw4ELwIN.mjs';
|
|
2
2
|
import '@mswjs/interceptors';
|
|
3
3
|
import './utils/internal/isIterable.mjs';
|
|
4
4
|
import './typeUtils.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestHandler, m as ResponseResolutionContext } from './HttpResponse-
|
|
1
|
+
import { R as RequestHandler, m as ResponseResolutionContext } from './HttpResponse-CVs3ngx3.js';
|
|
2
2
|
import '@mswjs/interceptors';
|
|
3
3
|
import './utils/internal/isIterable.js';
|
|
4
4
|
import './typeUtils.js';
|
package/lib/core/graphql.d.mts
CHANGED
|
@@ -1,60 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { f as GraphQLQuery, g as GraphQLVariables, r as GraphQLHandlerNameSelector, l as GraphQLCustomPredicate, a as ResponseResolver, s as GraphQLResolverExtras, i as GraphQLResponseBody, c as RequestHandlerOptions, G as GraphQLHandler } from './HttpResponse-C86fdZzb.mjs';
|
|
1
|
+
import { f as GraphQLQuery, g as GraphQLVariables, r as GraphQLPredicate, a as ResponseResolver, s as GraphQLResolverExtras, i as GraphQLResponseBody, c as RequestHandlerOptions, G as GraphQLHandler } from './HttpResponse-Cw4ELwIN.mjs';
|
|
3
2
|
import { Path } from './utils/matching/matchRequestUrl.mjs';
|
|
4
3
|
import '@mswjs/interceptors';
|
|
5
4
|
import './utils/internal/isIterable.mjs';
|
|
6
5
|
import './typeUtils.mjs';
|
|
6
|
+
import 'graphql';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}> extends DocumentNode {
|
|
13
|
-
__apiType?: (variables: Variables) => Result;
|
|
14
|
-
__resultType?: Result;
|
|
15
|
-
__variablesType?: Variables;
|
|
16
|
-
}
|
|
17
|
-
type GraphQLRequestHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(predicate: GraphQLHandlerNameSelector | DocumentNode | TypedDocumentNode<Query, Variables> | GraphQLCustomPredicate, resolver: GraphQLResponseResolver<[
|
|
8
|
+
type GraphQLRequestHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(predicate: GraphQLPredicate<Query, Variables>, resolver: GraphQLResponseResolver<[
|
|
9
|
+
Query
|
|
10
|
+
] extends [never] ? GraphQLQuery : Query, Variables>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
11
|
+
type GraphQLOperationHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(resolver: GraphQLResponseResolver<[
|
|
18
12
|
Query
|
|
19
13
|
] extends [never] ? GraphQLQuery : Query, Variables>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
20
14
|
type GraphQLResponseResolver<Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables> = ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<[Query] extends [never] ? GraphQLQuery : Query>>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Intercepts a GraphQL query by a given name.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* graphql.query('GetUser', () => {
|
|
27
|
-
* return HttpResponse.json({ data: { user: { name: 'John' } } })
|
|
28
|
-
* })
|
|
29
|
-
*
|
|
30
|
-
* @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
|
|
31
|
-
*/
|
|
15
|
+
interface GraphQLLinkHandlers {
|
|
32
16
|
query: GraphQLRequestHandler;
|
|
33
|
-
/**
|
|
34
|
-
* Intercepts a GraphQL mutation by its name.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* graphql.mutation('SavePost', () => {
|
|
38
|
-
* return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
|
|
39
|
-
* })
|
|
40
|
-
*
|
|
41
|
-
* @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
17
|
mutation: GraphQLRequestHandler;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* graphql.operation(() => {
|
|
50
|
-
* return HttpResponse.json({ data: { name: 'John' } })
|
|
51
|
-
* })
|
|
52
|
-
*
|
|
53
|
-
* @see {@link https://mswjs.io/docs/api/graphql#graphqloperationresolver `graphql.operation()` API reference}
|
|
54
|
-
*/
|
|
55
|
-
operation: <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>) => GraphQLHandler;
|
|
56
|
-
};
|
|
57
|
-
declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
|
|
18
|
+
operation: GraphQLOperationHandler;
|
|
19
|
+
}
|
|
58
20
|
/**
|
|
59
21
|
* A namespace to intercept and mock GraphQL operations
|
|
60
22
|
*
|
|
@@ -65,16 +27,6 @@ declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
|
|
|
65
27
|
* @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}
|
|
66
28
|
*/
|
|
67
29
|
declare const graphql: {
|
|
68
|
-
/**
|
|
69
|
-
* Intercepts GraphQL operations scoped by the given URL.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* const github = graphql.link('https://api.github.com/graphql')
|
|
73
|
-
* github.query('GetRepo', resolver)
|
|
74
|
-
*
|
|
75
|
-
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
76
|
-
*/
|
|
77
|
-
link: typeof createGraphQLLink;
|
|
78
30
|
/**
|
|
79
31
|
* Intercepts a GraphQL query by a given name.
|
|
80
32
|
*
|
|
@@ -108,7 +60,17 @@ declare const graphql: {
|
|
|
108
60
|
*
|
|
109
61
|
* @see {@link https://mswjs.io/docs/api/graphql#graphqloperationresolver `graphql.operation()` API reference}
|
|
110
62
|
*/
|
|
111
|
-
operation:
|
|
63
|
+
operation: GraphQLOperationHandler;
|
|
64
|
+
/**
|
|
65
|
+
* Intercepts GraphQL operations scoped by the given URL.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const github = graphql.link('https://api.github.com/graphql')
|
|
69
|
+
* github.query('GetRepo', resolver)
|
|
70
|
+
*
|
|
71
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
72
|
+
*/
|
|
73
|
+
link(url: Path): GraphQLLinkHandlers;
|
|
112
74
|
};
|
|
113
75
|
|
|
114
|
-
export { type
|
|
76
|
+
export { type GraphQLLinkHandlers, type GraphQLOperationHandler, type GraphQLRequestHandler, type GraphQLResponseResolver, graphql };
|
package/lib/core/graphql.d.ts
CHANGED
|
@@ -1,60 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { f as GraphQLQuery, g as GraphQLVariables, r as GraphQLHandlerNameSelector, l as GraphQLCustomPredicate, a as ResponseResolver, s as GraphQLResolverExtras, i as GraphQLResponseBody, c as RequestHandlerOptions, G as GraphQLHandler } from './HttpResponse-DM21DMt_.js';
|
|
1
|
+
import { f as GraphQLQuery, g as GraphQLVariables, r as GraphQLPredicate, a as ResponseResolver, s as GraphQLResolverExtras, i as GraphQLResponseBody, c as RequestHandlerOptions, G as GraphQLHandler } from './HttpResponse-CVs3ngx3.js';
|
|
3
2
|
import { Path } from './utils/matching/matchRequestUrl.js';
|
|
4
3
|
import '@mswjs/interceptors';
|
|
5
4
|
import './utils/internal/isIterable.js';
|
|
6
5
|
import './typeUtils.js';
|
|
6
|
+
import 'graphql';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}> extends DocumentNode {
|
|
13
|
-
__apiType?: (variables: Variables) => Result;
|
|
14
|
-
__resultType?: Result;
|
|
15
|
-
__variablesType?: Variables;
|
|
16
|
-
}
|
|
17
|
-
type GraphQLRequestHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(predicate: GraphQLHandlerNameSelector | DocumentNode | TypedDocumentNode<Query, Variables> | GraphQLCustomPredicate, resolver: GraphQLResponseResolver<[
|
|
8
|
+
type GraphQLRequestHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(predicate: GraphQLPredicate<Query, Variables>, resolver: GraphQLResponseResolver<[
|
|
9
|
+
Query
|
|
10
|
+
] extends [never] ? GraphQLQuery : Query, Variables>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
11
|
+
type GraphQLOperationHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(resolver: GraphQLResponseResolver<[
|
|
18
12
|
Query
|
|
19
13
|
] extends [never] ? GraphQLQuery : Query, Variables>, options?: RequestHandlerOptions) => GraphQLHandler;
|
|
20
14
|
type GraphQLResponseResolver<Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables> = ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<[Query] extends [never] ? GraphQLQuery : Query>>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Intercepts a GraphQL query by a given name.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* graphql.query('GetUser', () => {
|
|
27
|
-
* return HttpResponse.json({ data: { user: { name: 'John' } } })
|
|
28
|
-
* })
|
|
29
|
-
*
|
|
30
|
-
* @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
|
|
31
|
-
*/
|
|
15
|
+
interface GraphQLLinkHandlers {
|
|
32
16
|
query: GraphQLRequestHandler;
|
|
33
|
-
/**
|
|
34
|
-
* Intercepts a GraphQL mutation by its name.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* graphql.mutation('SavePost', () => {
|
|
38
|
-
* return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
|
|
39
|
-
* })
|
|
40
|
-
*
|
|
41
|
-
* @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
17
|
mutation: GraphQLRequestHandler;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* graphql.operation(() => {
|
|
50
|
-
* return HttpResponse.json({ data: { name: 'John' } })
|
|
51
|
-
* })
|
|
52
|
-
*
|
|
53
|
-
* @see {@link https://mswjs.io/docs/api/graphql#graphqloperationresolver `graphql.operation()` API reference}
|
|
54
|
-
*/
|
|
55
|
-
operation: <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>) => GraphQLHandler;
|
|
56
|
-
};
|
|
57
|
-
declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
|
|
18
|
+
operation: GraphQLOperationHandler;
|
|
19
|
+
}
|
|
58
20
|
/**
|
|
59
21
|
* A namespace to intercept and mock GraphQL operations
|
|
60
22
|
*
|
|
@@ -65,16 +27,6 @@ declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
|
|
|
65
27
|
* @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}
|
|
66
28
|
*/
|
|
67
29
|
declare const graphql: {
|
|
68
|
-
/**
|
|
69
|
-
* Intercepts GraphQL operations scoped by the given URL.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* const github = graphql.link('https://api.github.com/graphql')
|
|
73
|
-
* github.query('GetRepo', resolver)
|
|
74
|
-
*
|
|
75
|
-
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
76
|
-
*/
|
|
77
|
-
link: typeof createGraphQLLink;
|
|
78
30
|
/**
|
|
79
31
|
* Intercepts a GraphQL query by a given name.
|
|
80
32
|
*
|
|
@@ -108,7 +60,17 @@ declare const graphql: {
|
|
|
108
60
|
*
|
|
109
61
|
* @see {@link https://mswjs.io/docs/api/graphql#graphqloperationresolver `graphql.operation()` API reference}
|
|
110
62
|
*/
|
|
111
|
-
operation:
|
|
63
|
+
operation: GraphQLOperationHandler;
|
|
64
|
+
/**
|
|
65
|
+
* Intercepts GraphQL operations scoped by the given URL.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const github = graphql.link('https://api.github.com/graphql')
|
|
69
|
+
* github.query('GetRepo', resolver)
|
|
70
|
+
*
|
|
71
|
+
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
72
|
+
*/
|
|
73
|
+
link(url: Path): GraphQLLinkHandlers;
|
|
112
74
|
};
|
|
113
75
|
|
|
114
|
-
export { type
|
|
76
|
+
export { type GraphQLLinkHandlers, type GraphQLOperationHandler, type GraphQLRequestHandler, type GraphQLResponseResolver, graphql };
|
package/lib/core/graphql.js
CHANGED
|
@@ -28,11 +28,11 @@ function createScopedGraphQLHandler(operationType, url) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
function createGraphQLOperationHandler(url) {
|
|
31
|
-
return (resolver) => {
|
|
32
|
-
return new import_GraphQLHandler.GraphQLHandler("all", new RegExp(".*"), url, resolver);
|
|
31
|
+
return (resolver, options) => {
|
|
32
|
+
return new import_GraphQLHandler.GraphQLHandler("all", new RegExp(".*"), url, resolver, options);
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const graphql = {
|
|
36
36
|
/**
|
|
37
37
|
* Intercepts a GraphQL query by a given name.
|
|
38
38
|
*
|
|
@@ -66,17 +66,7 @@ const standardGraphQLHandlers = {
|
|
|
66
66
|
*
|
|
67
67
|
* @see {@link https://mswjs.io/docs/api/graphql#graphqloperationresolver `graphql.operation()` API reference}
|
|
68
68
|
*/
|
|
69
|
-
operation: createGraphQLOperationHandler("*")
|
|
70
|
-
};
|
|
71
|
-
function createGraphQLLink(url) {
|
|
72
|
-
return {
|
|
73
|
-
operation: createGraphQLOperationHandler(url),
|
|
74
|
-
query: createScopedGraphQLHandler("query", url),
|
|
75
|
-
mutation: createScopedGraphQLHandler("mutation", url)
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
const graphql = {
|
|
79
|
-
...standardGraphQLHandlers,
|
|
69
|
+
operation: createGraphQLOperationHandler("*"),
|
|
80
70
|
/**
|
|
81
71
|
* Intercepts GraphQL operations scoped by the given URL.
|
|
82
72
|
*
|
|
@@ -86,6 +76,15 @@ const graphql = {
|
|
|
86
76
|
*
|
|
87
77
|
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
88
78
|
*/
|
|
89
|
-
link
|
|
79
|
+
link(url) {
|
|
80
|
+
return {
|
|
81
|
+
operation: createGraphQLOperationHandler(url),
|
|
82
|
+
query: createScopedGraphQLHandler("query", url),
|
|
83
|
+
mutation: createScopedGraphQLHandler(
|
|
84
|
+
"mutation",
|
|
85
|
+
url
|
|
86
|
+
)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
90
89
|
};
|
|
91
90
|
//# sourceMappingURL=graphql.js.map
|
package/lib/core/graphql.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type { OperationTypeNode } from 'graphql'\nimport {\n ResponseResolver,\n RequestHandlerOptions,\n} from './handlers/RequestHandler'\nimport {\n GraphQLHandler,\n GraphQLVariables,\n GraphQLOperationType,\n GraphQLResolverExtras,\n GraphQLResponseBody,\n GraphQLQuery,\n GraphQLPredicate,\n} from './handlers/GraphQLHandler'\nimport type { Path } from './utils/matching/matchRequestUrl'\n\nexport type GraphQLRequestHandler = <\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n>(\n predicate: GraphQLPredicate<Query, Variables>,\n resolver: GraphQLResponseResolver<\n [Query] extends [never] ? GraphQLQuery : Query,\n Variables\n >,\n options?: RequestHandlerOptions,\n) => GraphQLHandler\n\nexport type GraphQLOperationHandler = <\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n>(\n resolver: GraphQLResponseResolver<\n [Query] extends [never] ? GraphQLQuery : Query,\n Variables\n >,\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] extends [never] ? GraphQLQuery : Query>\n>\n\nfunction createScopedGraphQLHandler(\n operationType: GraphQLOperationType,\n url: Path,\n): GraphQLRequestHandler {\n return (predicate, resolver, options = {}) => {\n return new GraphQLHandler(operationType, predicate, url, resolver, options)\n }\n}\n\nfunction createGraphQLOperationHandler(url: Path): GraphQLOperationHandler {\n return (resolver, options) => {\n return new GraphQLHandler('all', new RegExp('.*'), url, resolver, options)\n }\n}\n\nexport interface GraphQLLinkHandlers {\n query: GraphQLRequestHandler\n mutation: GraphQLRequestHandler\n operation: GraphQLOperationHandler\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 /**\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#graphqloperationresolver `graphql.operation()` API reference}\n */\n operation: createGraphQLOperationHandler('*'),\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(url: Path): GraphQLLinkHandlers {\n return {\n operation: createGraphQLOperationHandler(url),\n query: createScopedGraphQLHandler('query' as OperationTypeNode, url),\n mutation: createScopedGraphQLHandler(\n 'mutation' as OperationTypeNode,\n url,\n ),\n }\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,4BAQO;AAmCP,SAAS,2BACP,eACA,KACuB;AACvB,SAAO,CAAC,WAAW,UAAU,UAAU,CAAC,MAAM;AAC5C,WAAO,IAAI,qCAAe,eAAe,WAAW,KAAK,UAAU,OAAO;AAAA,EAC5E;AACF;AAEA,SAAS,8BAA8B,KAAoC;AACzE,SAAO,CAAC,UAAU,YAAY;AAC5B,WAAO,IAAI,qCAAe,OAAO,IAAI,OAAO,IAAI,GAAG,KAAK,UAAU,OAAO;AAAA,EAC3E;AACF;AAiBO,MAAM,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWrB,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW5C,KAAK,KAAgC;AACnC,WAAO;AAAA,MACL,WAAW,8BAA8B,GAAG;AAAA,MAC5C,OAAO,2BAA2B,SAA8B,GAAG;AAAA,MACnE,UAAU;AAAA,QACR;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/lib/core/graphql.mjs
CHANGED
|
@@ -7,11 +7,11 @@ function createScopedGraphQLHandler(operationType, url) {
|
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
function createGraphQLOperationHandler(url) {
|
|
10
|
-
return (resolver) => {
|
|
11
|
-
return new GraphQLHandler("all", new RegExp(".*"), url, resolver);
|
|
10
|
+
return (resolver, options) => {
|
|
11
|
+
return new GraphQLHandler("all", new RegExp(".*"), url, resolver, options);
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
const
|
|
14
|
+
const graphql = {
|
|
15
15
|
/**
|
|
16
16
|
* Intercepts a GraphQL query by a given name.
|
|
17
17
|
*
|
|
@@ -45,17 +45,7 @@ const standardGraphQLHandlers = {
|
|
|
45
45
|
*
|
|
46
46
|
* @see {@link https://mswjs.io/docs/api/graphql#graphqloperationresolver `graphql.operation()` API reference}
|
|
47
47
|
*/
|
|
48
|
-
operation: createGraphQLOperationHandler("*")
|
|
49
|
-
};
|
|
50
|
-
function createGraphQLLink(url) {
|
|
51
|
-
return {
|
|
52
|
-
operation: createGraphQLOperationHandler(url),
|
|
53
|
-
query: createScopedGraphQLHandler("query", url),
|
|
54
|
-
mutation: createScopedGraphQLHandler("mutation", url)
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const graphql = {
|
|
58
|
-
...standardGraphQLHandlers,
|
|
48
|
+
operation: createGraphQLOperationHandler("*"),
|
|
59
49
|
/**
|
|
60
50
|
* Intercepts GraphQL operations scoped by the given URL.
|
|
61
51
|
*
|
|
@@ -65,7 +55,16 @@ const graphql = {
|
|
|
65
55
|
*
|
|
66
56
|
* @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
|
|
67
57
|
*/
|
|
68
|
-
link
|
|
58
|
+
link(url) {
|
|
59
|
+
return {
|
|
60
|
+
operation: createGraphQLOperationHandler(url),
|
|
61
|
+
query: createScopedGraphQLHandler("query", url),
|
|
62
|
+
mutation: createScopedGraphQLHandler(
|
|
63
|
+
"mutation",
|
|
64
|
+
url
|
|
65
|
+
)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
69
68
|
};
|
|
70
69
|
export {
|
|
71
70
|
graphql
|
package/lib/core/graphql.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/core/graphql.ts"],"sourcesContent":["import type { OperationTypeNode } from 'graphql'\nimport {\n ResponseResolver,\n RequestHandlerOptions,\n} from './handlers/RequestHandler'\nimport {\n GraphQLHandler,\n GraphQLVariables,\n GraphQLOperationType,\n GraphQLResolverExtras,\n GraphQLResponseBody,\n GraphQLQuery,\n GraphQLPredicate,\n} from './handlers/GraphQLHandler'\nimport type { Path } from './utils/matching/matchRequestUrl'\n\nexport type GraphQLRequestHandler = <\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n>(\n predicate: GraphQLPredicate<Query, Variables>,\n resolver: GraphQLResponseResolver<\n [Query] extends [never] ? GraphQLQuery : Query,\n Variables\n >,\n options?: RequestHandlerOptions,\n) => GraphQLHandler\n\nexport type GraphQLOperationHandler = <\n Query extends GraphQLQuery = GraphQLQuery,\n Variables extends GraphQLVariables = GraphQLVariables,\n>(\n resolver: GraphQLResponseResolver<\n [Query] extends [never] ? GraphQLQuery : Query,\n Variables\n >,\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] extends [never] ? GraphQLQuery : Query>\n>\n\nfunction createScopedGraphQLHandler(\n operationType: GraphQLOperationType,\n url: Path,\n): GraphQLRequestHandler {\n return (predicate, resolver, options = {}) => {\n return new GraphQLHandler(operationType, predicate, url, resolver, options)\n }\n}\n\nfunction createGraphQLOperationHandler(url: Path): GraphQLOperationHandler {\n return (resolver, options) => {\n return new GraphQLHandler('all', new RegExp('.*'), url, resolver, options)\n }\n}\n\nexport interface GraphQLLinkHandlers {\n query: GraphQLRequestHandler\n mutation: GraphQLRequestHandler\n operation: GraphQLOperationHandler\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 /**\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#graphqloperationresolver `graphql.operation()` API reference}\n */\n operation: createGraphQLOperationHandler('*'),\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(url: Path): GraphQLLinkHandlers {\n return {\n operation: createGraphQLOperationHandler(url),\n query: createScopedGraphQLHandler('query' as OperationTypeNode, url),\n mutation: createScopedGraphQLHandler(\n 'mutation' as OperationTypeNode,\n url,\n ),\n }\n },\n}\n"],"mappings":"AAKA;AAAA,EACE;AAAA,OAOK;AAmCP,SAAS,2BACP,eACA,KACuB;AACvB,SAAO,CAAC,WAAW,UAAU,UAAU,CAAC,MAAM;AAC5C,WAAO,IAAI,eAAe,eAAe,WAAW,KAAK,UAAU,OAAO;AAAA,EAC5E;AACF;AAEA,SAAS,8BAA8B,KAAoC;AACzE,SAAO,CAAC,UAAU,YAAY;AAC5B,WAAO,IAAI,eAAe,OAAO,IAAI,OAAO,IAAI,GAAG,KAAK,UAAU,OAAO;AAAA,EAC3E;AACF;AAiBO,MAAM,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWrB,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW5C,KAAK,KAAgC;AACnC,WAAO;AAAA,MACL,WAAW,8BAA8B,GAAG;AAAA,MAC5C,OAAO,2BAA2B,SAA8B,GAAG;AAAA,MACnE,UAAU;AAAA,QACR;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { l as GraphQLCustomPredicate,
|
|
2
|
+
export { C as DocumentTypeDecoration, l as GraphQLCustomPredicate, K as GraphQLCustomPredicateResult, G as GraphQLHandler, F as GraphQLHandlerInfo, E as GraphQLHandlerNameSelector, j as GraphQLJsonRequestBody, k as GraphQLOperationType, r as GraphQLPredicate, f as GraphQLQuery, h as GraphQLRequestBody, I as GraphQLRequestParsedResult, s as GraphQLResolverExtras, i as GraphQLResponseBody, g as GraphQLVariables, L as isDocumentNode } from '../HttpResponse-Cw4ELwIN.mjs';
|
|
3
3
|
import '../utils/matching/matchRequestUrl.mjs';
|
|
4
4
|
import '@mswjs/interceptors';
|
|
5
5
|
import '../utils/internal/isIterable.mjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'graphql';
|
|
2
|
-
export { l as GraphQLCustomPredicate,
|
|
2
|
+
export { C as DocumentTypeDecoration, l as GraphQLCustomPredicate, K as GraphQLCustomPredicateResult, G as GraphQLHandler, F as GraphQLHandlerInfo, E as GraphQLHandlerNameSelector, j as GraphQLJsonRequestBody, k as GraphQLOperationType, r as GraphQLPredicate, f as GraphQLQuery, h as GraphQLRequestBody, I as GraphQLRequestParsedResult, s as GraphQLResolverExtras, i as GraphQLResponseBody, g as GraphQLVariables, L as isDocumentNode } from '../HttpResponse-CVs3ngx3.js';
|
|
3
3
|
import '../utils/matching/matchRequestUrl.js';
|
|
4
4
|
import '@mswjs/interceptors';
|
|
5
5
|
import '../utils/internal/isIterable.js';
|
|
@@ -22,6 +22,7 @@ __export(GraphQLHandler_exports, {
|
|
|
22
22
|
isDocumentNode: () => isDocumentNode
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(GraphQLHandler_exports);
|
|
25
|
+
var import_graphql = require("graphql");
|
|
25
26
|
var import_RequestHandler = require("./RequestHandler");
|
|
26
27
|
var import_getTimestamp = require("../utils/logging/getTimestamp");
|
|
27
28
|
var import_getStatusCodeColor = require("../utils/logging/getStatusCodeColor");
|
|
@@ -32,38 +33,62 @@ var import_parseGraphQLRequest = require("../utils/internal/parseGraphQLRequest"
|
|
|
32
33
|
var import_toPublicUrl = require("../utils/request/toPublicUrl");
|
|
33
34
|
var import_devUtils = require("../utils/internal/devUtils");
|
|
34
35
|
var import_getRequestCookies = require("../utils/request/getRequestCookies");
|
|
36
|
+
var import_outvariant = require("outvariant");
|
|
35
37
|
function isDocumentNode(value) {
|
|
36
38
|
if (value == null) {
|
|
37
39
|
return false;
|
|
38
40
|
}
|
|
39
41
|
return typeof value === "object" && "kind" in value && "definitions" in value;
|
|
40
42
|
}
|
|
43
|
+
function isDocumentTypeDecoration(value) {
|
|
44
|
+
return value instanceof String;
|
|
45
|
+
}
|
|
41
46
|
class GraphQLHandler extends import_RequestHandler.RequestHandler {
|
|
42
47
|
endpoint;
|
|
43
48
|
static parsedRequestCache = /* @__PURE__ */ new WeakMap();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
static #parseOperationName(predicate, operationType) {
|
|
50
|
+
const getOperationName = (node) => {
|
|
51
|
+
(0, import_outvariant.invariant)(
|
|
52
|
+
node.operationType === operationType,
|
|
53
|
+
'Failed to create a GraphQL handler: provided a DocumentNode with a mismatched operation type (expected "%s" but got "%s").',
|
|
54
|
+
operationType,
|
|
55
|
+
node.operationType
|
|
56
|
+
);
|
|
57
|
+
(0, import_outvariant.invariant)(
|
|
58
|
+
node.operationName,
|
|
59
|
+
"Failed to create a GraphQL handler: provided a DocumentNode without operation name"
|
|
60
|
+
);
|
|
61
|
+
return node.operationName;
|
|
62
|
+
};
|
|
63
|
+
if (isDocumentNode(predicate)) {
|
|
64
|
+
return getOperationName((0, import_parseGraphQLRequest.parseDocumentNode)(predicate));
|
|
59
65
|
}
|
|
60
|
-
|
|
66
|
+
if (isDocumentTypeDecoration(predicate)) {
|
|
67
|
+
const documentNode = (0, import_graphql.parse)(predicate.toString());
|
|
68
|
+
(0, import_outvariant.invariant)(
|
|
69
|
+
isDocumentNode(documentNode),
|
|
70
|
+
"Failed to create a GraphQL handler: given TypedDocumentString (%s) does not produce a valid DocumentNode",
|
|
71
|
+
predicate
|
|
72
|
+
);
|
|
73
|
+
return getOperationName((0, import_parseGraphQLRequest.parseDocumentNode)(documentNode));
|
|
74
|
+
}
|
|
75
|
+
return predicate;
|
|
76
|
+
}
|
|
77
|
+
constructor(operationType, predicate, endpoint, resolver, options) {
|
|
78
|
+
const operationName = GraphQLHandler.#parseOperationName(
|
|
79
|
+
predicate,
|
|
80
|
+
operationType
|
|
81
|
+
);
|
|
82
|
+
const displayOperationName = typeof operationName === "function" ? "[custom predicate]" : operationName;
|
|
61
83
|
const header = operationType === "all" ? `${operationType} (origin: ${endpoint.toString()})` : `${operationType}${displayOperationName ? ` ${displayOperationName}` : ""} (origin: ${endpoint.toString()})`;
|
|
62
84
|
super({
|
|
63
85
|
info: {
|
|
64
86
|
header,
|
|
65
87
|
operationType,
|
|
66
|
-
operationName:
|
|
88
|
+
operationName: GraphQLHandler.#parseOperationName(
|
|
89
|
+
predicate,
|
|
90
|
+
operationType
|
|
91
|
+
)
|
|
67
92
|
},
|
|
68
93
|
resolver,
|
|
69
94
|
options
|