import graphql from '../src/graphql'; import bindTranslations from './bindTranslations'; let cache = null; import { getRandom } from "./eventHelper"; export default async function () { try { sails.log.verbose('>>> graphql hook starting'); sails.on('clear_cache', async function (){ cache = null; }); sails.on('lifted', async function (){ try { const graphServer = await graphql.init(); // inject middleware into express app sails.hooks.http.app.use(graphServer.getMiddleware()); let layer = sails.hooks.http.app._router.stack.slice(-1)[0] sails.hooks.http.app._router.stack.splice(1, 0, layer) graphServer.installSubscriptionHandlers(sails.hooks.http.server); sails.emit('graphql-middleware:loaded'); } catch (error) { sails.emit('graphql-middleware:error'); sails.log.error(error); } }) if (await Settings.get("JWT_SECRET") === undefined) { //@ts-ignore const random = getRandom(); await Settings.set("JWT_SECRET", random) } bindTranslations() } catch (e) { sails.log.error('graphql > afterHook > error1', e); } }