diff --git a/src/graphql/operations/index.ts b/src/graphql/operations/index.ts index 17105fc6..1d79c9cb 100644 --- a/src/graphql/operations/index.ts +++ b/src/graphql/operations/index.ts @@ -9,7 +9,6 @@ import proposal from './proposal'; import proposals from './proposals'; import ranking from './ranking'; import roles from './roles'; -import skin from './skin'; import skins from './skins'; import space from './space'; import spaces from './spaces'; @@ -36,7 +35,6 @@ export default { aliases, follows, subscriptions, - skin, skins, networks, options, diff --git a/src/graphql/operations/skin.ts b/src/graphql/operations/skin.ts deleted file mode 100644 index 0db16a07..00000000 --- a/src/graphql/operations/skin.ts +++ /dev/null @@ -1,11 +0,0 @@ -import skins from './skins'; - -export default async function (parent, args) { - const results = await skins(parent, { - first: 1, - skip: 0, - where: { id: args.id } - }); - - return results[0] || null; -} diff --git a/src/graphql/operations/skins.ts b/src/graphql/operations/skins.ts index e350d382..ce099ac7 100644 --- a/src/graphql/operations/skins.ts +++ b/src/graphql/operations/skins.ts @@ -1,43 +1,13 @@ -import { capture } from '@snapshot-labs/snapshot-sentry'; -import log from '../../helpers/log'; -import db from '../../helpers/mysql'; -import { buildWhereQuery, checkLimits } from '../helpers'; +import { spaces } from '../../helpers/spaces'; -const COLORS = ['bg', 'link', 'text', 'border', 'heading', 'primary']; - -function formatSkins(queryResults) { - return queryResults.map(skin => { - skin.colors = Object.fromEntries( - COLORS.map(color => [color, `#${skin[color]}`]) - ); - return skin; +export default function () { + const skins = {}; + Object.values(spaces).forEach((space: any) => { + if (space.skin) + skins[space.skin] = skins[space.skin] ? skins[space.skin] + 1 : 1; }); -} - -export default async function (parent, args) { - const { first, skip, where = {} } = args; - - checkLimits(args, 'skins'); - - const fields = { - id: 'string' - }; - const whereQuery = buildWhereQuery(fields, 's', where); - const queryStr = whereQuery.query; - const params: any[] = whereQuery.params; - - const query = ` - SELECT s.* FROM skins s - WHERE id IS NOT NULL ${queryStr} - ORDER BY id ASC LIMIT ?, ? - `; - params.push(skip, first); - - try { - return formatSkins(await db.queryAsync(query, params)); - } catch (e: any) { - log.error(`[graphql] skins, ${JSON.stringify(e)}`); - capture(e, { args }); - return Promise.reject(new Error('request failed')); - } + return Object.entries(skins).map(skin => ({ + id: skin[0], + spacesCount: skin[1] + })); } diff --git a/src/graphql/schema.gql b/src/graphql/schema.gql index 5eaeb70e..a8aa2cd2 100644 --- a/src/graphql/schema.gql +++ b/src/graphql/schema.gql @@ -81,14 +81,7 @@ type Query { statement(id: String!): Statement - - skin(id: String!): Skin - - skins( - first: Int! = 20 - skip: Int! = 0, - where: SkinWhere - ): [Skin] + skins: [Item] networks: [Item] @@ -386,10 +379,6 @@ input LeaderboardsWhere { vote_count_lte: [Int] } -input SkinWhere { - id: String -} - enum OrderDirection { asc desc @@ -662,17 +651,3 @@ type Option { name: String value: String } - -type SkinColors { - bg: String - link: String - text: String - border: String - heading: String - primary: String - } - -type Skin { - id: String! - colors: SkinColors -}