2020-01-27 10:30:52 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merges
|
|
|
|
*/
|
|
|
|
const mergeSchemas = (root, ...subs) => {
|
|
|
|
subs.forEach(sub => {
|
|
|
|
if (_.isEmpty(sub)) return;
|
|
|
|
const { definition = '', query = {}, mutation = {}, resolvers = {} } = sub;
|
|
|
|
|
|
|
|
root.definition += '\n' + definition;
|
|
|
|
_.merge(root, {
|
|
|
|
query,
|
|
|
|
mutation,
|
|
|
|
resolvers,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-01-27 22:43:44 +01:00
|
|
|
const createDefaultSchema = () => ({
|
|
|
|
definition: '',
|
|
|
|
query: '',
|
|
|
|
mutation: '',
|
|
|
|
resolvers: {},
|
|
|
|
});
|
|
|
|
|
2020-01-27 10:30:52 +01:00
|
|
|
module.exports = {
|
|
|
|
mergeSchemas,
|
2020-01-27 22:43:44 +01:00
|
|
|
createDefaultSchema,
|
2020-01-27 10:30:52 +01:00
|
|
|
};
|