Skip to content

Commit

Permalink
Merge pull request #97 from lorefnon/fix-subscription-types
Browse files Browse the repository at this point in the history
Fix subscription type
  • Loading branch information
mishushakov authored Feb 25, 2024
2 parents 9de43dd + d08bf1f commit bc1d582
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion examples/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }, {}> = {
Expand All @@ -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}` }
}
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ export type InferUnionNames<T> = T extends AnyUnion ? ObjectToUnion<T['_inner']>
export type InferResolvers<T extends AnyTypes, X extends InferResolverConfig> = {
[K in keyof T]: K extends 'Subscription' ? {
[G in keyof T[K]['_shape']]?: {
subscribe: (parent: {}, args: InferArg<T[K]['_shape'][G]>, context: X['context'], info: GraphQLResolveInfo) => MaybePromise<AsyncIterator<{ [G in keyof T[K]['_shape']]: Infer<T[K]['_shape'][G], { omitResolver: AnyOmitResolver }> }>>
subscribe: (parent: {}, args: InferArg<T[K]['_shape'][G]>, context: X['context'], info: GraphQLResolveInfo) => MaybePromise<AsyncIterator<{
[key in G]: Infer<T[K]['_shape'][G], { omitResolver: AnyOmitResolver }>
}>>
resolve?: (value: Infer<T[K]['_shape'][G]>, args: InferArg<T[K]['_shape'][G]>, context: X['context'], info: GraphQLResolveInfo) => MaybePromise<Infer<T[K]['_shape'][G], { omitResolver: AnyOmitResolver }>>
}
} : {
Expand Down

0 comments on commit bc1d582

Please sign in to comment.