Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var debug = require('debug')('primus-graphql:fixtures:user-changes-iterator')
var iterall = require('iterall')
var db = require('./mem-db.js') // In memory database
var $$asyncIterator = iterall.$$asyncIterator
var i = 0
function createExposedPromise () {
var _resolve, _reject
var promise = new Promise(function (resolve, reject) {
_resolve = resolve
_reject = reject
})
promise.id = ++i
promise.resolve = function (data) {
_resolve(data)
promise.val = data
return promise
}
promise.reject = function (err) {
_reject(err)
},
return: function _return() {
return $return ? $return.call(iterator).then(mapResult, mapReject) : Promise.resolve({
value: undefined,
done: true
});
},
throw: function _throw(error) {
// $FlowFixMe(>=0.68.0)
if (typeof iterator.throw === 'function') {
return iterator.throw(error).then(mapResult, mapReject);
}
return Promise.reject(error).catch(abruptClose);
}
}, _iterall.$$asyncIterator, function () {
return this;
});
}
// Before loading anything graphql-related, polyfill Symbol.asyncIterator because it's needed by TypeScript to support
// async iterators, and the 'iterall' package imported by graphql-js will make its own symbol and reject others
// if this isn't defined when 'iterall' is loaded
Symbol.asyncIterator = Symbol.asyncIterator || Symbol.for("Symbol.asyncIterator");
if (require('iterall').$$asyncIterator !== Symbol.asyncIterator) {
throw new Error('iterall is using the wrong symbol for asyncIterator')
}
import {utc} from 'moment';
import * as bodyParser from 'body-parser';
import * as compression from 'compression';
import * as http from 'http';
import * as express from 'express';
import * as session from 'express-session';
import * as connectRedis from 'connect-redis';
import * as Sentry from '@sentry/node';
import {ApolloServer} from 'apollo-server-express';
import * as jsonwebtoken from 'jsonwebtoken';
import * as cors from 'cors';
import { execute, subscribe, GraphQLError } from 'graphql';
PubSubAsyncIterator.prototype.throw = function (error) {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this.emptyQueue;
return [4, this.allSubscribed];
case 1:
_a.apply(this, [_b.sent()]);
return [2, Promise.reject(error)];
}
});
});
};
PubSubAsyncIterator.prototype[iterall_1.$$asyncIterator] = function () {
return this;
};
PubSubAsyncIterator.prototype.pushValue = function (message) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.allSubscribed];
case 1:
_a.sent();
if (this.pullQueue.length !== 0) {
this.pullQueue.shift()({ value: message, done: false });
}
else {
this.pushQueue.push(message);
}
return [2];
}) : Promise.reject(error);
isComplete = true;
return result;
},
return: function _return() {
isComplete = true;
return Promise.resolve({
value: undefined,
done: true
});
},
throw: function _throw() {
isComplete = true;
return Promise.reject(error);
}
}, _iterall.$$asyncIterator, function () {
return this;
});
}
PubSubAsyncIterator.prototype.throw = function (error) {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this.emptyQueue;
return [4 /*yield*/, this.allSubscribed];
case 1:
_a.apply(this, [_b.sent()]);
return [2 /*return*/, Promise.reject(error)];
}
});
});
};
PubSubAsyncIterator.prototype[iterall.$$asyncIterator] = function () {
return this;
};
PubSubAsyncIterator.prototype.pushValue = function (message) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.allSubscribed];
case 1:
_a.sent();
if (this.pullQueue.length !== 0) {
this.pullQueue.shift()({ value: message, done: false });
}
else {
this.pushQueue.push(message);
}
return [2 /*return*/];