1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-04 00:50:09 +02:00
copilot/packages/portal-api/lib/models/graphql.js

90 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-04-28 00:59:03 +03:00
'use strict';
2017-05-23 00:25:21 +03:00
const Fs = require('fs');
const Path = require('path');
2017-04-28 00:59:03 +03:00
const internals = {
2017-05-23 00:25:21 +03:00
schema: Fs.readFileSync(Path.join(__dirname, 'schema.gql')).toString()
2017-04-28 00:59:03 +03:00
};
exports.options = (data) => {
2017-05-24 05:32:22 +03:00
const queryWrap = function (name) {
return function (args, request) {
return data[name](args);
};
2017-04-28 00:59:03 +03:00
};
2017-05-24 05:32:22 +03:00
const queries = [
'portal',
'deploymentGroups',
'deploymentGroup',
'services',
'service',
'instances',
'instance',
'metricTypes',
'metricData',
'package',
'datacenters',
'instanceMetric'
];
2017-04-28 00:59:03 +03:00
2017-05-24 05:32:22 +03:00
const resolvers = {
createDeploymentGroup: (args, request) => {
return data.createDeploymentGroup(args.name);
},
2017-04-28 00:59:03 +03:00
2017-05-24 05:32:22 +03:00
updateDeploymentGroup: (args, request) => {
return data.updateDeploymentGroup(args.uuid, args.name);
},
2017-04-28 00:59:03 +03:00
2017-05-24 05:32:22 +03:00
provisionManifest: (args, request) => {
return data.provisionManifest(args.deploymentGroupUuid, args.type, args.format, args.raw);
},
2017-04-28 00:59:03 +03:00
2017-05-24 05:32:22 +03:00
scale: (args, request) => {
return data.scale(args.service, args.replicas);
},
2017-04-28 00:59:03 +03:00
2017-05-24 05:32:22 +03:00
stopServices: (args, request) => {
return data.stopServices(args.uuids);
},
startServices: (args, request) => {
return data.startServices(args.uuids);
},
restartServices: (args, request) => {
return data.restartServices(args.uuids);
},
2017-04-28 00:59:03 +03:00
2017-05-24 05:32:22 +03:00
deleteServices: (args, request) => {
return data.deleteServices(args.uuids);
},
2017-04-28 00:59:03 +03:00
2017-05-24 05:32:22 +03:00
stopInstances: (args, request) => {
return data.stopInstances(args.uuids);
},
startInstances: (args, request) => {
return data.startInstances(args.uuids);
},
restartInstances: (args, request) => {
return data.restartInstances(args.uuids);
}
2017-04-28 00:59:03 +03:00
};
2017-05-24 05:32:22 +03:00
queries.forEach((query) => {
const functionName = 'get' + query[0].toUpperCase() + query.slice(1);
resolvers[query] = queryWrap(functionName);
});
2017-04-28 00:59:03 +03:00
return {
2017-05-23 03:13:15 +03:00
schema: internals.schema,
2017-05-24 05:32:22 +03:00
resolvers
2017-04-28 00:59:03 +03:00
};
};