From 2e3a436594691392f43f708b7e0acd2f874f44e9 Mon Sep 17 00:00:00 2001 From: geek Date: Tue, 23 May 2017 21:32:22 -0500 Subject: [PATCH] Update graphi and map resolvers --- portal-api/lib/models/graphql.js | 88 ++++++++++++++++++++++++-------- portal-api/package.json | 2 +- 2 files changed, 68 insertions(+), 22 deletions(-) diff --git a/portal-api/lib/models/graphql.js b/portal-api/lib/models/graphql.js index e62d98d4..626e716a 100644 --- a/portal-api/lib/models/graphql.js +++ b/portal-api/lib/models/graphql.js @@ -10,34 +10,80 @@ const internals = { exports.options = (data) => { - const getPortal = function (args, request) { - + const queryWrap = function (name) { + return function (args, request) { + return data[name](args); + }; }; - const getDeploymentGroups = function (args, request) { + const queries = [ + 'portal', + 'deploymentGroups', + 'deploymentGroup', + 'services', + 'service', + 'instances', + 'instance', + 'metricTypes', + 'metricData', + 'package', + 'datacenters', + 'instanceMetric' + ]; + const resolvers = { + createDeploymentGroup: (args, request) => { + return data.createDeploymentGroup(args.name); + }, + + updateDeploymentGroup: (args, request) => { + return data.updateDeploymentGroup(args.uuid, args.name); + }, + + provisionManifest: (args, request) => { + return data.provisionManifest(args.deploymentGroupUuid, args.type, args.format, args.raw); + }, + + scale: (args, request) => { + return data.scale(args.service, args.replicas); + }, + + stopServices: (args, request) => { + return data.stopServices(args.uuids); + }, + + startServices: (args, request) => { + return data.startServices(args.uuids); + }, + + restartServices: (args, request) => { + return data.restartServices(args.uuids); + }, + + deleteServices: (args, request) => { + return data.deleteServices(args.uuids); + }, + + stopInstances: (args, request) => { + return data.stopInstances(args.uuids); + }, + + startInstances: (args, request) => { + return data.startInstances(args.uuids); + }, + + restartInstances: (args, request) => { + return data.restartInstances(args.uuids); + } }; - const getDeploymentGroup = function (args, request) { - - }; - - const getServiceScales = function (args, request) { - - }; - - const getServiceScale = function (args, request) { - - }; + queries.forEach((query) => { + const functionName = 'get' + query[0].toUpperCase() + query.slice(1); + resolvers[query] = queryWrap(functionName); + }); return { schema: internals.schema, - functions: { - portal: getPortal, - deploymentGroups: getDeploymentGroups, - deploymentGroup: getDeploymentGroup, - serviceScales: getServiceScales, - serviceScale: getServiceScale - } + resolvers }; }; diff --git a/portal-api/package.json b/portal-api/package.json index 05bb580e..7e840761 100644 --- a/portal-api/package.json +++ b/portal-api/package.json @@ -24,7 +24,7 @@ }, "dependencies": { "boom": "^4.3.1", - "graphi": "^1.0.0", + "graphi": "^2.0.0", "hoek": "^4.1.1", "joi": "^10.4.1", "portal-data": "^1.0.0"