diff --git a/examples/subscriptions.ts b/examples/subscriptions.ts index f972155..b3ca3d4 100644 --- a/examples/subscriptions.ts +++ b/examples/subscriptions.ts @@ -7,7 +7,8 @@ const queryType = g.type('Query', { }) const subscriptionType = g.type('Subscription', { - counter: g.int() + counter: g.int(), + winner: g.string() }) const resolvers: InferResolvers<{ Subscription: typeof subscriptionType }, {}> = { @@ -19,6 +20,14 @@ const resolvers: InferResolvers<{ Subscription: typeof subscriptionType }, {}> = yield { counter: i } } } + }, + winner: { + subscribe: async function* (parent, args, context, info) { + for (let i = 100; i >= 0; i--) { + await new Promise((resolve) => setTimeout(resolve, 1000)) + yield { winner: `User ${i}` } + } + } } } } diff --git a/src/index.ts b/src/index.ts index 2a19466..6b40990 100644 --- a/src/index.ts +++ b/src/index.ts @@ -134,7 +134,9 @@ export type InferUnionNames = T extends AnyUnion ? ObjectToUnion export type InferResolvers = { [K in keyof T]: K extends 'Subscription' ? { [G in keyof T[K]['_shape']]?: { - subscribe: (parent: {}, args: InferArg, context: X['context'], info: GraphQLResolveInfo) => MaybePromise }>> + subscribe: (parent: {}, args: InferArg, context: X['context'], info: GraphQLResolveInfo) => MaybePromise + }>> resolve?: (value: Infer, args: InferArg, context: X['context'], info: GraphQLResolveInfo) => MaybePromise> } } : {