UNPKG

3.38 kBTypeScriptView Raw
1import type { Maybe } from '../jsutils/Maybe';
2import type { DocumentNode } from '../language/ast';
3import type { GraphQLFieldResolver } from '../type/definition';
4import type { GraphQLSchema } from '../type/schema';
5import type { ExecutionArgs, ExecutionResult } from './execute';
6/**
7 * Implements the "Subscribe" algorithm described in the GraphQL specification.
8 *
9 * Returns a Promise which resolves to either an AsyncIterator (if successful)
10 * or an ExecutionResult (error). The promise will be rejected if the schema or
11 * other arguments to this function are invalid, or if the resolved event stream
12 * is not an async iterable.
13 *
14 * If the client-provided arguments to this function do not result in a
15 * compliant subscription, a GraphQL Response (ExecutionResult) with
16 * descriptive errors and no data will be returned.
17 *
18 * If the source stream could not be created due to faulty subscription
19 * resolver logic or underlying systems, the promise will resolve to a single
20 * ExecutionResult containing `errors` and no `data`.
21 *
22 * If the operation succeeded, the promise resolves to an AsyncIterator, which
23 * yields a stream of ExecutionResults representing the response stream.
24 *
25 * Accepts either an object with named arguments, or individual arguments.
26 */
27export declare function subscribe(
28 args: ExecutionArgs,
29): Promise<AsyncGenerator<ExecutionResult, void, void> | ExecutionResult>;
30/**
31 * Implements the "CreateSourceEventStream" algorithm described in the
32 * GraphQL specification, resolving the subscription source event stream.
33 *
34 * Returns a Promise which resolves to either an AsyncIterable (if successful)
35 * or an ExecutionResult (error). The promise will be rejected if the schema or
36 * other arguments to this function are invalid, or if the resolved event stream
37 * is not an async iterable.
38 *
39 * If the client-provided arguments to this function do not result in a
40 * compliant subscription, a GraphQL Response (ExecutionResult) with
41 * descriptive errors and no data will be returned.
42 *
43 * If the the source stream could not be created due to faulty subscription
44 * resolver logic or underlying systems, the promise will resolve to a single
45 * ExecutionResult containing `errors` and no `data`.
46 *
47 * If the operation succeeded, the promise resolves to the AsyncIterable for the
48 * event stream returned by the resolver.
49 *
50 * A Source Event Stream represents a sequence of events, each of which triggers
51 * a GraphQL execution for that event.
52 *
53 * This may be useful when hosting the stateful subscription service in a
54 * different process or machine than the stateless GraphQL execution engine,
55 * or otherwise separating these two steps. For more on this, see the
56 * "Supporting Subscriptions at Scale" information in the GraphQL specification.
57 */
58export declare function createSourceEventStream(
59 args: ExecutionArgs,
60): Promise<AsyncIterable<unknown> | ExecutionResult>;
61/** @deprecated will be removed in next major version in favor of named arguments */
62export declare function createSourceEventStream(
63 schema: GraphQLSchema,
64 document: DocumentNode,
65 rootValue?: unknown,
66 contextValue?: unknown,
67 variableValues?: Maybe<{
68 readonly [variable: string]: unknown;
69 }>,
70 operationName?: Maybe<string>,
71 subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
72): Promise<AsyncIterable<unknown> | ExecutionResult>;