From 4de2d60cec8e79741c3b41b770c836a22a5a561f Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Fri, 30 Oct 2020 12:06:52 -0600 Subject: [PATCH] [CORL-1485] Revert #3241 (#3267) * fix: revert custom async iterator to resolve memory * chore: bump 6.4.1 --- package-lock.json | 2 +- package.json | 2 +- .../graph/resolvers/Subscription/helpers.ts | 47 ++----------------- 3 files changed, 6 insertions(+), 45 deletions(-) diff --git a/package-lock.json b/package-lock.json index f1f499454c..e9de9e8428 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@coralproject/talk", - "version": "6.4.0", + "version": "6.4.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2bdc11943b..0c4062b989 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@coralproject/talk", - "version": "6.4.0", + "version": "6.4.1", "author": "The Coral Project", "homepage": "https://coralproject.net/", "sideEffects": [ diff --git a/src/core/server/graph/resolvers/Subscription/helpers.ts b/src/core/server/graph/resolvers/Subscription/helpers.ts index c105399af2..d177f31ba1 100644 --- a/src/core/server/graph/resolvers/Subscription/helpers.ts +++ b/src/core/server/graph/resolvers/Subscription/helpers.ts @@ -1,15 +1,9 @@ import { GraphQLResolveInfo } from "graphql"; +import { withFilter } from "graphql-subscriptions"; import GraphContext from "../../context"; import { SUBSCRIPTION_CHANNELS, SubscriptionPayload } from "./types"; -type ResolverFn = ( - parent: TParent, - args: TArgs, - context: TContext, - info: GraphQLResolveInfo -) => AsyncIterable; - type FilterFn = ( parent: TParent, args: TArgs, @@ -29,51 +23,18 @@ interface SubscriptionResolver { resolve: Resolver; } -/** - * withFilter applies a filter to a async iterator. - * - * This duplicates the functionality of the withFilter function provided by the - * `graphql-subscriptions` package without the memory leak as it uses native - * async iterators instead. - * - * Solution provided by @brettjashford. - * - * https://github.com/apollographql/graphql-subscriptions/pull/209#issuecomment-713906710 - * - * @param asyncIteratorFn the async iterator to use that's provided by the transport - * @param filterFn the filter to apply for each iteration to check to see if we should sent it - */ -function withFilter( - asyncIteratorFn: ResolverFn, - filterFn: FilterFn -) { - return async function* ( - source: TParent, - args: TArgs, - ctx: GraphContext, - info: GraphQLResolveInfo - ) { - const asyncIterator = asyncIteratorFn(source, args, ctx, info); - for await (const payload of asyncIterator) { - if (await filterFn(payload, args, ctx, info)) { - yield payload; - } - } - }; -} - function createTenantAsyncIterator( channel: SUBSCRIPTION_CHANNELS -): Resolver> { +): Resolver> { return (source, args, ctx) => // This is already technically returning an AsyncIterable, the Typescript // types are in fact wrong: // // https://github.com/davidyaha/graphql-redis-subscriptions/pull/255 // - (ctx.pubsub.asyncIterator( + ctx.pubsub.asyncIterator( createSubscriptionChannelName(ctx.tenant.id, channel) - ) as unknown) as AsyncIterable; + ); } export function createSubscriptionChannelName(