diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0f34fdd..b36128f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,8 @@
[@cursorsdottsx](https://github.com/cursorsdottsx) in [#245](https://github.com/apollographql/graphql-subscriptions/pull/245)
- Support `readonly` arrays of event names.
[@rh389](https://github.com/rh389) in [#234](https://github.com/apollographql/graphql-subscriptions/pull/234)
+- Support returning a Promise of an `AsyncIterator` as the `withFilter` resolver function.
+ [@maclockard](https://github.com/maclockard) in [#220](https://github.com/apollographql/graphql-subscriptions/pull/220)
### 2.0.1 (not yet released)
diff --git a/README.md b/README.md
index 8b5a309..ca67ab9 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ You can use it with any GraphQL client and server (not only Apollo).
If you are developing a project that uses this module with TypeScript:
-* ensure that your `tsconfig.json` `lib` definition includes `"esnext.asynciterable"`
+* ensure that your `tsconfig.json` `lib` definition includes `"es2018.asynciterable"`
* `npm install @types/graphql` or `yarn add @types/graphql`
### Getting started with your first subscription
diff --git a/src/test/asyncIteratorSubscription.ts b/src/test/asyncIteratorSubscription.ts
index d0f669d..fcf8ac8 100644
--- a/src/test/asyncIteratorSubscription.ts
+++ b/src/test/asyncIteratorSubscription.ts
@@ -189,7 +189,7 @@ const testFiniteAsyncIterator: AsyncIterableIterator = (async function *
describe('withFilter', () => {
it('works properly with finite asyncIterators', async () => {
- const filteredAsyncIterator = withFilter(() => testFiniteAsyncIterator, isEven)();
+ const filteredAsyncIterator = await withFilter(() => testFiniteAsyncIterator, isEven)();
for (let i = 1; i <= 4; i++) {
const result = await filteredAsyncIterator.next();
@@ -228,7 +228,8 @@ describe('withFilter', () => {
},
};
- const filteredAsyncIterator = withFilter(() => asyncIterator, () => stopped)();
+ const filteredAsyncIterator =
+ await withFilter(() => asyncIterator, () => stopped)();
global.gc();
const heapUsed = process.memoryUsage().heapUsed;
diff --git a/src/test/tests.ts b/src/test/tests.ts
index a1e009a..a22852c 100644
--- a/src/test/tests.ts
+++ b/src/test/tests.ts
@@ -74,7 +74,7 @@ describe('AsyncIterator', () => {
it('register to multiple events', done => {
const eventName = 'test2';
const ps = new PubSub();
- const iterator = ps.asyncIterator(['test', 'test2'] as const);
+ const iterator = ps.asyncIterableIterator(['test', 'test2'] as const);
const spy = sinon.spy();
iterator.next().then(() => {
diff --git a/src/with-filter.ts b/src/with-filter.ts
index f5c93e5..584934b 100644
--- a/src/with-filter.ts
+++ b/src/with-filter.ts
@@ -1,6 +1,5 @@
-
export type FilterFn = (rootValue?: TSource, args?: TArgs, context?: TContext, info?: any) => boolean | Promise;
-export type ResolverFn = (rootValue?: TSource, args?: TArgs, context?: TContext, info?: any) => AsyncIterator;
+export type ResolverFn = (rootValue?: TSource, args?: TArgs, context?: TContext, info?: any) => AsyncIterator | Promise>;
interface IterallAsyncIterator extends AsyncIterableIterator {
[Symbol.asyncIterator](): IterallAsyncIterator;
@@ -15,8 +14,8 @@ export function withFilter(
asyncIteratorFn: ResolverFn,
filterFn: FilterFn
): ResolverFn {
- return (rootValue: TSource, args: TArgs, context: TContext, info: any): IterallAsyncIterator => {
- const asyncIterator = asyncIteratorFn(rootValue, args, context, info);
+ return async (rootValue: TSource, args: TArgs, context: TContext, info: any): Promise> => {
+ const asyncIterator = await asyncIteratorFn(rootValue, args, context, info);
const getNextPromise = () => {
return new Promise>((resolve, reject) => {