Skip to content

Commit

Permalink
Sync subscription TS defintions with Flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson Kearl authored and IvanGoncharov committed Aug 23, 2019
1 parent 7d9ad14 commit 49f86be
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
6 changes: 6 additions & 0 deletions tstypes/subscription/asyncIteratorReject.d.ts
@@ -0,0 +1,6 @@
/**
* Given an error, returns an AsyncIterable which will fail with that error.
*
* Similar to Promise.reject(error)
*/
export default function asyncIteratorReject(error: Error): AsyncIterator<void>;
6 changes: 5 additions & 1 deletion tstypes/subscription/index.d.ts
@@ -1 +1,5 @@
export { subscribe, createSourceEventStream } from './subscribe';
export {
subscribe,
createSourceEventStream,
SubscriptionArgs,
} from './subscribe';
9 changes: 9 additions & 0 deletions tstypes/subscription/mapAsyncIterator.d.ts
@@ -0,0 +1,9 @@
/**
* Given an AsyncIterable and a callback function, return an AsyncIterator
* which produces values mapped via calling the callback function.
*/
export default function mapAsyncIterator<T, U>(
iterable: AsyncIterable<T>,
callback: (arg: T) => PromiseOrValue<U>,
rejectCallback?: (arg: any) => PromiseOrValue<U>,
): AsyncGenerator<U, void, void>;
28 changes: 16 additions & 12 deletions tstypes/subscription/subscribe.d.ts
@@ -1,11 +1,22 @@
import Maybe from '../tsutils/Maybe';
import { GraphQLSchema } from '../type/schema';
import { DocumentNode } from '../language/ast';
import { GraphQLFieldResolver } from '../type/definition';
import {
ExecutionResult,
ExecutionResultDataDefault,
} from '../execution/execute';
import { GraphQLSchema } from '../type/schema';
import { GraphQLFieldResolver } from '../type/definition';

export interface SubscriptionArgs {
schema: GraphQLSchema;
document: DocumentNode;
rootValue?: any;
contextValue?: any;
variableValues?: Maybe<Record<string, any>>;
operationName?: Maybe<string>;
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
}

/**
* Implements the "Subscribe" algorithm described in the GraphQL specification.
Expand All @@ -27,16 +38,9 @@ import {
*
* Accepts either an object with named arguments, or individual arguments.
*/
export function subscribe<TData = ExecutionResultDataDefault>(args: {
schema: GraphQLSchema;
document: DocumentNode;
rootValue?: any;
contextValue?: any;
variableValues?: Maybe<{ [key: string]: any }>;
operationName?: Maybe<string>;
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
}): Promise<
export function subscribe<TData = ExecutionResultDataDefault>(
args: SubscriptionArgs,
): Promise<
AsyncIterableIterator<ExecutionResult<TData>> | ExecutionResult<TData>
>;

Expand Down

0 comments on commit 49f86be

Please sign in to comment.