From 3fa5392cb7a34f072330f07cf2eac6603dce5425 Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:46:41 +0900 Subject: [PATCH 1/2] feat: filter spaces by strategies and plugins --- src/graphql/helpers.ts | 12 +++++++++++- src/graphql/schema.gql | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/graphql/helpers.ts b/src/graphql/helpers.ts index 0baf9eb0..b40c390a 100644 --- a/src/graphql/helpers.ts +++ b/src/graphql/helpers.ts @@ -156,7 +156,7 @@ export async function fetchSpaces(args) { const fields = { id: 'string' }; const whereQuery = buildWhereQuery(fields, 's', where); - const queryStr = whereQuery.query; + let queryStr = whereQuery.query; const params: any[] = whereQuery.params; let orderBy = args.orderBy || 'created_at'; @@ -165,6 +165,16 @@ export async function fetchSpaces(args) { orderDirection = orderDirection.toUpperCase(); if (!['ASC', 'DESC'].includes(orderDirection)) orderDirection = 'DESC'; + if (where.strategies_in) { + queryStr += " AND JSON_OVERLAPS(JSON_EXTRACT(settings, '$.strategies[*].name'), JSON_ARRAY(?))"; + params.push(where.strategies_in); + } + + if (where.plugins_in) { + queryStr += " AND JSON_OVERLAPS(JSON_KEYS(settings, '$.plugins') , JSON_ARRAY(?))"; + params.push(where.plugins_in); + } + const query = ` SELECT s.* FROM spaces s WHERE s.deleted = 0 ${queryStr} diff --git a/src/graphql/schema.gql b/src/graphql/schema.gql index 73ee28c1..577d2c26 100644 --- a/src/graphql/schema.gql +++ b/src/graphql/schema.gql @@ -117,6 +117,8 @@ type Query { input SpaceWhere { id: String id_in: [String] + strategies_in: [String] + plugins_in: [String] } input RankingWhere { From 85bb6b7371660c5f0c3dd69c454e4d2d626b3beb Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:12:03 +0900 Subject: [PATCH 2/2] feat: filter spaces by `network` --- src/graphql/helpers.ts | 5 +++++ src/graphql/schema.gql | 1 + 2 files changed, 6 insertions(+) diff --git a/src/graphql/helpers.ts b/src/graphql/helpers.ts index 1b8e9bae..7afdedcb 100644 --- a/src/graphql/helpers.ts +++ b/src/graphql/helpers.ts @@ -175,6 +175,11 @@ export async function fetchSpaces(args) { params.push(where.plugins_in); } + if (where.network) { + queryStr += " AND JSON_EXTRACT(settings, '$.network') = ?"; + params.push(where.network); + } + const query = ` SELECT s.* FROM spaces s WHERE s.deleted = 0 ${queryStr} diff --git a/src/graphql/schema.gql b/src/graphql/schema.gql index 577d2c26..f4c1afb4 100644 --- a/src/graphql/schema.gql +++ b/src/graphql/schema.gql @@ -119,6 +119,7 @@ input SpaceWhere { id_in: [String] strategies_in: [String] plugins_in: [String] + network: String } input RankingWhere {