diff --git a/packages/codegen/src/schema.ts b/packages/codegen/src/schema.ts index 88a6f146..62f3178d 100644 --- a/packages/codegen/src/schema.ts +++ b/packages/codegen/src/schema.ts @@ -193,7 +193,7 @@ export class Schema { const queryObject: { [key: string]: any; } = {}; queryObject[queryName] = { // Get type composer object for return type from the schema composer. - type: this._composer.getAnyTC(subgraphType).NonNull, + type: this._composer.getAnyTC(subgraphType), args: { id: 'ID!', block: BlockHeight diff --git a/packages/util/src/database.ts b/packages/util/src/database.ts index 56cf51fa..c9596f36 100644 --- a/packages/util/src/database.ts +++ b/packages/util/src/database.ts @@ -515,7 +515,15 @@ export class Database { `; // Fetching blockHash for previous entity in frothy region. - const [{ block_hash: blockHash, block_number: blockNumber, id }] = await queryRunner.query(heirerchicalQuery, [data.blockHash, data.id, MAX_REORG_DEPTH]); + const result = await queryRunner.query(heirerchicalQuery, [data.blockHash, data.id, MAX_REORG_DEPTH]); + + // Check if empty array returned + // (occurs when block at given hash doesn't exist in the db) + if (!result?.length) { + throw new Error('no block with that hash found'); + } + + const [{ block_hash: blockHash, block_number: blockNumber, id }] = result; return { blockHash, blockNumber, id }; } diff --git a/packages/util/src/graph/database.ts b/packages/util/src/graph/database.ts index 3a17ba08..36976381 100644 --- a/packages/util/src/graph/database.ts +++ b/packages/util/src/graph/database.ts @@ -222,18 +222,14 @@ export class GraphDatabase { block: CanonicalBlockHeight = {}, selections: ReadonlyArray = [] ): Promise { - let { hash: blockHash, number: blockNumber } = block; + const { hash: blockHash, number: blockNumber } = block; const repo = queryRunner.manager.getRepository(entityType); const whereOptions: any = { id }; - if (blockNumber) { - whereOptions.blockNumber = LessThanOrEqual(blockNumber); - } - if (blockHash) { whereOptions.blockHash = blockHash; - const block = await this._baseDatabase.getBlockProgress(queryRunner.manager.getRepository('block_progress'), blockHash); - blockNumber = block?.blockNumber; + } else if (blockNumber) { + whereOptions.blockNumber = LessThanOrEqual(blockNumber); } const findOptions = {