UNPKG

4.54 kBTypeScriptView Raw
1import { OperationTypeNode, DocumentNode, GraphQLError } from 'graphql';
2import { g as RequestHandlerDefaultInfo, D as DefaultBodyType, R as RequestHandler, a as ResponseResolver, c as RequestHandlerOptions } from './HttpResponse-5Sn2vNaJ.js';
3import { Match, Path } from './utils/matching/matchRequestUrl.js';
4
5interface ParsedGraphQLQuery {
6 operationType: OperationTypeNode;
7 operationName?: string;
8}
9type ParsedGraphQLRequest<VariablesType extends GraphQLVariables = GraphQLVariables> = (ParsedGraphQLQuery & {
10 query: string;
11 variables?: VariablesType;
12}) | undefined;
13declare function parseDocumentNode(node: DocumentNode): ParsedGraphQLQuery;
14type GraphQLParsedOperationsMap = Record<string, string[]>;
15type 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 */
25declare function parseGraphQLRequest(request: Request): Promise<ParsedGraphQLRequest>;
26
27type ExpectedOperationTypeNode = OperationTypeNode | 'all';
28type GraphQLHandlerNameSelector = DocumentNode | RegExp | string;
29type GraphQLQuery = Record<string, any>;
30type GraphQLVariables = Record<string, any>;
31interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {
32 operationType: ExpectedOperationTypeNode;
33 operationName: GraphQLHandlerNameSelector;
34}
35type 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});
50type GraphQLResolverExtras<Variables extends GraphQLVariables> = {
51 query: string;
52 operationName: string;
53 variables: Variables;
54 cookies: Record<string, string>;
55};
56type GraphQLRequestBody<VariablesType extends GraphQLVariables> = GraphQLJsonRequestBody<VariablesType> | GraphQLMultipartRequestBody | Record<string, any> | undefined;
57interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {
58 query: string;
59 variables?: Variables;
60}
61type GraphQLResponseBody<BodyType extends DefaultBodyType> = {
62 data?: BodyType | null;
63 errors?: readonly Partial<GraphQLError>[] | null;
64} | null | undefined;
65declare function isDocumentNode(value: DocumentNode | any): value is DocumentNode;
66declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, GraphQLRequestParsedResult, GraphQLResolverExtras<any>> {
67 private endpoint;
68 static parsedRequestCache: WeakMap<Request, ParsedGraphQLRequest<GraphQLVariables>>;
69 constructor(operationType: ExpectedOperationTypeNode, operationName: GraphQLHandlerNameSelector, endpoint: Path, resolver: ResponseResolver<GraphQLResolverExtras<any>, any, any>, options?: RequestHandlerOptions);
70 /**
71 * Parses the request body, once per request, cached across all
72 * GraphQL handlers. This is done to avoid multiple parsing of the
73 * request body, which each requires a clone of the request.
74 */
75 parseGraphQLRequestOrGetFromCache(request: Request): Promise<ParsedGraphQLRequest<GraphQLVariables>>;
76 parse(args: {
77 request: Request;
78 }): Promise<GraphQLRequestParsedResult>;
79 predicate(args: {
80 request: Request;
81 parsedResult: GraphQLRequestParsedResult;
82 }): boolean;
83 protected extendResolverArgs(args: {
84 request: Request;
85 parsedResult: GraphQLRequestParsedResult;
86 }): {
87 query: string;
88 operationName: string;
89 variables: GraphQLVariables;
90 cookies: Record<string, string>;
91 };
92 log(args: {
93 request: Request;
94 response: Response;
95 parsedResult: GraphQLRequestParsedResult;
96 }): Promise<void>;
97}
98
99export { 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 };