joyent-portal/spikes/graphql/graphql-server/src/resolvers.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-05-03 17:56:02 +03:00
import { find, filter } from 'lodash';
import data from './mock-data';
const portal = { username: 'juditgreskovits', host: 'dockerhost'};
2017-05-03 19:36:38 +03:00
const deploymentGroups = data.projects.data;
2017-05-03 17:56:02 +03:00
const services = data.services.data;
const instances = data.instances.data;
const metricTypes = data.metrics.data.types;
const datacenters = data.datacenters.data;
const resolveFunctions = {
Query: {
portal() {
return portal;
},
2017-05-03 19:36:38 +03:00
deploymentGroups() {
return deploymentGroups;
2017-05-03 17:56:02 +03:00
},
2017-05-03 19:36:38 +03:00
deploymentGroup(_, { uuid }) {
return find(deploymentGroups, { uuid: uuid });
2017-05-03 17:56:02 +03:00
},
services() {
return services;
},
service(_, { uuid }) {
return find(services, { uuid: uuid });
},
instances() {
return instances;
},
metricTypes() {
return metricTypes;
},
datacenters() {
return datacenters;
},
},
2017-05-03 19:36:38 +03:00
DeploymentGroup: {
services(deploymentGroup) {
return filter(services, { project: deploymentGroup.uuid })
2017-05-03 17:56:02 +03:00
}
},
Service: {
instances(service) {
return filter(instances, { service: service.uuid })
},
metrics(service) {
return service.metrics ?
service.metrics.map((metric) =>
find(metricTypes, { uuid: metric.type })) : []
}
},
};
export default resolveFunctions;