@depup/express-graphql 0.12.0-depup.0

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.
@@ -0,0 +1,146 @@
1
+ /// <reference types="node" />
2
+ import { IncomingMessage, ServerResponse } from 'http';
3
+ import { ASTVisitor, DocumentNode, ValidationRule, ValidationContext, ExecutionArgs, ExecutionResult, FormattedExecutionResult, GraphQLSchema, GraphQLFieldResolver, GraphQLTypeResolver, GraphQLFormattedError } from 'graphql';
4
+ import { Source, GraphQLError } from 'graphql';
5
+ import { GraphiQLOptions } from './renderGraphiQL';
6
+ declare type Request = IncomingMessage & {
7
+ url: string;
8
+ };
9
+ declare type Response = ServerResponse & {
10
+ json?: (data: unknown) => void;
11
+ };
12
+ declare type MaybePromise<T> = Promise<T> | T;
13
+ /**
14
+ * Used to configure the graphqlHTTP middleware by providing a schema
15
+ * and other configuration options.
16
+ *
17
+ * Options can be provided as an Object, a Promise for an Object, or a Function
18
+ * that returns an Object or a Promise for an Object.
19
+ */
20
+ export declare type Options = ((request: Request, response: Response, params?: GraphQLParams) => MaybePromise<OptionsData>) | MaybePromise<OptionsData>;
21
+ export interface OptionsData {
22
+ /**
23
+ * A GraphQL schema from graphql-js.
24
+ */
25
+ schema: GraphQLSchema;
26
+ /**
27
+ * A value to pass as the context to this middleware.
28
+ */
29
+ context?: unknown;
30
+ /**
31
+ * An object to pass as the rootValue to the graphql() function.
32
+ */
33
+ rootValue?: unknown;
34
+ /**
35
+ * A boolean to configure whether the output should be pretty-printed.
36
+ */
37
+ pretty?: boolean;
38
+ /**
39
+ * An optional array of validation rules that will be applied on the document
40
+ * in additional to those defined by the GraphQL spec.
41
+ */
42
+ validationRules?: ReadonlyArray<(ctx: ValidationContext) => ASTVisitor>;
43
+ /**
44
+ * An optional function which will be used to validate instead of default `validate`
45
+ * from `graphql-js`.
46
+ */
47
+ customValidateFn?: (schema: GraphQLSchema, documentAST: DocumentNode, rules: ReadonlyArray<ValidationRule>) => ReadonlyArray<GraphQLError>;
48
+ /**
49
+ * An optional function which will be used to execute instead of default `execute`
50
+ * from `graphql-js`.
51
+ */
52
+ customExecuteFn?: (args: ExecutionArgs) => MaybePromise<ExecutionResult>;
53
+ /**
54
+ * An optional function which will be used to format any errors produced by
55
+ * fulfilling a GraphQL operation. If no function is provided, GraphQL's
56
+ * default spec-compliant `formatError` function will be used.
57
+ */
58
+ customFormatErrorFn?: (error: GraphQLError) => GraphQLFormattedError;
59
+ /**
60
+ * An optional function which will be used to create a document instead of
61
+ * the default `parse` from `graphql-js`.
62
+ */
63
+ customParseFn?: (source: Source) => DocumentNode;
64
+ /**
65
+ * `formatError` is deprecated and replaced by `customFormatErrorFn`. It will
66
+ * be removed in version 1.0.0.
67
+ */
68
+ formatError?: (error: GraphQLError) => GraphQLFormattedError;
69
+ /**
70
+ * An optional function for adding additional metadata to the GraphQL response
71
+ * as a key-value object. The result will be added to "extensions" field in
72
+ * the resulting JSON. This is often a useful place to add development time
73
+ * info such as the runtime of a query or the amount of resources consumed.
74
+ *
75
+ * Information about the request is provided to be used.
76
+ *
77
+ * This function may be async.
78
+ */
79
+ extensions?: (info: RequestInfo) => MaybePromise<undefined | {
80
+ [key: string]: unknown;
81
+ }>;
82
+ /**
83
+ * A boolean to optionally enable GraphiQL mode.
84
+ * Alternatively, instead of `true` you can pass in an options object.
85
+ */
86
+ graphiql?: boolean | GraphiQLOptions;
87
+ /**
88
+ * A resolver function to use when one is not provided by the schema.
89
+ * If not provided, the default field resolver is used (which looks for a
90
+ * value or method on the source value with the field's name).
91
+ */
92
+ fieldResolver?: GraphQLFieldResolver<unknown, unknown>;
93
+ /**
94
+ * A type resolver function to use when none is provided by the schema.
95
+ * If not provided, the default type resolver is used (which looks for a
96
+ * `__typename` field or alternatively calls the `isTypeOf` method).
97
+ */
98
+ typeResolver?: GraphQLTypeResolver<unknown, unknown>;
99
+ }
100
+ /**
101
+ * All information about a GraphQL request.
102
+ */
103
+ export interface RequestInfo {
104
+ /**
105
+ * The parsed GraphQL document.
106
+ */
107
+ document: DocumentNode;
108
+ /**
109
+ * The variable values used at runtime.
110
+ */
111
+ variables: {
112
+ readonly [name: string]: unknown;
113
+ } | null;
114
+ /**
115
+ * The (optional) operation name requested.
116
+ */
117
+ operationName: string | null;
118
+ /**
119
+ * The result of executing the operation.
120
+ */
121
+ result: FormattedExecutionResult;
122
+ /**
123
+ * A value to pass as the context to the graphql() function.
124
+ */
125
+ context?: unknown;
126
+ }
127
+ declare type Middleware = (request: Request, response: Response) => Promise<void>;
128
+ /**
129
+ * Middleware for express; takes an options object or function as input to
130
+ * configure behavior, and returns an express middleware.
131
+ */
132
+ export declare function graphqlHTTP(options: Options): Middleware;
133
+ export interface GraphQLParams {
134
+ query: string | null;
135
+ variables: {
136
+ readonly [name: string]: unknown;
137
+ } | null;
138
+ operationName: string | null;
139
+ raw: boolean;
140
+ }
141
+ /**
142
+ * Provided a "Request" provided by express or connect (typically a node style
143
+ * HTTPClientRequest), Promise the GraphQL request parameters.
144
+ */
145
+ export declare function getGraphQLParams(request: Request): Promise<GraphQLParams>;
146
+ export {};
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import { IncomingMessage } from 'http';
3
+ declare type Request = IncomingMessage & {
4
+ body?: unknown;
5
+ };
6
+ /**
7
+ * Provided a "Request" provided by express or connect (typically a node style
8
+ * HTTPClientRequest), Promise the body data contained.
9
+ */
10
+ export declare function parseBody(req: Request): Promise<{
11
+ [param: string]: unknown;
12
+ }>;
13
+ export {};
@@ -0,0 +1,30 @@
1
+ import { FormattedExecutionResult } from 'graphql';
2
+ export interface GraphiQLData {
3
+ query?: string | null;
4
+ variables?: {
5
+ readonly [name: string]: unknown;
6
+ } | null;
7
+ operationName?: string | null;
8
+ result?: FormattedExecutionResult;
9
+ }
10
+ export interface GraphiQLOptions {
11
+ /**
12
+ * An optional GraphQL string to use when no query is provided and no stored
13
+ * query exists from a previous session. If undefined is provided, GraphiQL
14
+ * will use its own default query.
15
+ */
16
+ defaultQuery?: string;
17
+ /**
18
+ * An optional boolean which enables the header editor when true.
19
+ * Defaults to false.
20
+ */
21
+ headerEditorEnabled?: boolean;
22
+ }
23
+ /**
24
+ * When express-graphql receives a request which does not Accept JSON, but does
25
+ * Accept HTML, it may present GraphiQL, the in-browser GraphQL explorer IDE.
26
+ *
27
+ * When shown, it will be pre-populated with the result of having executed the
28
+ * requested query.
29
+ */
30
+ export declare function renderGraphiQL(data: GraphiQLData, options?: GraphiQLOptions): string;