Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync subscription TS definitions with Flow #2108

Merged
merged 1 commit into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tstypes/subscription/asyncIteratorReject.d.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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