diff --git a/src/graphql/operations/index.ts b/src/graphql/operations/index.ts index d9e7e250..1d79c9cb 100644 --- a/src/graphql/operations/index.ts +++ b/src/graphql/operations/index.ts @@ -3,6 +3,7 @@ import follows from './follows'; import leaderboards from './leaderboards'; import messages from './messages'; import networks from './networks'; +import options from './options'; import plugins from './plugins'; import proposal from './proposal'; import proposals from './proposals'; @@ -36,6 +37,7 @@ export default { subscriptions, skins, networks, + options, validations, plugins, strategies, diff --git a/src/graphql/operations/options.ts b/src/graphql/operations/options.ts new file mode 100644 index 00000000..7bc787c9 --- /dev/null +++ b/src/graphql/operations/options.ts @@ -0,0 +1,32 @@ +import { capture } from '@snapshot-labs/snapshot-sentry'; +import snapshot from '@snapshot-labs/snapshot.js'; +import log from '../../helpers/log'; +import db from '../../helpers/mysql'; + +const RUN_INTERVAL = 120e3; + +let options = []; + +export default async function () { + return options; +} + +async function loadOptions() { + options = await db.queryAsync('SELECT s.* FROM options s'); +} + +async function run() { + try { + log.info('[options] Start options refresh'); + await loadOptions(); + log.info(`[options] ${options.length} options reloaded`); + log.info('[options] End options refresh'); + } catch (e: any) { + capture(e); + log.error(`[options] failed to refresh options, ${JSON.stringify(e)}`); + } + await snapshot.utils.sleep(RUN_INTERVAL); + run(); +} + +run(); diff --git a/src/graphql/schema.gql b/src/graphql/schema.gql index 83b79c65..060a2b68 100644 --- a/src/graphql/schema.gql +++ b/src/graphql/schema.gql @@ -110,6 +110,8 @@ type Query { orderBy: String orderDirection: OrderDirection ): [Leaderboard] + + options: [Option] } input SpaceWhere { @@ -640,3 +642,8 @@ type Leaderboard { votesCount: Int lastVote: Int } + +type Option { + name: String + value: String +} diff --git a/src/helpers/schema.sql b/src/helpers/schema.sql index 78a2eec2..4d4a052b 100644 --- a/src/helpers/schema.sql +++ b/src/helpers/schema.sql @@ -183,3 +183,9 @@ CREATE TABLE leaderboard ( INDEX proposal_count (proposal_count), INDEX last_vote (last_vote) ); + +CREATE TABLE options ( + name VARCHAR(100) NOT NULL, + value VARCHAR(100) NOT NULL, + PRIMARY KEY (name) +);