2021-07-02 10:56:32 +00:00
|
|
|
import assert from 'assert';
|
|
|
|
import BigInt from 'apollo-type-bigint';
|
2021-07-29 09:15:38 +00:00
|
|
|
import debug from 'debug';
|
2021-07-02 10:56:32 +00:00
|
|
|
|
|
|
|
import { Indexer } from './indexer';
|
2021-07-29 12:42:35 +00:00
|
|
|
import { Burn } from './entity/Burn';
|
|
|
|
import { OrderDirection } from './database';
|
2021-07-02 10:56:32 +00:00
|
|
|
|
2021-07-29 09:15:38 +00:00
|
|
|
const log = debug('vulcanize:resolver');
|
|
|
|
|
2021-07-29 12:42:35 +00:00
|
|
|
const DEFAULT_LIMIT = 100;
|
|
|
|
|
2021-07-29 09:15:38 +00:00
|
|
|
export interface BlockHeight {
|
|
|
|
number?: number;
|
|
|
|
hash?: string;
|
|
|
|
}
|
|
|
|
|
2021-07-02 10:56:32 +00:00
|
|
|
export const createResolvers = async (indexer: Indexer): Promise<any> => {
|
|
|
|
assert(indexer);
|
|
|
|
|
|
|
|
return {
|
|
|
|
BigInt: new BigInt('bigInt'),
|
|
|
|
|
2021-07-29 09:15:38 +00:00
|
|
|
Query: {
|
|
|
|
bundle: async (_: any, { id, block = {} }: { id: string, block: BlockHeight }) => {
|
|
|
|
log('bundle', id, block);
|
|
|
|
|
|
|
|
return indexer.getBundle(id, block);
|
|
|
|
},
|
|
|
|
|
2021-07-29 12:42:35 +00:00
|
|
|
bundles: async (_: any, { block = {}, first = DEFAULT_LIMIT }: { first: number, block: BlockHeight }) => {
|
|
|
|
log('bundles', block, first);
|
|
|
|
|
|
|
|
return indexer.getBundles(block, { limit: first });
|
|
|
|
},
|
|
|
|
|
|
|
|
burns: async (_: any, { first = DEFAULT_LIMIT, orderBy, orderDirection, where }: { first: number, orderBy: string, orderDirection: OrderDirection, where: Partial<Burn> }) => {
|
|
|
|
log('burns', first, orderBy, orderDirection, where);
|
|
|
|
|
|
|
|
return indexer.getBurns(where, { limit: first, orderBy, orderDirection });
|
|
|
|
},
|
|
|
|
|
|
|
|
factories: async (_: any, { block = {}, first = DEFAULT_LIMIT }: { first: number, block: BlockHeight }) => {
|
|
|
|
log('factories', block, first);
|
2021-07-29 09:15:38 +00:00
|
|
|
|
2021-07-29 12:42:35 +00:00
|
|
|
return indexer.getFactories(block, { limit: first });
|
2021-07-29 09:15:38 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-02 10:56:32 +00:00
|
|
|
};
|
|
|
|
};
|