msw 0.24.0 → 0.24.1

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.
@@ -28,7 +28,10 @@ function mergeRight(left, right) {
28
28
  }
29
29
 
30
30
  /**
31
- * Returns a GraphQL body payload.
31
+ * Sets a given payload as a GraphQL response body.
32
+ * @example
33
+ * res(ctx.data({ user: { firstName: 'John' }}))
34
+ * @see {@link https://mswjs.io/docs/api/context/data `ctx.data()`}
32
35
  */
33
36
  const data = (payload) => {
34
37
  return (res) => {
@@ -40,6 +43,8 @@ const data = (payload) => {
40
43
 
41
44
  /**
42
45
  * Sets a given list of GraphQL errors on the mocked response.
46
+ * @example res(ctx.errors([{ message: 'Unauthorized' }]))
47
+ * @see {@link https://mswjs.io/docs/api/context/errors}
43
48
  */
44
49
  const errors = (errorsList) => {
45
50
  return (res) => {
@@ -64,6 +64,13 @@ var statuses = {
64
64
  "511": "Network Authentication Required"
65
65
  };
66
66
 
67
+ /**
68
+ * Sets a response status code and text.
69
+ * @example
70
+ * res(ctx.status(301))
71
+ * res(ctx.status(400, 'Custom status text'))
72
+ * @see {@link https://mswjs.io/docs/api/context/status `ctx.status()`}
73
+ */
67
74
  const status = (statusCode, statusText) => {
68
75
  return (res) => {
69
76
  res.status = statusCode;
@@ -327,6 +334,10 @@ exports.flattenHeadersList = flattenHeadersList_1.flattenHeadersList;
327
334
  exports.flattenHeadersObject = flattenHeadersObject_1.flattenHeadersObject;
328
335
  });
329
336
 
337
+ /**
338
+ * Sets one or multiple response headers.
339
+ * @see {@link https://mswjs.io/docs/api/context/set `ctx.set()`}
340
+ */
330
341
  function set(...args) {
331
342
  return (res) => {
332
343
  const [name, value] = args;
@@ -358,10 +369,13 @@ function jsonParse(str) {
358
369
 
359
370
  /**
360
371
  * Sets the given value as the JSON body of the response.
372
+ * Appends a `Content-Type: application/json` header on the
373
+ * mocked response.
361
374
  * @example
362
- * res(json({ key: 'value' }))
363
- * res(json('Some string'))
364
- * res(json([1, '2', false, { ok: true }]))
375
+ * res(ctx.json('Some string'))
376
+ * res(ctx.json({ key: 'value' }))
377
+ * res(ctx.json([1, '2', false, { ok: true }]))
378
+ * @see {@link https://mswjs.io/docs/api/context/json `ctx.json()`}
365
379
  */
366
380
  const json = (body) => {
367
381
  return (res) => {
@@ -398,10 +412,11 @@ const getRandomServerResponseTime = () => {
398
412
  MIN_SERVER_RESPONSE_TIME);
399
413
  };
400
414
  /**
401
- * Delays the current response for the given duration (in ms)
415
+ * Delays the response by the given duration (ms).
402
416
  * @example
403
- * res(delay()) // realistic server response time
404
- * res(delay(1500)) // explicit response delay duration
417
+ * res(ctx.delay()) // realistic server response time
418
+ * res(ctx.delay(1200))
419
+ * @see {@link https://mswjs.io/docs/api/context/delay `ctx.delay()`}
405
420
  */
406
421
  const delay = (durationMs) => {
407
422
  return (res) => {
@@ -427,9 +442,10 @@ const createFetchRequestParameters = (input) => {
427
442
  return requestParameters;
428
443
  };
429
444
  /**
430
- * Wrapper around the native `window.fetch()` function that performs
431
- * a request bypassing MSW. Requests performed using
432
- * this function will never be mocked.
445
+ * Performs a bypassed request inside a request handler.
446
+ * @example
447
+ * const originalResponse = await ctx.fetch(req)
448
+ * @see {@link https://mswjs.io/docs/api/context/fetch `ctx.fetch()`}
433
449
  */
434
450
  const fetch = (input, requestInit = {}) => {
435
451
  // Keep the default `window.fetch()` call signature
@@ -3239,10 +3239,42 @@ const createGraphQLOperationHandler = (mask) => {
3239
3239
  };
3240
3240
  };
3241
3241
  const graphqlStandardHandlers = {
3242
+ /**
3243
+ * Captures any GraphQL operation, regardless of its name, under the current scope.
3244
+ * @example
3245
+ * graphql.operation((req, res, ctx) => {
3246
+ * return res(ctx.data({ name: 'John' }))
3247
+ * })
3248
+ * @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
3249
+ */
3242
3250
  operation: createGraphQLOperationHandler('*'),
3251
+ /**
3252
+ * Captures a GraphQL query by a given name.
3253
+ * @example
3254
+ * graphql.query('GetUser', (req, res, ctx) => {
3255
+ * return res(ctx.data({ user: { name: 'John' } }))
3256
+ * })
3257
+ * @see {@link https://mswjs.io/docs/api/graphql/query `graphql.query()`}
3258
+ */
3243
3259
  query: createGraphQLScopedHandler('query', '*'),
3260
+ /**
3261
+ * Captures a GraphQL mutation by a given name.
3262
+ * @example
3263
+ * graphql.mutation('SavePost', (req, res, ctx) => {
3264
+ * return res(ctx.data({ post: { id: 'abc-123' } }))
3265
+ * })
3266
+ * @see {@link https://mswjs.io/docs/api/graphql/mutation `graphql.mutation()`}
3267
+ */
3244
3268
  mutation: createGraphQLScopedHandler('mutation', '*'),
3245
3269
  };
3270
+ /**
3271
+ * Creates a GraphQL mocking API scoped to the given endpoint.
3272
+ * @param uri Endpoint URL, or path.
3273
+ * @example
3274
+ * const api = graphql.link('https://api.site.com/graphql)
3275
+ * api.query('GetUser', resolver)
3276
+ * @see {@link https://mswjs.io/docs/api/graphql/link `graphql.link()`}
3277
+ */
3246
3278
  function createGraphQLLink(uri) {
3247
3279
  return {
3248
3280
  operation: createGraphQLOperationHandler(uri),
package/lib/esm/index.js CHANGED
@@ -618,6 +618,12 @@ function resetHandlers(initialHandlers, ...nextHandlers) {
618
618
  // Declare the list of event handlers on the module's scope
619
619
  // so it persists between Fash refreshes of the application's code.
620
620
  let listeners = [];
621
+ /**
622
+ * Creates a new mock Service Worker registration
623
+ * with the given request handlers.
624
+ * @param {RequestHandler[]} requestHandlers List of request handlers
625
+ * @see {@link https://mswjs.io/docs/api/setup-worker `setupWorker`}
626
+ */
621
627
  function setupWorker(...requestHandlers) {
622
628
  requestHandlers.forEach((handler) => {
623
629
  if (Array.isArray(handler))
@@ -1451,12 +1451,73 @@ ${queryParams
1451
1451
  };
1452
1452
  };
1453
1453
  const rest = {
1454
+ /**
1455
+ * Captures a HEAD request by a given path.
1456
+ * @example
1457
+ * rest.head('/numbers', (req, res, ctx) => {
1458
+ * return res(ctx.status(302))
1459
+ * })
1460
+ * @see {@link https://mswjs.io/docs/api/rest `rest`}
1461
+ */
1454
1462
  head: createRestHandler(RESTMethods.HEAD),
1463
+ /**
1464
+ * Captures a GET request by a given path.
1465
+ * @example
1466
+ * rest.get('/numbers', (req, res, ctx) => {
1467
+ * return res(ctx.json([1, 2, 3]))
1468
+ * })
1469
+ * @see {@link https://mswjs.io/docs/api/rest `rest`}
1470
+ */
1455
1471
  get: createRestHandler(RESTMethods.GET),
1472
+ /**
1473
+ * Captures a POST request by a given path.
1474
+ * @example
1475
+ * rest.post('/numbers', (req, res, ctx) => {
1476
+ * return res(ctx.text('success'))
1477
+ * })
1478
+ * @see {@link https://mswjs.io/docs/api/rest `rest`}
1479
+ */
1456
1480
  post: createRestHandler(RESTMethods.POST),
1481
+ /**
1482
+ * Captures a PUT request by a given path.
1483
+ * @example
1484
+ * rest.put('/numbers', (req, res, ctx) => {
1485
+ * const { numbers } = req.body
1486
+ * return res(ctx.json(numbers))
1487
+ * })
1488
+ * @see {@link https://mswjs.io/docs/api/rest `rest`}
1489
+ */
1457
1490
  put: createRestHandler(RESTMethods.PUT),
1491
+ /**
1492
+ * Captures a DELETE request by a given path.
1493
+ * @example
1494
+ * rest.delete('/numbers', (req, res, ctx) => {
1495
+ * const index = req.url.searchParams.get('index')
1496
+ * prevNumbers.splice(index, 1)
1497
+ * return res(ctx.json(nextNumbers))
1498
+ * })
1499
+ * @see {@link https://mswjs.io/docs/api/rest `rest`}
1500
+ */
1458
1501
  delete: createRestHandler(RESTMethods.DELETE),
1502
+ /**
1503
+ * Captures a PATCH request by a given path.
1504
+ * @example
1505
+ * rest.patch('/numbers', (req, res, ctx) => {
1506
+ * const { numbers } = req.body
1507
+ * const nextNumbers = prevNumbers.concat(number)
1508
+ * return res(ctx.json(nextNumbers))
1509
+ * })
1510
+ * @see {@link https://mswjs.io/docs/api/rest `rest`}
1511
+ */
1459
1512
  patch: createRestHandler(RESTMethods.PATCH),
1513
+ /**
1514
+ * Captures an OPTIONS request by a given path.
1515
+ * @example
1516
+ * rest.options('/numbers', (req, res, ctx) => {
1517
+ * return res(ctx.set('Allow', 'GET,HEAD,POST'))
1518
+ * })
1519
+ * @see {@link https://mswjs.io/docs/api/rest `rest`}
1520
+ */
1460
1521
  options: createRestHandler(RESTMethods.OPTIONS),
1461
1522
  };
1462
1523
 
@@ -200,9 +200,8 @@ function tryDecode(str, decode) {
200
200
  }
201
201
 
202
202
  /**
203
- * Sets a given cookie on the response.
204
- * @example
205
- * res(cookie('name', 'value'))
203
+ * Sets a given cookie on the mocked response.
204
+ * @example res(ctx.cookie('name', 'value'))
206
205
  */
207
206
  const cookie = (name, value, options) => {
208
207
  return (res) => {
@@ -216,9 +215,11 @@ const cookie = (name, value, options) => {
216
215
  };
217
216
 
218
217
  /**
219
- * Sets the body of the response without any `Content-Type` header.
218
+ * Sets a raw response body. Does not append any `Content-Type` headers.
220
219
  * @example
221
- * res(body('message'))
220
+ * res(ctx.body('Successful response'))
221
+ * res(ctx.body(JSON.stringify({ key: 'value' })))
222
+ * @see {@link https://mswjs.io/docs/api/context/body `ctx.body()`}
222
223
  */
223
224
  const body = (value) => {
224
225
  return (res) => {
@@ -228,9 +229,10 @@ const body = (value) => {
228
229
  };
229
230
 
230
231
  /**
231
- * Sets a given text as a "Cotent-Type: text/plain" body of the response.
232
- * @example
233
- * res(text('message'))
232
+ * Sets a textual response body. Appends a `Content-Type: text/plain`
233
+ * header on the mocked response.
234
+ * @example res(ctx.text('Successful response'))
235
+ * @see {@link https://mswjs.io/docs/api/context/text `ctx.text()`}
234
236
  */
235
237
  const text = (body) => {
236
238
  return (res) => {
@@ -241,9 +243,11 @@ const text = (body) => {
241
243
  };
242
244
 
243
245
  /**
244
- * Sets the given XML as the body of the response.
246
+ * Sets an XML response body. Appends a `Content-Type: text/xml` header
247
+ * on the mocked response.
245
248
  * @example
246
- * res(xml('<key>value</key>'))
249
+ * res(ctx.xml('<node key="value">Content</node>'))
250
+ * @see {@link https://mswjs.io/docs/api/context/xml `ctx.xml()`}
247
251
  */
248
252
  const xml = (body) => {
249
253
  return (res) => {
@@ -1,7 +1,9 @@
1
1
  import { ResponseTransformer } from '../response';
2
2
  /**
3
- * Sets the body of the response without any `Content-Type` header.
3
+ * Sets a raw response body. Does not append any `Content-Type` headers.
4
4
  * @example
5
- * res(body('message'))
5
+ * res(ctx.body('Successful response'))
6
+ * res(ctx.body(JSON.stringify({ key: 'value' })))
7
+ * @see {@link https://mswjs.io/docs/api/context/body `ctx.body()`}
6
8
  */
7
9
  export declare const body: <BodyType extends string | Blob | ArrayBufferView | ArrayBuffer | ReadableStream<any> | FormData>(value: BodyType) => ResponseTransformer<BodyType>;
@@ -1,8 +1,7 @@
1
1
  import * as cookieUtils from 'cookie';
2
2
  import { ResponseTransformer } from '../response';
3
3
  /**
4
- * Sets a given cookie on the response.
5
- * @example
6
- * res(cookie('name', 'value'))
4
+ * Sets a given cookie on the mocked response.
5
+ * @example res(ctx.cookie('name', 'value'))
7
6
  */
8
7
  export declare const cookie: (name: string, value: string, options?: cookieUtils.CookieSerializeOptions | undefined) => ResponseTransformer;
@@ -1,6 +1,8 @@
1
1
  import { ResponseTransformer } from '../response';
2
- export declare type DataContext<T> = (payload: T) => ResponseTransformer;
3
2
  /**
4
- * Returns a GraphQL body payload.
3
+ * Sets a given payload as a GraphQL response body.
4
+ * @example
5
+ * res(ctx.data({ user: { firstName: 'John' }}))
6
+ * @see {@link https://mswjs.io/docs/api/context/data `ctx.data()`}
5
7
  */
6
- export declare const data: DataContext<Record<string, any>>;
8
+ export declare const data: <T extends Record<string, any>>(payload: T) => ResponseTransformer;
@@ -3,9 +3,10 @@ export declare const MIN_SERVER_RESPONSE_TIME = 100;
3
3
  export declare const MAX_SERVER_RESPONSE_TIME = 400;
4
4
  export declare const NODE_SERVER_RESPONSE_TIME = 5;
5
5
  /**
6
- * Delays the current response for the given duration (in ms)
6
+ * Delays the response by the given duration (ms).
7
7
  * @example
8
- * res(delay()) // realistic server response time
9
- * res(delay(1500)) // explicit response delay duration
8
+ * res(ctx.delay()) // realistic server response time
9
+ * res(ctx.delay(1200))
10
+ * @see {@link https://mswjs.io/docs/api/context/delay `ctx.delay()`}
10
11
  */
11
12
  export declare const delay: (durationMs?: number | undefined) => ResponseTransformer;
@@ -2,5 +2,7 @@ import { GraphQLError } from 'graphql';
2
2
  import { ResponseTransformer } from '../response';
3
3
  /**
4
4
  * Sets a given list of GraphQL errors on the mocked response.
5
+ * @example res(ctx.errors([{ message: 'Unauthorized' }]))
6
+ * @see {@link https://mswjs.io/docs/api/context/errors}
5
7
  */
6
8
  export declare const errors: <ErrorsType extends Partial<GraphQLError>[] | null | undefined>(errorsList: ErrorsType) => ResponseTransformer<string>;
@@ -1,8 +1,9 @@
1
1
  import { MockedRequest } from '../utils/handlers/requestHandler';
2
2
  export declare const augmentRequestInit: (requestInit: RequestInit) => RequestInit;
3
3
  /**
4
- * Wrapper around the native `window.fetch()` function that performs
5
- * a request bypassing MSW. Requests performed using
6
- * this function will never be mocked.
4
+ * Performs a bypassed request inside a request handler.
5
+ * @example
6
+ * const originalResponse = await ctx.fetch(req)
7
+ * @see {@link https://mswjs.io/docs/api/context/fetch `ctx.fetch()`}
7
8
  */
8
9
  export declare const fetch: (input: string | MockedRequest, requestInit?: RequestInit) => any;
@@ -1,9 +1,12 @@
1
1
  import { ResponseTransformer } from '../response';
2
2
  /**
3
3
  * Sets the given value as the JSON body of the response.
4
+ * Appends a `Content-Type: application/json` header on the
5
+ * mocked response.
4
6
  * @example
5
- * res(json({ key: 'value' }))
6
- * res(json('Some string'))
7
- * res(json([1, '2', false, { ok: true }]))
7
+ * res(ctx.json('Some string'))
8
+ * res(ctx.json({ key: 'value' }))
9
+ * res(ctx.json([1, '2', false, { ok: true }]))
10
+ * @see {@link https://mswjs.io/docs/api/context/json `ctx.json()`}
8
11
  */
9
12
  export declare const json: <BodyTypeJSON>(body: BodyTypeJSON) => ResponseTransformer<string>;
@@ -1,2 +1,6 @@
1
1
  import { ResponseTransformer } from '../response';
2
+ /**
3
+ * Sets one or multiple response headers.
4
+ * @see {@link https://mswjs.io/docs/api/context/set `ctx.set()`}
5
+ */
2
6
  export declare function set<N extends string | Record<string, string | string[]>>(...args: N extends string ? [N, string] : [N]): ResponseTransformer;
@@ -1,2 +1,9 @@
1
1
  import { ResponseTransformer } from '../response';
2
+ /**
3
+ * Sets a response status code and text.
4
+ * @example
5
+ * res(ctx.status(301))
6
+ * res(ctx.status(400, 'Custom status text'))
7
+ * @see {@link https://mswjs.io/docs/api/context/status `ctx.status()`}
8
+ */
2
9
  export declare const status: (statusCode: number, statusText?: string | undefined) => ResponseTransformer;
@@ -1,7 +1,8 @@
1
1
  import { ResponseTransformer } from '../response';
2
2
  /**
3
- * Sets a given text as a "Cotent-Type: text/plain" body of the response.
4
- * @example
5
- * res(text('message'))
3
+ * Sets a textual response body. Appends a `Content-Type: text/plain`
4
+ * header on the mocked response.
5
+ * @example res(ctx.text('Successful response'))
6
+ * @see {@link https://mswjs.io/docs/api/context/text `ctx.text()`}
6
7
  */
7
8
  export declare const text: <BodyType extends string>(body: BodyType) => ResponseTransformer<BodyType>;
@@ -1,7 +1,9 @@
1
1
  import { ResponseTransformer } from '../response';
2
2
  /**
3
- * Sets the given XML as the body of the response.
3
+ * Sets an XML response body. Appends a `Content-Type: text/xml` header
4
+ * on the mocked response.
4
5
  * @example
5
- * res(xml('<key>value</key>'))
6
+ * res(ctx.xml('<node key="value">Content</node>'))
7
+ * @see {@link https://mswjs.io/docs/api/context/xml `ctx.xml()`}
6
8
  */
7
9
  export declare const xml: <BodyType extends string>(body: BodyType) => ResponseTransformer<BodyType>;
@@ -6,7 +6,7 @@ import { set } from './context/set';
6
6
  import { status } from './context/status';
7
7
  import { delay } from './context/delay';
8
8
  import { fetch } from './context/fetch';
9
- import { DataContext } from './context/data';
9
+ import { data } from './context/data';
10
10
  import { errors } from './context/errors';
11
11
  declare type GraphQLRequestHandlerSelector = RegExp | string;
12
12
  export declare type GraphQLMockedRequest<VariablesType = Record<string, any>> = Omit<MockedRequest, 'body'> & {
@@ -18,7 +18,7 @@ export interface GraphQLMockedContext<QueryType> {
18
18
  status: typeof status;
19
19
  delay: typeof delay;
20
20
  fetch: typeof fetch;
21
- data: DataContext<QueryType>;
21
+ data: typeof data;
22
22
  errors: typeof errors;
23
23
  }
24
24
  export declare const graphqlContext: GraphQLMockedContext<any>;
@@ -33,15 +33,71 @@ export interface GraphQLRequestParsedResult<VariablesType> {
33
33
  variables: VariablesType | undefined;
34
34
  }
35
35
  declare const graphqlStandardHandlers: {
36
+ /**
37
+ * Captures any GraphQL operation, regardless of its name, under the current scope.
38
+ * @example
39
+ * graphql.operation((req, res, ctx) => {
40
+ * return res(ctx.data({ name: 'John' }))
41
+ * })
42
+ * @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
43
+ */
36
44
  operation: <QueryType, VariablesType = Record<string, any>>(resolver: GraphQLResponseResolver<QueryType, VariablesType>) => RequestHandler<GraphQLMockedRequest<VariablesType>, GraphQLMockedContext<QueryType>, GraphQLRequestParsedResult<VariablesType>, GraphQLMockedRequest<VariablesType>, any>;
45
+ /**
46
+ * Captures a GraphQL query by a given name.
47
+ * @example
48
+ * graphql.query('GetUser', (req, res, ctx) => {
49
+ * return res(ctx.data({ user: { name: 'John' } }))
50
+ * })
51
+ * @see {@link https://mswjs.io/docs/api/graphql/query `graphql.query()`}
52
+ */
37
53
  query: <QueryType_1, VariablesType_1 = Record<string, any>>(expectedOperationName: GraphQLRequestHandlerSelector, resolver: GraphQLResponseResolver<QueryType_1, VariablesType_1>) => RequestHandler<GraphQLMockedRequest<VariablesType_1>, GraphQLMockedContext<QueryType_1>, GraphQLRequestParsedResult<VariablesType_1>, GraphQLMockedRequest<VariablesType_1>, any>;
54
+ /**
55
+ * Captures a GraphQL mutation by a given name.
56
+ * @example
57
+ * graphql.mutation('SavePost', (req, res, ctx) => {
58
+ * return res(ctx.data({ post: { id: 'abc-123' } }))
59
+ * })
60
+ * @see {@link https://mswjs.io/docs/api/graphql/mutation `graphql.mutation()`}
61
+ */
38
62
  mutation: <QueryType_1, VariablesType_1 = Record<string, any>>(expectedOperationName: GraphQLRequestHandlerSelector, resolver: GraphQLResponseResolver<QueryType_1, VariablesType_1>) => RequestHandler<GraphQLMockedRequest<VariablesType_1>, GraphQLMockedContext<QueryType_1>, GraphQLRequestParsedResult<VariablesType_1>, GraphQLMockedRequest<VariablesType_1>, any>;
39
63
  };
64
+ /**
65
+ * Creates a GraphQL mocking API scoped to the given endpoint.
66
+ * @param uri Endpoint URL, or path.
67
+ * @example
68
+ * const api = graphql.link('https://api.site.com/graphql)
69
+ * api.query('GetUser', resolver)
70
+ * @see {@link https://mswjs.io/docs/api/graphql/link `graphql.link()`}
71
+ */
40
72
  declare function createGraphQLLink(uri: Mask): typeof graphqlStandardHandlers;
41
73
  export declare const graphql: {
42
74
  link: typeof createGraphQLLink;
75
+ /**
76
+ * Captures any GraphQL operation, regardless of its name, under the current scope.
77
+ * @example
78
+ * graphql.operation((req, res, ctx) => {
79
+ * return res(ctx.data({ name: 'John' }))
80
+ * })
81
+ * @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
82
+ */
43
83
  operation: <QueryType, VariablesType = Record<string, any>>(resolver: GraphQLResponseResolver<QueryType, VariablesType>) => RequestHandler<GraphQLMockedRequest<VariablesType>, GraphQLMockedContext<QueryType>, GraphQLRequestParsedResult<VariablesType>, GraphQLMockedRequest<VariablesType>, any>;
84
+ /**
85
+ * Captures a GraphQL query by a given name.
86
+ * @example
87
+ * graphql.query('GetUser', (req, res, ctx) => {
88
+ * return res(ctx.data({ user: { name: 'John' } }))
89
+ * })
90
+ * @see {@link https://mswjs.io/docs/api/graphql/query `graphql.query()`}
91
+ */
44
92
  query: <QueryType_1, VariablesType_1 = Record<string, any>>(expectedOperationName: GraphQLRequestHandlerSelector, resolver: GraphQLResponseResolver<QueryType_1, VariablesType_1>) => RequestHandler<GraphQLMockedRequest<VariablesType_1>, GraphQLMockedContext<QueryType_1>, GraphQLRequestParsedResult<VariablesType_1>, GraphQLMockedRequest<VariablesType_1>, any>;
93
+ /**
94
+ * Captures a GraphQL mutation by a given name.
95
+ * @example
96
+ * graphql.mutation('SavePost', (req, res, ctx) => {
97
+ * return res(ctx.data({ post: { id: 'abc-123' } }))
98
+ * })
99
+ * @see {@link https://mswjs.io/docs/api/graphql/mutation `graphql.mutation()`}
100
+ */
45
101
  mutation: <QueryType_1, VariablesType_1 = Record<string, any>>(expectedOperationName: GraphQLRequestHandlerSelector, resolver: GraphQLResponseResolver<QueryType_1, VariablesType_1>) => RequestHandler<GraphQLMockedRequest<VariablesType_1>, GraphQLMockedContext<QueryType_1>, GraphQLRequestParsedResult<VariablesType_1>, GraphQLMockedRequest<VariablesType_1>, any>;
46
102
  };
47
103
  export {};
@@ -2,27 +2,33 @@ import { SharedOptions } from '../sharedOptions';
2
2
  import { RequestHandlersList } from '../setupWorker/glossary';
3
3
  export interface SetupServerApi {
4
4
  /**
5
- * Enables requests interception based on the previously provided mock definition.
5
+ * Starts requests interception based on the previously provided request handlers.
6
+ * @see {@link https://mswjs.io/docs/api/setup-server/listen `server.listen()`}
6
7
  */
7
8
  listen: (options?: SharedOptions) => void;
9
+ /**
10
+ * Stops requests interception by restoring all augmented modules.
11
+ * @see {@link https://mswjs.io/docs/api/setup-server/close `server.close()`}
12
+ */
13
+ close: () => void;
8
14
  /**
9
15
  * Prepends given request handlers to the list of existing handlers.
16
+ * @see {@link https://mswjs.io/docs/api/setup-server/use `server.use()`}
10
17
  */
11
18
  use: (...handlers: RequestHandlersList) => void;
12
19
  /**
13
20
  * Marks all request handlers that respond using `res.once()` as unused.
21
+ * @see {@link https://mswjs.io/docs/api/setup-server/restore-handlers `server.restore-handlers()`}
14
22
  */
15
23
  restoreHandlers: () => void;
16
24
  /**
17
25
  * Resets request handlers to the initial list given to the `setupServer` call, or to the explicit next request handlers list, if given.
26
+ * @see {@link https://mswjs.io/docs/api/setup-server/reset-handlers `server.reset-handlers()`}
18
27
  */
19
28
  resetHandlers: (...nextHandlers: RequestHandlersList) => void;
20
29
  /**
21
30
  * Lists all active request handlers.
31
+ * @see {@link https://mswjs.io/docs/api/setup-server/print-handlers `server.print-handlers()`}
22
32
  */
23
33
  printHandlers: () => void;
24
- /**
25
- * Stops requests interception by restoring all augmented modules.
26
- */
27
- close: () => void;
28
34
  }
@@ -1 +1,6 @@
1
+ /**
2
+ * Sets up a requests interception in NodeJS with the given request handlers.
3
+ * @param {RequestHandler[]} requestHandlers List of request handlers.
4
+ * @see {@link https://mswjs.io/docs/api/setup-server `setupServer`}
5
+ */
1
6
  export declare const setupServer: (...requestHandlers: import("../setupWorker/glossary").RequestHandlersList) => import("./glossary").SetupServerApi;