UNPKG

@agatee/graphql

Version:

Graphql module to use with Agatee

33 lines (32 loc) 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.combineResolvers = exports.combineSchema = exports.componentGql = exports.importSchema = void 0; const fs_1 = require("fs"); const importSchema = (path) => { return (0, fs_1.readFileSync)(path).toString(); }; exports.importSchema = importSchema; const componentGql = (name) => { const path = `app/components/${name}/${name}.graphql`; return (0, exports.importSchema)(path); }; exports.componentGql = componentGql; const combineSchema = (main, ...schemas) => { let result = schemas.join('\n'); result += `\n${main}`; return result; }; exports.combineSchema = combineSchema; const combineResolvers = (resolvers) => { const Query = Object.assign({}, ...resolvers.map(e => e.Query)); const Mutation = Object.assign({}, ...resolvers.map(e => e.Mutation)); let result = {}; if (Object.keys(Query).length) { result.Query = Query; } if (Object.keys(Mutation).length) { result.Mutation = Mutation; } return result; }; exports.combineResolvers = combineResolvers;