graphql-redis-subscriptions
Version:
A graphql-subscriptions PubSub Engine using redis
38 lines • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.withFilter = void 0;
const withFilter = (asyncIteratorFn, filterFn) => {
return (rootValue, args, context, info) => {
const asyncIterator = asyncIteratorFn();
const getNextPromise = () => {
return asyncIterator
.next()
.then(payload => Promise.all([
payload,
Promise.resolve(filterFn(payload.value, args, context, info)).catch(() => false),
]))
.then(([payload, filterResult]) => {
if (filterResult === true) {
return payload;
}
return getNextPromise();
});
};
return {
next() {
return getNextPromise();
},
return() {
return asyncIterator.return();
},
throw(error) {
return asyncIterator.throw(error);
},
[Symbol.asyncIterator]() {
return this;
},
};
};
};
exports.withFilter = withFilter;
//# sourceMappingURL=with-filter.js.map