Skip to content

Commit 49f86be

Browse files
Jackson KearlIvanGoncharov
authored andcommitted
Sync subscription TS defintions with Flow
1 parent 7d9ad14 commit 49f86be

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Given an error, returns an AsyncIterable which will fail with that error.
3+
*
4+
* Similar to Promise.reject(error)
5+
*/
6+
export default function asyncIteratorReject(error: Error): AsyncIterator<void>;

tstypes/subscription/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export { subscribe, createSourceEventStream } from './subscribe';
1+
export {
2+
subscribe,
3+
createSourceEventStream,
4+
SubscriptionArgs,
5+
} from './subscribe';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Given an AsyncIterable and a callback function, return an AsyncIterator
3+
* which produces values mapped via calling the callback function.
4+
*/
5+
export default function mapAsyncIterator<T, U>(
6+
iterable: AsyncIterable<T>,
7+
callback: (arg: T) => PromiseOrValue<U>,
8+
rejectCallback?: (arg: any) => PromiseOrValue<U>,
9+
): AsyncGenerator<U, void, void>;

tstypes/subscription/subscribe.d.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import Maybe from '../tsutils/Maybe';
2-
import { GraphQLSchema } from '../type/schema';
32
import { DocumentNode } from '../language/ast';
4-
import { GraphQLFieldResolver } from '../type/definition';
53
import {
64
ExecutionResult,
75
ExecutionResultDataDefault,
86
} from '../execution/execute';
7+
import { GraphQLSchema } from '../type/schema';
8+
import { GraphQLFieldResolver } from '../type/definition';
9+
10+
export interface SubscriptionArgs {
11+
schema: GraphQLSchema;
12+
document: DocumentNode;
13+
rootValue?: any;
14+
contextValue?: any;
15+
variableValues?: Maybe<Record<string, any>>;
16+
operationName?: Maybe<string>;
17+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
18+
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
19+
}
920

1021
/**
1122
* Implements the "Subscribe" algorithm described in the GraphQL specification.
@@ -27,16 +38,9 @@ import {
2738
*
2839
* Accepts either an object with named arguments, or individual arguments.
2940
*/
30-
export function subscribe<TData = ExecutionResultDataDefault>(args: {
31-
schema: GraphQLSchema;
32-
document: DocumentNode;
33-
rootValue?: any;
34-
contextValue?: any;
35-
variableValues?: Maybe<{ [key: string]: any }>;
36-
operationName?: Maybe<string>;
37-
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
38-
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
39-
}): Promise<
41+
export function subscribe<TData = ExecutionResultDataDefault>(
42+
args: SubscriptionArgs,
43+
): Promise<
4044
AsyncIterableIterator<ExecutionResult<TData>> | ExecutionResult<TData>
4145
>;
4246

0 commit comments

Comments
 (0)