UNPKG

4.83 kBTypeScriptView Raw
1import { DocumentNode } from 'graphql';
2import { c as RequestHandlerOptions, a as ResponseResolver } from './HttpResponse-5Sn2vNaJ.js';
3import { a as GraphQLQuery, b as GraphQLVariables, e as GraphQLHandlerNameSelector, G as GraphQLHandler, f as GraphQLResolverExtras, g as GraphQLResponseBody } from './GraphQLHandler-C5CUIS_N.js';
4import { Path } from './utils/matching/matchRequestUrl.js';
5import './utils/internal/isIterable.js';
6import './typeUtils.js';
7
8interface TypedDocumentNode<Result = {
9 [key: string]: any;
10}, Variables = {
11 [key: string]: any;
12}> extends DocumentNode {
13 __apiType?: (variables: Variables) => Result;
14 __resultType?: Result;
15 __variablesType?: Variables;
16}
17type GraphQLRequestHandler = <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(operationName: GraphQLHandlerNameSelector | DocumentNode | TypedDocumentNode<Query, Variables>, resolver: GraphQLResponseResolver<[
18 Query
19] extends [never] ? GraphQLQuery : Query, Variables>, options?: RequestHandlerOptions) => GraphQLHandler;
20type GraphQLResponseResolver<Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables> = ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<[Query] extends [never] ? GraphQLQuery : Query>>;
21declare const standardGraphQLHandlers: {
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 */
32 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 mutation: GraphQLRequestHandler;
45 /**
46 * Intercepts any GraphQL operation, regardless of its type or name.
47 *
48 * @example
49 * graphql.operation(() => {
50 * return HttpResponse.json({ data: { name: 'John' } })
51 * })
52 *
53 * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
54 */
55 operation: <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>) => GraphQLHandler;
56};
57declare function createGraphQLLink(url: Path): typeof standardGraphQLHandlers;
58/**
59 * A namespace to intercept and mock GraphQL operations
60 *
61 * @example
62 * graphql.query('GetUser', resolver)
63 * graphql.mutation('DeletePost', resolver)
64 *
65 * @see {@link https://mswjs.io/docs/api/graphql `graphql` API reference}
66 */
67declare 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 /**
79 * Intercepts a GraphQL query by a given name.
80 *
81 * @example
82 * graphql.query('GetUser', () => {
83 * return HttpResponse.json({ data: { user: { name: 'John' } } })
84 * })
85 *
86 * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
87 */
88 query: GraphQLRequestHandler;
89 /**
90 * Intercepts a GraphQL mutation by its name.
91 *
92 * @example
93 * graphql.mutation('SavePost', () => {
94 * return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
95 * })
96 *
97 * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
98 *
99 */
100 mutation: GraphQLRequestHandler;
101 /**
102 * Intercepts any GraphQL operation, regardless of its type or name.
103 *
104 * @example
105 * graphql.operation(() => {
106 * return HttpResponse.json({ data: { name: 'John' } })
107 * })
108 *
109 * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
110 */
111 operation: <Query extends GraphQLQuery = GraphQLQuery, Variables extends GraphQLVariables = GraphQLVariables>(resolver: ResponseResolver<GraphQLResolverExtras<Variables>, null, GraphQLResponseBody<Query>>) => GraphQLHandler;
112};
113
114export { type GraphQLRequestHandler, type GraphQLResponseResolver, type TypedDocumentNode, graphql };