Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: filter spaces by strategies, plugins and network #704

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/graphql/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -165,6 +165,21 @@ 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(?))";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only returns spaces that return space that uses only one strategy, it should return any space that use the strategy being passed

For example if space A is using ticket and erc721 and space B is using just ticket strategy,
now if we request with strategies_in:["ticket"] it return only space B, it should return space A too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be the case already, that's the job of JSON_OVERLAPS. Do you have a specific example I can test ?

Running the query in the description is giving me spaces using multiple strategies

"strategies": [
          {
            "name": "whitelist"
          },
          {
            "name": "delegation"
          },
          {
            "name": "moloch-all"
          },
          {
            "name": "loot-character-guilds"
          },
          {
            "name": "rocketpool-node-operator"
          },
          {
            "name": "honeyswap"
          },
          {
            "name": "xdai-stake-holders"
          },
          {
            "name": "yearn-vault"
          }
        ],

params.push(where.strategies_in);
}

if (where.plugins_in) {
queryStr += " AND JSON_OVERLAPS(JSON_KEYS(settings, '$.plugins') , JSON_ARRAY(?))";
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}
Expand Down
3 changes: 3 additions & 0 deletions src/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ type Query {
input SpaceWhere {
id: String
id_in: [String]
strategies_in: [String]
plugins_in: [String]
network: String
}

input RankingWhere {
Expand Down