From 8c45c729ca7a0be9015d32301efeb47693025446 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Thu, 14 Jul 2022 22:00:18 -0700 Subject: [PATCH] Closes #331 - Updated GraphQL schema --- requests/Switcher API.postman_collection.json | 26 +++++++------ src/api-docs/swagger-info.js | 2 +- src/client/configuration-resolvers.js | 38 ++++++++++--------- src/client/configuration-type.js | 16 ++++++++ src/client/schema.js | 6 +++ src/services/config.js | 1 + src/services/group-config.js | 1 + tests/client-api.test.js | 21 ++++++++++ 8 files changed, 80 insertions(+), 31 deletions(-) diff --git a/requests/Switcher API.postman_collection.json b/requests/Switcher API.postman_collection.json index 8539ace..9765168 100644 --- a/requests/Switcher API.postman_collection.json +++ b/requests/Switcher API.postman_collection.json @@ -1,8 +1,9 @@ { "info": { - "_postman_id": "cdfeeb52-cd3e-45ec-8478-155390a22621", + "_postman_id": "0cc46f7a-eeac-44a1-909e-4240909b7614", "name": "Switcher API", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "9436108" }, "item": [ { @@ -4457,7 +4458,7 @@ "query": [ { "key": "", - "value": null, + "value": "", "disabled": true } ] @@ -4504,7 +4505,7 @@ "query": [ { "key": "", - "value": null, + "value": "", "disabled": true } ] @@ -4551,7 +4552,7 @@ "query": [ { "key": "", - "value": null, + "value": "", "disabled": true } ] @@ -4606,7 +4607,7 @@ ], "body": { "mode": "raw", - "raw": "{\n\t\"domain\": \"My Domain\",\n\t\"component\": \"CustomerAPI\",\n\t\"environment\": \"default\"\n}", + "raw": "{\n\t\"domain\": \"Test Domain\",\n\t\"component\": \"App\",\n\t\"environment\": \"default\"\n}", "options": { "raw": { "language": "json" @@ -4667,7 +4668,7 @@ ], "body": { "mode": "raw", - "raw": "{\n\t\"entry\": [\n\t\t{\n\t\t\t\"strategy\": \"VALUE_VALIDATION\",\n\t\t\t\"input\": \"Roger\"\n\t\t}]\n}", + "raw": "{\n\t\"entry\": [\n\t\t{\n\t\t\t\"strategy\": \"PAYLOAD_VALIDATION\",\n\t\t\t\"input\": \"{ \\\"status\\\": \\\"ready\\\" }\"\n\t\t}]\n}", "options": { "raw": { "language": "json" @@ -4675,7 +4676,7 @@ } }, "url": { - "raw": "{{url}}/criteria?showReason=true&showStrategy=true&bypassMetric=true&key=FEATURE01", + "raw": "{{url}}/criteria?showReason=true&showStrategy=true&key=TEST_SWITCH", "host": [ "{{url}}" ], @@ -4693,11 +4694,12 @@ }, { "key": "bypassMetric", - "value": "true" + "value": "true", + "disabled": true }, { "key": "key", - "value": "FEATURE01" + "value": "TEST_SWITCH" } ] } @@ -5063,7 +5065,7 @@ "body": { "mode": "graphql", "graphql": { - "query": "{\r\n configuration(domain: \"5e0ece606f4f994eac9007ae\") {\r\n # configuration(domain: \"5e0ece606f4f994eac9007ae\", group: \"Project 2\") {\r\n # configuration(domain: \"5e0ece606f4f994eac9007ae\", group: \"Release 1\") {\r\n # configuration(domain: \"5e0ece606f4f994eac9007ae\", key: \"FEATURE01\", environment: \"default\") {\r\n # configuration(domain: \"5e4f9d8966e06b59c8254500\", key: \"FEATURE01\", environment: \"default\") {\r\n domain {\r\n name\r\n activated\r\n }\r\n group {\r\n name\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n }\r\n config {\r\n key\r\n activated\r\n }\r\n }\r\n}", + "query": "{\r\n configuration(domain: \"5e4f9d8966e06b59c8254500\", key: \"TEST_SWITCH\") {\r\n # configuration(domain: \"5e4f9d8966e06b59c8254500\", configId: \"6270b2fe68bceea783c450b4\") {\r\n # configuration(domain: \"5e4f9d8966e06b59c8254500\", groupId: \"6270b2f568bceea783c45081\") {\r\n # configuration(domain: \"5e4f9d8966e06b59c8254500\", group: \"Test group\") {\r\n # configuration(domain: \"5e0ece606f4f994eac9007ae\", key: \"FEATURE01\", environment: \"default\") {\r\n domain {\r\n name\r\n activated\r\n }\r\n group {\r\n _id\r\n name\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n }\r\n config {\r\n _id\r\n key\r\n activated\r\n }\r\n }\r\n}", "variables": "" } }, @@ -5128,7 +5130,7 @@ "response": [] }, { - "name": "Client - Configuration (Salck-GraphQL) - Configs", + "name": "Client - Configuration (Slack-GraphQL) - Configs", "request": { "method": "POST", "header": [], diff --git a/src/api-docs/swagger-info.js b/src/api-docs/swagger-info.js index 114ce3a..e302ce0 100644 --- a/src/api-docs/swagger-info.js +++ b/src/api-docs/swagger-info.js @@ -1,6 +1,6 @@ export default { title: 'Switcher API', - version: 'v1.2.4', + version: 'v1.2.5', description: 'Switcher API is a Feature Flag API focused on toggling features over different environments and applications.', contact: { name: 'Roger Floriano (petruki)', diff --git a/src/client/configuration-resolvers.js b/src/client/configuration-resolvers.js index 519c21b..f8f4052 100644 --- a/src/client/configuration-resolvers.js +++ b/src/client/configuration-resolvers.js @@ -8,29 +8,31 @@ import { getSlack } from '../services/slack'; import { getDomainById } from '../services/domain'; import { getComponents } from '../services/component'; -async function resolveConfigByConfig(key, domainId) { - const config = await getConfigs({ key, domain: domainId }, true); +async function resolveConfigByConfig(domainId, key, configId) { + const config = await getConfigs({ + id: configId, + key, domain: domainId + }, true); + if (config.length > 0) { return { config }; - } else { - return undefined; } -} -async function resolveGroup(domainId, groupConfig = undefined) { - let query = { - domain: domainId - }; + return undefined; +} - if (groupConfig) - query.name = groupConfig; +async function resolveGroup(domainId, groupConfig, groupId) { + const group = await getGroupConfigs({ + id: groupId, + name: groupConfig, + domain: domainId + }, true); - const group = await getGroupConfigs(query, true); if (group.length > 0) { return { group }; - } else { - return undefined; } + + return undefined; } async function resolveSlackInstallation(args) { @@ -53,12 +55,12 @@ export async function resolveConfiguration(args, context) { if (context.domain || args.domain) { context.environment = args.environment; context.domain = context.domain || args.domain; - if (args.key) { - return resolveConfigByConfig(args.key, context.domain); + if (args.key || args.config_id) { + return resolveConfigByConfig(context.domain, args.key, args.config_id); } - if (args.group) { - return resolveGroup(context.domain, args.group); + if (args.group || args.group_id) { + return resolveGroup(context.domain, args.group, args.group_id); } return resolveGroup(context.domain); diff --git a/src/client/configuration-type.js b/src/client/configuration-type.js index 7c0d324..1c431ed 100644 --- a/src/client/configuration-type.js +++ b/src/client/configuration-type.js @@ -176,6 +176,22 @@ export const domainType = new GraphQLObjectType({ description: { type: GraphQLString }, + owner: { + type: GraphQLString + }, + transfer: { + type: GraphQLBoolean + }, + integrations: { + type: new GraphQLObjectType({ + name: 'Integrations', + fields: { + slack: { + type: GraphQLString + } + } + }) + }, activated: { type: GraphQLBoolean, resolve: (source, _args, { environment }) => { diff --git a/src/client/schema.js b/src/client/schema.js index 0fdc030..bef4100 100644 --- a/src/client/schema.js +++ b/src/client/schema.js @@ -65,9 +65,15 @@ const queryType = new GraphQLObjectType({ group: { type: GraphQLString }, + group_id: { + type: GraphQLString + }, key: { type: GraphQLString }, + config_id: { + type: GraphQLString + }, environment: { type: GraphQLString }, diff --git a/src/services/config.js b/src/services/config.js index 51a9fce..ce17676 100644 --- a/src/services/config.js +++ b/src/services/config.js @@ -34,6 +34,7 @@ export async function getConfig(where, lean = false) { export async function getConfigs(where, lean = false) { const query = Config.find(); + if (where.id) query.where('_id', where.id); if (where.key) query.where('key', where.key); if (where.domain) query.where('domain', where.domain); if (where.group) query.where('group', where.group); diff --git a/src/services/group-config.js b/src/services/group-config.js index 64b14b5..0e7768a 100644 --- a/src/services/group-config.js +++ b/src/services/group-config.js @@ -19,6 +19,7 @@ export async function getGroupConfigById(id, lean = false) { export async function getGroupConfigs(where, lean = false) { const query = GroupConfig.find(); + if (where.id) query.where('_id', where.id); if (where.domain) query.where('domain', where.domain); if (where.name) query.where('name', where.name); if (lean) query.lean(); diff --git a/tests/client-api.test.js b/tests/client-api.test.js index bd0b717..e5349c4 100644 --- a/tests/client-api.test.js +++ b/tests/client-api.test.js @@ -816,6 +816,16 @@ describe('Testing domain [Adm-GraphQL] ', () => { expect(JSON.parse(req.text)).toMatchObject(JSON.parse(graphqlUtils.expected108)); }); + test('CLIENT_SUITE - Should return domain Flat-structure - By Switcher Id', async () => { + const req = await request(app) + .post('/adm-graphql') + .set('Authorization', `Bearer ${adminMasterAccountToken}`) + .send(graphqlUtils.configurationQuery([['domain', domainId], ['config_id', configId]])); + + expect(req.statusCode).toBe(200); + expect(JSON.parse(req.text)).toMatchObject(JSON.parse(graphqlUtils.expected108)); + }); + test('CLIENT_SUITE - Should return domain Flat-structure - By Group', async () => { const req = await request(app) .post('/adm-graphql') @@ -827,6 +837,17 @@ describe('Testing domain [Adm-GraphQL] ', () => { expect(result.data.configuration.group[0].name).toEqual('Group Test'); }); + test('CLIENT_SUITE - Should return domain Flat-structure - By Group Id', async () => { + const req = await request(app) + .post('/adm-graphql') + .set('Authorization', `Bearer ${adminMasterAccountToken}`) + .send(graphqlUtils.configurationQuery([['domain', domainId], ['group_id', groupConfigId]])); + + const result = JSON.parse(req.text); + expect(req.statusCode).toBe(200); + expect(result.data.configuration.group[0].name).toEqual('Group Test'); + }); + test('CLIENT_SUITE - Should return domain Flat-structure for a team member', async () => { const req = await request(app) .post('/adm-graphql')