@gabliam/graphql-koa
Version:
Graphql plugin for gabliam
37 lines (36 loc) • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GraphqlPlugin = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@gabliam/core");
const graphql_core_1 = require("@gabliam/graphql-core");
const web_core_1 = require("@gabliam/web-core");
const apollo_server_koa_1 = require("apollo-server-koa");
const debug_1 = tslib_1.__importDefault(require("debug"));
const debug = (0, debug_1.default)('Gabliam:Plugin:GraphqlPluginKoa');
let GraphqlPlugin = class GraphqlPlugin extends graphql_core_1.GraphqlCorePlugin {
async setUpAppolloServer(container, graphqlPluginConfig, apolloServer) {
debug('register Middleware', graphqlPluginConfig);
const webConfiguration = container.get(web_core_1.WebConfiguration);
await apolloServer.start();
const instance = (app, _container) => {
apolloServer.applyMiddleware({
path: graphqlPluginConfig.endpointUrl,
// cast to any apolloserver use koa-bodyserver for koa definition ><
app: app,
});
};
webConfiguration.addwebConfig({
order: 50,
instance,
});
}
getApolloServer(config) {
return new apollo_server_koa_1.ApolloServer(config);
}
};
GraphqlPlugin = tslib_1.__decorate([
(0, core_1.Plugin)({ dependencies: [{ name: 'KoaPlugin', order: 'before' }] }),
(0, core_1.Scan)()
], GraphqlPlugin);
exports.GraphqlPlugin = GraphqlPlugin;