diff --git a/src/resolvers.ts b/src/resolvers.ts index 8314988..87c0499 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -17,6 +17,7 @@ import { getResultState, IndexerInterface, BlockHeight, + OrderDirection, jsonBigIntStringReplacer, EventWatcher, // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -100,6 +101,29 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher return indexer.getSubgraphEntity(User, id, block, info.fieldNodes[0].selectionSet.selections); }, + users: async ( + _: any, + { block = {}, first, skip }: { block: BlockHeight, first: number, skip: number }, + __: any, + info: GraphQLResolveInfo + ) => { + log('users', JSON.stringify(block, jsonBigIntStringReplacer), first, skip); + gqlTotalQueryCount.inc(1); + gqlQueryCount.labels('users').inc(1); + assert(info.fieldNodes[0].selectionSet); + + // Set cache-control hints + // setGQLCacheHints(info, block, gqlCacheConfig); + + return indexer.getSubgraphEntities( + User, + block, + {}, + { limit: first, skip }, + info.fieldNodes[0].selectionSet.selections + ); + }, + taskReceiptWrapper: async ( _: any, { id, block = {} }: { id: string, block: BlockHeight }, @@ -117,6 +141,29 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher return indexer.getSubgraphEntity(TaskReceiptWrapper, id, block, info.fieldNodes[0].selectionSet.selections); }, + taskReceiptWrappers: async ( + _: any, + { block = {}, where, first, skip, orderBy, orderDirection }: { block: BlockHeight, where: { [key: string]: any }, first: number, skip: number, orderBy: string, orderDirection: OrderDirection }, + __: any, + info: GraphQLResolveInfo + ) => { + log('taskReceiptWrappers', JSON.stringify(block, jsonBigIntStringReplacer), JSON.stringify(where, jsonBigIntStringReplacer), first, skip, orderBy, orderDirection); + gqlTotalQueryCount.inc(1); + gqlQueryCount.labels('taskReceiptWrappers').inc(1); + assert(info.fieldNodes[0].selectionSet); + + // Set cache-control hints + // setGQLCacheHints(info, block, gqlCacheConfig); + + return indexer.getSubgraphEntities( + TaskReceiptWrapper, + block, + where, + { limit: first, skip, orderBy, orderDirection }, + info.fieldNodes[0].selectionSet.selections + ); + }, + taskReceipt: async ( _: any, { id, block = {} }: { id: string, block: BlockHeight }, @@ -134,6 +181,29 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher return indexer.getSubgraphEntity(TaskReceipt, id, block, info.fieldNodes[0].selectionSet.selections); }, + taskReceipts: async ( + _: any, + { block = {}, first, skip }: { block: BlockHeight, first: number, skip: number }, + __: any, + info: GraphQLResolveInfo + ) => { + log('taskReceipts', JSON.stringify(block, jsonBigIntStringReplacer), first, skip); + gqlTotalQueryCount.inc(1); + gqlQueryCount.labels('taskReceipts').inc(1); + assert(info.fieldNodes[0].selectionSet); + + // Set cache-control hints + // setGQLCacheHints(info, block, gqlCacheConfig); + + return indexer.getSubgraphEntities( + TaskReceipt, + block, + {}, + { limit: first, skip }, + info.fieldNodes[0].selectionSet.selections + ); + }, + taskCycle: async ( _: any, { id, block = {} }: { id: string, block: BlockHeight }, @@ -151,6 +221,29 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher return indexer.getSubgraphEntity(TaskCycle, id, block, info.fieldNodes[0].selectionSet.selections); }, + taskCycles: async ( + _: any, + { block = {}, first, skip }: { block: BlockHeight, first: number, skip: number }, + __: any, + info: GraphQLResolveInfo + ) => { + log('taskCycles', JSON.stringify(block, jsonBigIntStringReplacer), first, skip); + gqlTotalQueryCount.inc(1); + gqlQueryCount.labels('taskCycles').inc(1); + assert(info.fieldNodes[0].selectionSet); + + // Set cache-control hints + // setGQLCacheHints(info, block, gqlCacheConfig); + + return indexer.getSubgraphEntities( + TaskCycle, + block, + {}, + { limit: first, skip }, + info.fieldNodes[0].selectionSet.selections + ); + }, + task: async ( _: any, { id, block = {} }: { id: string, block: BlockHeight }, @@ -168,6 +261,29 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher return indexer.getSubgraphEntity(Task, id, block, info.fieldNodes[0].selectionSet.selections); }, + tasks: async ( + _: any, + { block = {}, first, skip }: { block: BlockHeight, first: number, skip: number }, + __: any, + info: GraphQLResolveInfo + ) => { + log('tasks', JSON.stringify(block, jsonBigIntStringReplacer), first, skip); + gqlTotalQueryCount.inc(1); + gqlQueryCount.labels('tasks').inc(1); + assert(info.fieldNodes[0].selectionSet); + + // Set cache-control hints + // setGQLCacheHints(info, block, gqlCacheConfig); + + return indexer.getSubgraphEntities( + Task, + block, + {}, + { limit: first, skip }, + info.fieldNodes[0].selectionSet.selections + ); + }, + provider: async ( _: any, { id, block = {} }: { id: string, block: BlockHeight }, @@ -185,6 +301,29 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher return indexer.getSubgraphEntity(Provider, id, block, info.fieldNodes[0].selectionSet.selections); }, + providers: async ( + _: any, + { block = {}, first, skip }: { block: BlockHeight, first: number, skip: number }, + __: any, + info: GraphQLResolveInfo + ) => { + log('providers', JSON.stringify(block, jsonBigIntStringReplacer), first, skip); + gqlTotalQueryCount.inc(1); + gqlQueryCount.labels('providers').inc(1); + assert(info.fieldNodes[0].selectionSet); + + // Set cache-control hints + // setGQLCacheHints(info, block, gqlCacheConfig); + + return indexer.getSubgraphEntities( + Provider, + block, + {}, + { limit: first, skip }, + info.fieldNodes[0].selectionSet.selections + ); + }, + condition: async ( _: any, { id, block = {} }: { id: string, block: BlockHeight }, @@ -202,6 +341,29 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher return indexer.getSubgraphEntity(Condition, id, block, info.fieldNodes[0].selectionSet.selections); }, + conditions: async ( + _: any, + { block = {}, first, skip }: { block: BlockHeight, first: number, skip: number }, + __: any, + info: GraphQLResolveInfo + ) => { + log('conditions', JSON.stringify(block, jsonBigIntStringReplacer), first, skip); + gqlTotalQueryCount.inc(1); + gqlQueryCount.labels('conditions').inc(1); + assert(info.fieldNodes[0].selectionSet); + + // Set cache-control hints + // setGQLCacheHints(info, block, gqlCacheConfig); + + return indexer.getSubgraphEntities( + Condition, + block, + {}, + { limit: first, skip }, + info.fieldNodes[0].selectionSet.selections + ); + }, + action: async ( _: any, { id, block = {} }: { id: string, block: BlockHeight }, @@ -219,6 +381,29 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher return indexer.getSubgraphEntity(Action, id, block, info.fieldNodes[0].selectionSet.selections); }, + actions: async ( + _: any, + { block = {}, first, skip }: { block: BlockHeight, first: number, skip: number }, + __: any, + info: GraphQLResolveInfo + ) => { + log('actions', JSON.stringify(block, jsonBigIntStringReplacer), first, skip); + gqlTotalQueryCount.inc(1); + gqlQueryCount.labels('actions').inc(1); + assert(info.fieldNodes[0].selectionSet); + + // Set cache-control hints + // setGQLCacheHints(info, block, gqlCacheConfig); + + return indexer.getSubgraphEntities( + Action, + block, + {}, + { limit: first, skip }, + info.fieldNodes[0].selectionSet.selections + ); + }, + executor: async ( _: any, { id, block = {} }: { id: string, block: BlockHeight }, @@ -236,6 +421,29 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher return indexer.getSubgraphEntity(Executor, id, block, info.fieldNodes[0].selectionSet.selections); }, + executors: async ( + _: any, + { block = {}, first, skip }: { block: BlockHeight, first: number, skip: number }, + __: any, + info: GraphQLResolveInfo + ) => { + log('executors', JSON.stringify(block, jsonBigIntStringReplacer), first, skip); + gqlTotalQueryCount.inc(1); + gqlQueryCount.labels('executors').inc(1); + assert(info.fieldNodes[0].selectionSet); + + // Set cache-control hints + // setGQLCacheHints(info, block, gqlCacheConfig); + + return indexer.getSubgraphEntities( + Executor, + block, + {}, + { limit: first, skip }, + info.fieldNodes[0].selectionSet.selections + ); + }, + events: async (_: any, { blockHash, contractAddress, name }: { blockHash: string, contractAddress: string, name?: string }) => { log('events', blockHash, contractAddress, name); gqlTotalQueryCount.inc(1); diff --git a/src/schema.gql b/src/schema.gql index ec573c1..98debfa 100644 --- a/src/schema.gql +++ b/src/schema.gql @@ -242,18 +242,32 @@ type ResultState { data: String! } +enum OrderDirection { + asc + desc +} + type Query { events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!] eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!] user(id: ID!, block: Block_height): User! + users(block: Block_height, first: Int = 100, skip: Int = 0): [User!]! taskReceiptWrapper(id: ID!, block: Block_height): TaskReceiptWrapper! + taskReceiptWrappers(where: TaskReceiptWrapper_filter, block: Block_height, orderBy: TaskReceiptWrapper_orderBy, orderDirection: OrderDirection, first: Int = 100, skip: Int = 0): [TaskReceiptWrapper!]! taskReceipt(id: ID!, block: Block_height): TaskReceipt! + taskReceipts(block: Block_height, first: Int = 100, skip: Int = 0): [TaskReceipt!]! taskCycle(id: ID!, block: Block_height): TaskCycle! + taskCycles(block: Block_height, first: Int = 100, skip: Int = 0): [TaskCycle!]! task(id: ID!, block: Block_height): Task! + tasks(block: Block_height, first: Int = 100, skip: Int = 0): [Task!]! provider(id: ID!, block: Block_height): Provider! + providers(block: Block_height, first: Int = 100, skip: Int = 0): [Provider!]! condition(id: ID!, block: Block_height): Condition! + conditions(block: Block_height, first: Int = 100, skip: Int = 0): [Condition!]! action(id: ID!, block: Block_height): Action! + actions(block: Block_height, first: Int = 100, skip: Int = 0): [Action!]! executor(id: ID!, block: Block_height): Executor! + executors(block: Block_height, first: Int = 100, skip: Int = 0): [Executor!]! getSyncStatus: SyncStatus getStateByCID(cid: String!): ResultState getState(blockHash: String!, contractAddress: String!, kind: String): ResultState @@ -279,6 +293,15 @@ type TaskReceiptWrapper { selfProvided: Boolean! } +input TaskReceiptWrapper_filter { + user: String + status: TaskReceiptStatus +} + +enum TaskReceiptWrapper_orderBy { + id +} + type TaskReceipt { id: ID! userProxy: Bytes!