-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
79 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,43 @@ | ||
import { spaces } from '../../helpers/spaces'; | ||
import { capture } from '@snapshot-labs/snapshot-sentry'; | ||
import log from '../../helpers/log'; | ||
import db from '../../helpers/mysql'; | ||
import { buildWhereQuery, checkLimits } from '../helpers'; | ||
|
||
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; | ||
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; | ||
}); | ||
return Object.entries(skins).map(skin => ({ | ||
id: skin[0], | ||
spacesCount: skin[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')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters