msw 2.10.1 → 2.10.3
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-BOGtXZ-B.d.mts → HttpResponse-C7FhBLaS.d.mts} +103 -2
- package/lib/core/{HttpResponse-DzeJL_i8.d.ts → HttpResponse-DWu36LsY.d.ts} +103 -2
- package/lib/core/HttpResponse.d.mts +3 -1
- package/lib/core/HttpResponse.d.ts +3 -1
- package/lib/core/HttpResponse.js +5 -1
- package/lib/core/HttpResponse.js.map +1 -1
- package/lib/core/HttpResponse.mjs +5 -1
- package/lib/core/HttpResponse.mjs.map +1 -1
- package/lib/core/SetupApi.d.mts +3 -2
- package/lib/core/SetupApi.d.ts +3 -2
- package/lib/core/getResponse.d.mts +5 -2
- package/lib/core/getResponse.d.ts +5 -2
- package/lib/core/getResponse.js +3 -2
- package/lib/core/getResponse.js.map +1 -1
- package/lib/core/getResponse.mjs +6 -3
- package/lib/core/getResponse.mjs.map +1 -1
- package/lib/core/graphql.d.mts +1 -2
- package/lib/core/graphql.d.ts +1 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -2
- package/lib/core/handlers/HttpHandler.d.mts +2 -1
- package/lib/core/handlers/HttpHandler.d.ts +2 -1
- package/lib/core/handlers/RequestHandler.d.mts +3 -1
- package/lib/core/handlers/RequestHandler.d.ts +3 -1
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +6 -2
- package/lib/core/handlers/WebSocketHandler.d.ts +6 -2
- package/lib/core/handlers/WebSocketHandler.js +8 -3
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +8 -3
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +2 -1
- package/lib/core/http.d.ts +2 -1
- package/lib/core/index.d.mts +1 -2
- package/lib/core/index.d.ts +1 -2
- package/lib/core/passthrough.d.mts +3 -1
- package/lib/core/passthrough.d.ts +3 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +3 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +3 -1
- package/lib/core/utils/executeHandlers.d.mts +3 -1
- package/lib/core/utils/executeHandlers.d.ts +3 -1
- package/lib/core/utils/handleRequest.d.mts +3 -1
- package/lib/core/utils/handleRequest.d.ts +3 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +3 -2
- package/lib/core/utils/internal/isHandlerKind.d.ts +3 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -2
- package/lib/core/utils/internal/parseMultipartData.d.mts +3 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +3 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +3 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +3 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +3 -2
- package/lib/core/ws/handleWebSocketEvent.d.ts +3 -2
- package/lib/iife/index.js +15 -5
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/HttpResponse.ts +8 -1
- package/src/core/getResponse.test.ts +28 -17
- package/src/core/getResponse.ts +7 -1
- package/src/core/handlers/RequestHandler.ts +17 -2
- package/src/core/handlers/WebSocketHandler.test.ts +16 -0
- package/src/core/handlers/WebSocketHandler.ts +15 -2
- package/lib/core/GraphQLHandler-DOXAygvT.d.mts +0 -100
- package/lib/core/GraphQLHandler-noP9MRWa.d.ts +0 -100
package/lib/mockServiceWorker.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Please do NOT modify this file.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
const PACKAGE_VERSION = '2.10.
|
|
10
|
+
const PACKAGE_VERSION = '2.10.3'
|
|
11
11
|
const INTEGRITY_CHECKSUM = 'f5825c521429caf22a4dd13b66e243af'
|
|
12
12
|
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
|
|
13
13
|
const activeClientIds = new Set()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.3",
|
|
4
4
|
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./lib/core/index.js",
|
|
@@ -280,7 +280,7 @@
|
|
|
280
280
|
"vitest-environment-miniflare": "^2.14.4",
|
|
281
281
|
"webpack": "^5.95.0",
|
|
282
282
|
"webpack-http-server": "^0.5.0",
|
|
283
|
-
"msw": "2.10.
|
|
283
|
+
"msw": "2.10.3"
|
|
284
284
|
},
|
|
285
285
|
"peerDependencies": {
|
|
286
286
|
"typescript": ">= 4.8.x"
|
package/src/core/HttpResponse.ts
CHANGED
|
@@ -10,7 +10,10 @@ export interface HttpResponseInit extends ResponseInit {
|
|
|
10
10
|
type?: ResponseType
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const bodyType: unique symbol = Symbol('bodyType')
|
|
13
|
+
export const bodyType: unique symbol = Symbol('bodyType')
|
|
14
|
+
export type DefaultUnsafeFetchResponse = Response & {
|
|
15
|
+
[bodyType]?: never
|
|
16
|
+
}
|
|
14
17
|
|
|
15
18
|
export interface StrictRequest<BodyType extends JsonBodyType> extends Request {
|
|
16
19
|
json(): Promise<BodyType>
|
|
@@ -46,6 +49,10 @@ export class HttpResponse<
|
|
|
46
49
|
decorateResponse(this, responseInit)
|
|
47
50
|
}
|
|
48
51
|
|
|
52
|
+
static error(): HttpResponse<any> {
|
|
53
|
+
return super.error() as HttpResponse<any>
|
|
54
|
+
}
|
|
55
|
+
|
|
49
56
|
/**
|
|
50
57
|
* Create a `Response` with a `Content-Type: "text/plain"` body.
|
|
51
58
|
* @example
|
|
@@ -1,40 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
* @vitest-environment node
|
|
3
|
-
*/
|
|
1
|
+
// @vitest-environment node
|
|
4
2
|
import { http } from './http'
|
|
5
3
|
import { getResponse } from './getResponse'
|
|
6
4
|
|
|
7
5
|
it('returns undefined given empty headers array', async () => {
|
|
8
|
-
expect(
|
|
9
|
-
|
|
10
|
-
).toBeUndefined()
|
|
6
|
+
await expect(
|
|
7
|
+
getResponse([], new Request('http://localhost/')),
|
|
8
|
+
).resolves.toBeUndefined()
|
|
11
9
|
})
|
|
12
10
|
|
|
13
11
|
it('returns undefined given no matching handlers', async () => {
|
|
14
|
-
expect(
|
|
15
|
-
|
|
12
|
+
await expect(
|
|
13
|
+
getResponse(
|
|
16
14
|
[http.get('/product', () => void 0)],
|
|
17
15
|
new Request('http://localhost/user'),
|
|
18
16
|
),
|
|
19
|
-
).toBeUndefined()
|
|
17
|
+
).resolves.toBeUndefined()
|
|
20
18
|
})
|
|
21
19
|
|
|
22
20
|
it('returns undefined given a matching handler that returned no response', async () => {
|
|
23
|
-
expect(
|
|
24
|
-
|
|
21
|
+
await expect(
|
|
22
|
+
getResponse(
|
|
25
23
|
[http.get('*/user', () => void 0)],
|
|
26
24
|
new Request('http://localhost/user'),
|
|
27
25
|
),
|
|
28
|
-
).toBeUndefined()
|
|
26
|
+
).resolves.toBeUndefined()
|
|
29
27
|
})
|
|
30
28
|
|
|
31
29
|
it('returns undefined given a matching handler that returned explicit undefined', async () => {
|
|
32
|
-
expect(
|
|
33
|
-
|
|
30
|
+
await expect(
|
|
31
|
+
getResponse(
|
|
34
32
|
[http.get('*/user', () => undefined)],
|
|
35
33
|
new Request('http://localhost/user'),
|
|
36
34
|
),
|
|
37
|
-
).toBeUndefined()
|
|
35
|
+
).resolves.toBeUndefined()
|
|
38
36
|
})
|
|
39
37
|
|
|
40
38
|
it('returns the response returned from a matching handler', async () => {
|
|
@@ -45,7 +43,7 @@ it('returns the response returned from a matching handler', async () => {
|
|
|
45
43
|
|
|
46
44
|
expect(response?.status).toBe(200)
|
|
47
45
|
expect(response?.headers.get('Content-Type')).toBe('application/json')
|
|
48
|
-
expect(
|
|
46
|
+
await expect(response?.json()).resolves.toEqual({ name: 'John' })
|
|
49
47
|
})
|
|
50
48
|
|
|
51
49
|
it('returns the response from the first matching handler if multiple match', async () => {
|
|
@@ -59,5 +57,18 @@ it('returns the response from the first matching handler if multiple match', asy
|
|
|
59
57
|
|
|
60
58
|
expect(response?.status).toBe(200)
|
|
61
59
|
expect(response?.headers.get('Content-Type')).toBe('application/json')
|
|
62
|
-
expect(
|
|
60
|
+
await expect(response?.json()).resolves.toEqual({ name: 'John' })
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('supports custom base url', async () => {
|
|
64
|
+
const response = await getResponse(
|
|
65
|
+
[http.get('/resource', () => new Response('hello world'))],
|
|
66
|
+
new Request('https://localhost:3000/resource'),
|
|
67
|
+
{
|
|
68
|
+
baseUrl: 'https://localhost:3000/',
|
|
69
|
+
},
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
expect(response?.status).toBe(200)
|
|
73
|
+
await expect(response?.text()).resolves.toBe('hello world')
|
|
63
74
|
})
|
package/src/core/getResponse.ts
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import { createRequestId } from '@mswjs/interceptors'
|
|
2
2
|
import type { RequestHandler } from './handlers/RequestHandler'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
executeHandlers,
|
|
5
|
+
type ResponseResolutionContext,
|
|
6
|
+
} from './utils/executeHandlers'
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Finds a response for the given request instance
|
|
7
10
|
* in the array of request handlers.
|
|
8
11
|
* @param handlers The array of request handlers.
|
|
9
12
|
* @param request The `Request` instance.
|
|
13
|
+
* @param resolutionContext Request resolution options.
|
|
10
14
|
* @returns {Response} A mocked response, if any.
|
|
11
15
|
*/
|
|
12
16
|
export const getResponse = async (
|
|
13
17
|
handlers: Array<RequestHandler>,
|
|
14
18
|
request: Request,
|
|
19
|
+
resolutionContext?: ResponseResolutionContext,
|
|
15
20
|
): Promise<Response | undefined> => {
|
|
16
21
|
const result = await executeHandlers({
|
|
17
22
|
request,
|
|
18
23
|
requestId: createRequestId(),
|
|
19
24
|
handlers,
|
|
25
|
+
resolutionContext,
|
|
20
26
|
})
|
|
21
27
|
|
|
22
28
|
return result?.response
|
|
@@ -6,8 +6,13 @@ import {
|
|
|
6
6
|
} from '../utils/internal/isIterable'
|
|
7
7
|
import type { ResponseResolutionContext } from '../utils/executeHandlers'
|
|
8
8
|
import type { MaybePromise } from '../typeUtils'
|
|
9
|
-
import
|
|
9
|
+
import {
|
|
10
|
+
StrictRequest,
|
|
11
|
+
HttpResponse,
|
|
12
|
+
DefaultUnsafeFetchResponse,
|
|
13
|
+
} from '../HttpResponse'
|
|
10
14
|
import type { HandlerKind } from './common'
|
|
15
|
+
import type { GraphQLRequestBody } from './GraphQLHandler'
|
|
11
16
|
|
|
12
17
|
export type DefaultRequestMultipartBody = Record<
|
|
13
18
|
string,
|
|
@@ -42,9 +47,19 @@ export interface RequestHandlerInternalInfo {
|
|
|
42
47
|
export type ResponseResolverReturnType<
|
|
43
48
|
ResponseBodyType extends DefaultBodyType = undefined,
|
|
44
49
|
> =
|
|
50
|
+
// If ResponseBodyType is a union and one of the types is `undefined`,
|
|
51
|
+
// allow plain Response as the type.
|
|
45
52
|
| ([ResponseBodyType] extends [undefined]
|
|
46
53
|
? Response
|
|
47
|
-
:
|
|
54
|
+
: /**
|
|
55
|
+
* Treat GraphQL response body type as a special case.
|
|
56
|
+
* For esome reason, making the default HttpResponse<T> | DefaultUnsafeFetchResponse
|
|
57
|
+
* union breaks the body type inference for HTTP requests.
|
|
58
|
+
* @see https://github.com/mswjs/msw/issues/2130
|
|
59
|
+
*/
|
|
60
|
+
ResponseBodyType extends GraphQLRequestBody<any>
|
|
61
|
+
? HttpResponse<ResponseBodyType> | DefaultUnsafeFetchResponse
|
|
62
|
+
: HttpResponse<ResponseBodyType>)
|
|
48
63
|
| undefined
|
|
49
64
|
| void
|
|
50
65
|
|
|
@@ -108,4 +108,20 @@ describe('parse', () => {
|
|
|
108
108
|
},
|
|
109
109
|
})
|
|
110
110
|
})
|
|
111
|
+
|
|
112
|
+
it('supports a custom resolution context (base url)', () => {
|
|
113
|
+
expect(
|
|
114
|
+
new WebSocketHandler('/api/ws').parse({
|
|
115
|
+
url: new URL('ws://localhost:3000/api/ws'),
|
|
116
|
+
resolutionContext: {
|
|
117
|
+
baseUrl: 'ws://localhost:3000/',
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
).toEqual({
|
|
121
|
+
match: {
|
|
122
|
+
matches: true,
|
|
123
|
+
params: {},
|
|
124
|
+
},
|
|
125
|
+
})
|
|
126
|
+
})
|
|
111
127
|
})
|
|
@@ -29,6 +29,10 @@ export interface WebSocketHandlerConnection {
|
|
|
29
29
|
params: PathParams
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
export interface WebSocketResolutionContext {
|
|
33
|
+
baseUrl?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
32
36
|
export const kEmitter = Symbol('kEmitter')
|
|
33
37
|
export const kSender = Symbol('kSender')
|
|
34
38
|
const kStopPropagationPatched = Symbol('kStopPropagationPatched')
|
|
@@ -50,7 +54,10 @@ export class WebSocketHandler {
|
|
|
50
54
|
this.__kind = 'EventHandler'
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
public parse(args: {
|
|
57
|
+
public parse(args: {
|
|
58
|
+
url: URL
|
|
59
|
+
resolutionContext?: WebSocketResolutionContext
|
|
60
|
+
}): WebSocketHandlerParsedResult {
|
|
54
61
|
const clientUrl = new URL(args.url)
|
|
55
62
|
|
|
56
63
|
/**
|
|
@@ -60,7 +67,11 @@ export class WebSocketHandler {
|
|
|
60
67
|
*/
|
|
61
68
|
clientUrl.pathname = clientUrl.pathname.replace(/^\/socket.io\//, '/')
|
|
62
69
|
|
|
63
|
-
const match = matchRequestUrl(
|
|
70
|
+
const match = matchRequestUrl(
|
|
71
|
+
clientUrl,
|
|
72
|
+
this.url,
|
|
73
|
+
args.resolutionContext?.baseUrl,
|
|
74
|
+
)
|
|
64
75
|
|
|
65
76
|
return {
|
|
66
77
|
match,
|
|
@@ -76,9 +87,11 @@ export class WebSocketHandler {
|
|
|
76
87
|
|
|
77
88
|
public async run(
|
|
78
89
|
connection: Omit<WebSocketHandlerConnection, 'params'>,
|
|
90
|
+
resolutionContext?: WebSocketResolutionContext,
|
|
79
91
|
): Promise<boolean> {
|
|
80
92
|
const parsedResult = this.parse({
|
|
81
93
|
url: connection.client.url,
|
|
94
|
+
resolutionContext,
|
|
82
95
|
})
|
|
83
96
|
|
|
84
97
|
if (!this.predicate({ url: connection.client.url, parsedResult })) {
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { OperationTypeNode, DocumentNode, GraphQLError } from 'graphql';
|
|
2
|
-
import { D as DefaultBodyType, R as RequestHandler, g as RequestHandlerDefaultInfo, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-BOGtXZ-B.mjs';
|
|
3
|
-
import { Match, Path } from './utils/matching/matchRequestUrl.mjs';
|
|
4
|
-
|
|
5
|
-
interface ParsedGraphQLQuery {
|
|
6
|
-
operationType: OperationTypeNode;
|
|
7
|
-
operationName?: string;
|
|
8
|
-
}
|
|
9
|
-
type ParsedGraphQLRequest<VariablesType extends GraphQLVariables = GraphQLVariables> = (ParsedGraphQLQuery & {
|
|
10
|
-
query: string;
|
|
11
|
-
variables?: VariablesType;
|
|
12
|
-
}) | undefined;
|
|
13
|
-
declare function parseDocumentNode(node: DocumentNode): ParsedGraphQLQuery;
|
|
14
|
-
type GraphQLParsedOperationsMap = Record<string, string[]>;
|
|
15
|
-
type GraphQLMultipartRequestBody = {
|
|
16
|
-
operations: string;
|
|
17
|
-
map?: string;
|
|
18
|
-
} & {
|
|
19
|
-
[fileName: string]: File;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Determines if a given request can be considered a GraphQL request.
|
|
23
|
-
* Does not parse the query and does not guarantee its validity.
|
|
24
|
-
*/
|
|
25
|
-
declare function parseGraphQLRequest(request: Request): Promise<ParsedGraphQLRequest>;
|
|
26
|
-
|
|
27
|
-
type ExpectedOperationTypeNode = OperationTypeNode | 'all';
|
|
28
|
-
type GraphQLHandlerNameSelector = DocumentNode | RegExp | string;
|
|
29
|
-
type GraphQLQuery = Record<string, any> | null;
|
|
30
|
-
type GraphQLVariables = Record<string, any>;
|
|
31
|
-
interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {
|
|
32
|
-
operationType: ExpectedOperationTypeNode;
|
|
33
|
-
operationName: GraphQLHandlerNameSelector;
|
|
34
|
-
}
|
|
35
|
-
type GraphQLRequestParsedResult = {
|
|
36
|
-
match: Match;
|
|
37
|
-
cookies: Record<string, string>;
|
|
38
|
-
} & (ParsedGraphQLRequest<GraphQLVariables>
|
|
39
|
-
/**
|
|
40
|
-
* An empty version of the ParsedGraphQLRequest
|
|
41
|
-
* which simplifies the return type of the resolver
|
|
42
|
-
* when the request is to a non-matching endpoint
|
|
43
|
-
*/
|
|
44
|
-
| {
|
|
45
|
-
operationType?: undefined;
|
|
46
|
-
operationName?: undefined;
|
|
47
|
-
query?: undefined;
|
|
48
|
-
variables?: undefined;
|
|
49
|
-
});
|
|
50
|
-
type GraphQLResolverExtras<Variables extends GraphQLVariables> = {
|
|
51
|
-
query: string;
|
|
52
|
-
operationName: string;
|
|
53
|
-
variables: Variables;
|
|
54
|
-
cookies: Record<string, string>;
|
|
55
|
-
};
|
|
56
|
-
type GraphQLRequestBody<VariablesType extends GraphQLVariables> = GraphQLJsonRequestBody<VariablesType> | GraphQLMultipartRequestBody | Record<string, any> | undefined;
|
|
57
|
-
interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {
|
|
58
|
-
query: string;
|
|
59
|
-
variables?: Variables;
|
|
60
|
-
}
|
|
61
|
-
type GraphQLResponseBody<BodyType extends DefaultBodyType> = {
|
|
62
|
-
data?: BodyType | null;
|
|
63
|
-
errors?: readonly Partial<GraphQLError>[] | null;
|
|
64
|
-
extensions?: Record<string, any>;
|
|
65
|
-
} | null | undefined;
|
|
66
|
-
declare function isDocumentNode(value: DocumentNode | any): value is DocumentNode;
|
|
67
|
-
declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, GraphQLRequestParsedResult, GraphQLResolverExtras<any>> {
|
|
68
|
-
private endpoint;
|
|
69
|
-
static parsedRequestCache: WeakMap<Request, ParsedGraphQLRequest<GraphQLVariables>>;
|
|
70
|
-
constructor(operationType: ExpectedOperationTypeNode, operationName: GraphQLHandlerNameSelector, endpoint: Path, resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>, options?: RequestHandlerOptions);
|
|
71
|
-
/**
|
|
72
|
-
* Parses the request body, once per request, cached across all
|
|
73
|
-
* GraphQL handlers. This is done to avoid multiple parsing of the
|
|
74
|
-
* request body, which each requires a clone of the request.
|
|
75
|
-
*/
|
|
76
|
-
parseGraphQLRequestOrGetFromCache(request: Request): Promise<ParsedGraphQLRequest<GraphQLVariables>>;
|
|
77
|
-
parse(args: {
|
|
78
|
-
request: Request;
|
|
79
|
-
}): Promise<GraphQLRequestParsedResult>;
|
|
80
|
-
predicate(args: {
|
|
81
|
-
request: Request;
|
|
82
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
83
|
-
}): boolean;
|
|
84
|
-
protected extendResolverArgs(args: {
|
|
85
|
-
request: Request;
|
|
86
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
87
|
-
}): {
|
|
88
|
-
query: string;
|
|
89
|
-
operationName: string;
|
|
90
|
-
variables: GraphQLVariables;
|
|
91
|
-
cookies: Record<string, string>;
|
|
92
|
-
};
|
|
93
|
-
log(args: {
|
|
94
|
-
request: Request;
|
|
95
|
-
response: Response;
|
|
96
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
97
|
-
}): Promise<void>;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export { type ExpectedOperationTypeNode as E, GraphQLHandler as G, type ParsedGraphQLRequest as P, type GraphQLQuery as a, type GraphQLVariables as b, type GraphQLRequestBody as c, type GraphQLJsonRequestBody as d, type GraphQLHandlerNameSelector as e, type GraphQLResolverExtras as f, type GraphQLResponseBody as g, type ParsedGraphQLQuery as h, type GraphQLParsedOperationsMap as i, type GraphQLMultipartRequestBody as j, parseGraphQLRequest as k, type GraphQLHandlerInfo as l, type GraphQLRequestParsedResult as m, isDocumentNode as n, parseDocumentNode as p };
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { OperationTypeNode, DocumentNode, GraphQLError } from 'graphql';
|
|
2
|
-
import { D as DefaultBodyType, R as RequestHandler, g as RequestHandlerDefaultInfo, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-DzeJL_i8.js';
|
|
3
|
-
import { Match, Path } from './utils/matching/matchRequestUrl.js';
|
|
4
|
-
|
|
5
|
-
interface ParsedGraphQLQuery {
|
|
6
|
-
operationType: OperationTypeNode;
|
|
7
|
-
operationName?: string;
|
|
8
|
-
}
|
|
9
|
-
type ParsedGraphQLRequest<VariablesType extends GraphQLVariables = GraphQLVariables> = (ParsedGraphQLQuery & {
|
|
10
|
-
query: string;
|
|
11
|
-
variables?: VariablesType;
|
|
12
|
-
}) | undefined;
|
|
13
|
-
declare function parseDocumentNode(node: DocumentNode): ParsedGraphQLQuery;
|
|
14
|
-
type GraphQLParsedOperationsMap = Record<string, string[]>;
|
|
15
|
-
type GraphQLMultipartRequestBody = {
|
|
16
|
-
operations: string;
|
|
17
|
-
map?: string;
|
|
18
|
-
} & {
|
|
19
|
-
[fileName: string]: File;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Determines if a given request can be considered a GraphQL request.
|
|
23
|
-
* Does not parse the query and does not guarantee its validity.
|
|
24
|
-
*/
|
|
25
|
-
declare function parseGraphQLRequest(request: Request): Promise<ParsedGraphQLRequest>;
|
|
26
|
-
|
|
27
|
-
type ExpectedOperationTypeNode = OperationTypeNode | 'all';
|
|
28
|
-
type GraphQLHandlerNameSelector = DocumentNode | RegExp | string;
|
|
29
|
-
type GraphQLQuery = Record<string, any> | null;
|
|
30
|
-
type GraphQLVariables = Record<string, any>;
|
|
31
|
-
interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {
|
|
32
|
-
operationType: ExpectedOperationTypeNode;
|
|
33
|
-
operationName: GraphQLHandlerNameSelector;
|
|
34
|
-
}
|
|
35
|
-
type GraphQLRequestParsedResult = {
|
|
36
|
-
match: Match;
|
|
37
|
-
cookies: Record<string, string>;
|
|
38
|
-
} & (ParsedGraphQLRequest<GraphQLVariables>
|
|
39
|
-
/**
|
|
40
|
-
* An empty version of the ParsedGraphQLRequest
|
|
41
|
-
* which simplifies the return type of the resolver
|
|
42
|
-
* when the request is to a non-matching endpoint
|
|
43
|
-
*/
|
|
44
|
-
| {
|
|
45
|
-
operationType?: undefined;
|
|
46
|
-
operationName?: undefined;
|
|
47
|
-
query?: undefined;
|
|
48
|
-
variables?: undefined;
|
|
49
|
-
});
|
|
50
|
-
type GraphQLResolverExtras<Variables extends GraphQLVariables> = {
|
|
51
|
-
query: string;
|
|
52
|
-
operationName: string;
|
|
53
|
-
variables: Variables;
|
|
54
|
-
cookies: Record<string, string>;
|
|
55
|
-
};
|
|
56
|
-
type GraphQLRequestBody<VariablesType extends GraphQLVariables> = GraphQLJsonRequestBody<VariablesType> | GraphQLMultipartRequestBody | Record<string, any> | undefined;
|
|
57
|
-
interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {
|
|
58
|
-
query: string;
|
|
59
|
-
variables?: Variables;
|
|
60
|
-
}
|
|
61
|
-
type GraphQLResponseBody<BodyType extends DefaultBodyType> = {
|
|
62
|
-
data?: BodyType | null;
|
|
63
|
-
errors?: readonly Partial<GraphQLError>[] | null;
|
|
64
|
-
extensions?: Record<string, any>;
|
|
65
|
-
} | null | undefined;
|
|
66
|
-
declare function isDocumentNode(value: DocumentNode | any): value is DocumentNode;
|
|
67
|
-
declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, GraphQLRequestParsedResult, GraphQLResolverExtras<any>> {
|
|
68
|
-
private endpoint;
|
|
69
|
-
static parsedRequestCache: WeakMap<Request, ParsedGraphQLRequest<GraphQLVariables>>;
|
|
70
|
-
constructor(operationType: ExpectedOperationTypeNode, operationName: GraphQLHandlerNameSelector, endpoint: Path, resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>, options?: RequestHandlerOptions);
|
|
71
|
-
/**
|
|
72
|
-
* Parses the request body, once per request, cached across all
|
|
73
|
-
* GraphQL handlers. This is done to avoid multiple parsing of the
|
|
74
|
-
* request body, which each requires a clone of the request.
|
|
75
|
-
*/
|
|
76
|
-
parseGraphQLRequestOrGetFromCache(request: Request): Promise<ParsedGraphQLRequest<GraphQLVariables>>;
|
|
77
|
-
parse(args: {
|
|
78
|
-
request: Request;
|
|
79
|
-
}): Promise<GraphQLRequestParsedResult>;
|
|
80
|
-
predicate(args: {
|
|
81
|
-
request: Request;
|
|
82
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
83
|
-
}): boolean;
|
|
84
|
-
protected extendResolverArgs(args: {
|
|
85
|
-
request: Request;
|
|
86
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
87
|
-
}): {
|
|
88
|
-
query: string;
|
|
89
|
-
operationName: string;
|
|
90
|
-
variables: GraphQLVariables;
|
|
91
|
-
cookies: Record<string, string>;
|
|
92
|
-
};
|
|
93
|
-
log(args: {
|
|
94
|
-
request: Request;
|
|
95
|
-
response: Response;
|
|
96
|
-
parsedResult: GraphQLRequestParsedResult;
|
|
97
|
-
}): Promise<void>;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export { type ExpectedOperationTypeNode as E, GraphQLHandler as G, type ParsedGraphQLRequest as P, type GraphQLQuery as a, type GraphQLVariables as b, type GraphQLRequestBody as c, type GraphQLJsonRequestBody as d, type GraphQLHandlerNameSelector as e, type GraphQLResolverExtras as f, type GraphQLResponseBody as g, type ParsedGraphQLQuery as h, type GraphQLParsedOperationsMap as i, type GraphQLMultipartRequestBody as j, parseGraphQLRequest as k, type GraphQLHandlerInfo as l, type GraphQLRequestParsedResult as m, isDocumentNode as n, parseDocumentNode as p };
|