@yeskiy/federation-with-subscriptions
Version:
Apollo Federation with subscriptions support
49 lines (48 loc) • 2.56 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMicroservice = void 0;
const apollo_server_core_1 = require("apollo-server-core");
const express_1 = __importDefault(require("express"));
const http_1 = __importDefault(require("http"));
const _1 = require(".");
const createMicroservice = (params) => __awaiter(void 0, void 0, void 0, function* () {
const { host, path } = params, rest = __rest(params, ["host", "path"]);
const assumedHost = host || "0.0.0.0";
const assumedPath = path || "/graphql";
const app = (0, express_1.default)();
const httpServer = http_1.default.createServer(app);
const microservice = yield (0, _1.createExpressMicroservice)(Object.assign(Object.assign({}, rest), { host: assumedHost, plugins: [
(0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({ httpServer }),
(0, apollo_server_core_1.ApolloServerPluginLandingPageGraphQLPlayground)(),
] }));
yield microservice.start();
const { listen } = microservice.applyMiddleware({
app,
path: assumedPath,
});
return listen(params.port);
});
exports.createMicroservice = createMicroservice;