From cef46a8dbcec03916ae793169d336ff65ba17510 Mon Sep 17 00:00:00 2001 From: "Jorge S. Cuesta" Date: Thu, 30 Jan 2025 16:39:01 -0400 Subject: [PATCH] Fix ID validation in set method of model.ts. Ensure that IDs match correctly even when data types like BigInt, Int, or Float are used in GraphQL schemas. This prevents mismatches and ensures error handling for invalid ID comparisons. --- .../node-core/src/indexer/storeModelProvider/model/model.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/node-core/src/indexer/storeModelProvider/model/model.ts b/packages/node-core/src/indexer/storeModelProvider/model/model.ts index baa6820488..f4fdc89ba0 100644 --- a/packages/node-core/src/indexer/storeModelProvider/model/model.ts +++ b/packages/node-core/src/indexer/storeModelProvider/model/model.ts @@ -60,7 +60,11 @@ export class PlainModel implements IModel } async set(id: string, data: T, blockHeight: number, tx?: Transaction): Promise { - if (id !== data.id) { + // NOTE: this is to fix the error when use @dbType('BigInt') or maybe Int, Float as parameters on the graphql schema + const dataId = data.id as unknown as string | bigint | number; + if (typeof dataId !== 'string' && typeof dataId.toString === 'function' && dataId.toString() !== id) { + throw new Error(`Id doesnt match with data ${typeof id} !== ${typeof data.id}`); + } else if (typeof dataId === 'string' && dataId !== id) { throw new Error(`Id doesnt match with data`); }