From 125ac9a16795270a83487d8067b583e9442c1d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Tue, 25 Oct 2016 20:34:56 +0100 Subject: [PATCH] allow circular dependencies in graphql --- cloudapi-graphql/src/schema/types/firewall-rule.js | 9 +++++---- cloudapi-graphql/src/schema/types/machine.js | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cloudapi-graphql/src/schema/types/firewall-rule.js b/cloudapi-graphql/src/schema/types/firewall-rule.js index 35810c7c..6981af29 100644 --- a/cloudapi-graphql/src/schema/types/firewall-rule.js +++ b/cloudapi-graphql/src/schema/types/firewall-rule.js @@ -1,4 +1,3 @@ -const MachineType = require('../types/machine'); const api = require('../../api'); const { @@ -36,7 +35,8 @@ const FirewallRuleSyntaxType = new GraphQLObjectType({ module.exports = new GraphQLObjectType({ name: 'FirewallRuleType', - fields: { + // function to allow circular dependencies + fields: () => ({ id: { type: GraphQLID, description: 'Unique identifier for this rule' @@ -79,7 +79,8 @@ module.exports = new GraphQLObjectType({ description: 'Human-readable description for the rule' }, machines: { - type: new GraphQLList(MachineType), + // circular dependency + type: new GraphQLList(require('./machine')), description: 'Lists all instances a firewall rule is applied to', resolve: (root) => { return api.firewallRules.listMachines({ @@ -87,5 +88,5 @@ module.exports = new GraphQLObjectType({ }); } } - } + }) }); diff --git a/cloudapi-graphql/src/schema/types/machine.js b/cloudapi-graphql/src/schema/types/machine.js index 6ea46cdc..e0049a96 100644 --- a/cloudapi-graphql/src/schema/types/machine.js +++ b/cloudapi-graphql/src/schema/types/machine.js @@ -1,4 +1,3 @@ -const FirewallRuleType = require('./firewall-rule'); const DynamicObjectType = require('./dynamic-object'); const SnapshotType = require('./snapshot'); const api = require('../../api'); @@ -16,7 +15,8 @@ const { module.exports = new GraphQLObjectType({ name: 'MachineType', description: 'An image contains the software packages that will be available on newly-provisioned instance. In the case of hardware virtual machines, the image also includes the operating system', - fields: { + // function to allow circular dependencies + fields: () => ({ id: { type: GraphQLID, description: 'Unique id for this instance' @@ -110,7 +110,8 @@ module.exports = new GraphQLObjectType({ } }, firewall_rules: { - type: new GraphQLList(FirewallRuleType), + // circular dependency + type: new GraphQLList(require('./firewall-rule')), description: 'List of FirewallRules affecting this machine', resolve: (root) => { return api.firewallRules.listByMachine(root.id); @@ -147,7 +148,7 @@ module.exports = new GraphQLObjectType({ }); } } - } + }) }); module.exports.locality = new GraphQLInputObjectType({