Skip to content

Instantly share code, notes, and snippets.

View casey-chow's full-sized avatar

Casey Chow casey-chow

View GitHub Profile
@casey-chow
casey-chow / wait-for-subscription-with-trigger.ts
Last active November 24, 2020 19:08 — forked from blocka/wait-for-subscription.ts
waitForSubscription helper function for testing graphql subscriptions
/**
* Waits for a subscription after a trigger function is called. The trigger function is delayed to
* properly time the subscription return event.
*/
const waitForSubscription = async <TResult = any>(
subscription: DocumentNode,
trigger: () => Promise<void>
): Promise<ExecutionResult<TResult>> => {
const iterator = await subscribe<TResult>(
schema,