From a2738098496b64e5be29b8b1307e89c74440e8d4 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Wed, 14 Jan 2026 15:25:01 +0100 Subject: [PATCH 1/8] fix parsing bug --- .changeset/fix-number-property-parsing.md | 5 +++ .claude/settings.local.json | 8 ++++- apps/events/package.json | 3 +- apps/events/test-script.ts | 33 +++++++++++++++++++ .../hypergraph/src/entity/find-many-public.ts | 2 +- .../hypergraph/src/entity/find-one-public.ts | 2 +- .../src/utils/convert-property-value.ts | 9 ++++- .../hypergraph/src/utils/convert-relations.ts | 2 +- 8 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 .changeset/fix-number-property-parsing.md create mode 100644 apps/events/test-script.ts diff --git a/.changeset/fix-number-property-parsing.md b/.changeset/fix-number-property-parsing.md new file mode 100644 index 00000000..70116265 --- /dev/null +++ b/.changeset/fix-number-property-parsing.md @@ -0,0 +1,5 @@ +--- +"@graphprotocol/hypergraph": patch +--- + +fix number property parsing when API returns value as string diff --git a/.claude/settings.local.json b/.claude/settings.local.json index f43a83b3..742604a0 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -1,6 +1,12 @@ { "permissions": { - "allow": ["Bash(pnpm lint:fix:*)", "Bash(pnpm typecheck:*)", "Bash(pnpm check:*)"], + "allow": [ + "Bash(pnpm lint:fix:*)", + "Bash(pnpm typecheck:*)", + "Bash(pnpm check:*)", + "Bash(pnpm --filter events test:script:*)", + "Bash(pnpm test:*)" + ], "deny": [], "ask": [] } diff --git a/apps/events/package.json b/apps/events/package.json index 3c6f7864..18fa6dba 100644 --- a/apps/events/package.json +++ b/apps/events/package.json @@ -6,7 +6,8 @@ "scripts": { "dev": "vite --force", "preview": "vite preview", - "typesync": "hypergraph typesync" + "typesync": "hypergraph typesync", + "test:script": "tsx test-script.ts" }, "dependencies": { "@graphprotocol/grc-20": "^0.27.0", diff --git a/apps/events/test-script.ts b/apps/events/test-script.ts new file mode 100644 index 00000000..e31b48ce --- /dev/null +++ b/apps/events/test-script.ts @@ -0,0 +1,33 @@ +import { SystemIds } from '@graphprotocol/grc-20'; +import { Config, Entity, Id, Type } from '@graphprotocol/hypergraph'; + +Config.setApiOrigin('https://testnet-api.geobrowser.io'); + +const BOUNTY_TYPE_ID = Id('327976dea5ad45769b83b7e7ec6337cf'); +const REWARD_PROPERTY_ID = Id('e8e7301136354e84b46b767e7cd530a8'); + +const Bounty = Entity.Schema( + { + name: Type.String, + description: Type.String, + reward: Type.Number, + }, + { + types: [BOUNTY_TYPE_ID], + properties: { + name: SystemIds.NAME_PROPERTY, + description: SystemIds.DESCRIPTION_PROPERTY, + reward: REWARD_PROPERTY_ID, + }, + }, +); + +async function main() { + const bounty = await Entity.findOnePublic(Bounty, { + id: '93c9d09e662840a891fefe4c505f9365', + space: 'b0043a26cb81379c1217dfd2283b67b8', + }); + console.log(bounty); +} + +main(); diff --git a/packages/hypergraph/src/entity/find-many-public.ts b/packages/hypergraph/src/entity/find-many-public.ts index 992ce4c8..ba29c2b5 100644 --- a/packages/hypergraph/src/entity/find-many-public.ts +++ b/packages/hypergraph/src/entity/find-many-public.ts @@ -165,7 +165,7 @@ export const parseResult = a.propertyId === result.value); if (value) { const rawValue = Utils.convertPropertyValue(value, propType); - if (rawValue) { + if (rawValue !== undefined) { rawEntity[String(prop.name)] = rawValue; } } diff --git a/packages/hypergraph/src/entity/find-one-public.ts b/packages/hypergraph/src/entity/find-one-public.ts index f52d0537..6736f159 100644 --- a/packages/hypergraph/src/entity/find-one-public.ts +++ b/packages/hypergraph/src/entity/find-one-public.ts @@ -97,7 +97,7 @@ const parseResult = a.propertyId === result.value); if (value) { const rawValue = Utils.convertPropertyValue(value, propType); - if (rawValue) { + if (rawValue !== undefined) { rawEntity[String(prop.name)] = rawValue; } } diff --git a/packages/hypergraph/src/utils/convert-property-value.ts b/packages/hypergraph/src/utils/convert-property-value.ts index 92874bea..e3bdfbd5 100644 --- a/packages/hypergraph/src/utils/convert-property-value.ts +++ b/packages/hypergraph/src/utils/convert-property-value.ts @@ -18,7 +18,14 @@ export const convertPropertyValue = ( return property.point; } if (propertyType.value === 'number') { - return Number(property.number); + // Handle case where number is stored as string in the API + if (property.number != null) { + return Number(property.number); + } + if (property.string != null) { + return Number(property.string); + } + return undefined; } if (propertyType.value === 'date') { return property.time; diff --git a/packages/hypergraph/src/utils/convert-relations.ts b/packages/hypergraph/src/utils/convert-relations.ts index 6a014006..16f6a9ec 100644 --- a/packages/hypergraph/src/utils/convert-relations.ts +++ b/packages/hypergraph/src/utils/convert-relations.ts @@ -150,7 +150,7 @@ export const convertRelations = <_S extends Schema.Schema.AnyNoContext>( continue; } const rawValue = convertPropertyValue(value, propType); - if (rawValue) { + if (rawValue !== undefined) { nestedRawEntity[String(nestedProp.name)] = rawValue; } } From 436fe4cbe1dcdf574be5169f6d7a6347fdcd3b15 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Thu, 15 Jan 2026 11:40:39 +0100 Subject: [PATCH 2/8] add more fallbacks --- .../src/utils/convert-property-value.ts | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/hypergraph/src/utils/convert-property-value.ts b/packages/hypergraph/src/utils/convert-property-value.ts index e3bdfbd5..162aa79e 100644 --- a/packages/hypergraph/src/utils/convert-property-value.ts +++ b/packages/hypergraph/src/utils/convert-property-value.ts @@ -12,23 +12,44 @@ export const convertPropertyValue = ( return property.string; } if (propertyType.value === 'boolean') { - return Boolean(property.boolean); + // Handle case where number is stored as string in the API + if (property.boolean != null) { + return Boolean(property.boolean); + } + if ((property.string != null && property.string === '1') || property.string === '0') { + return Boolean(property.string); + } + return undefined; } if (propertyType.value === 'point') { - return property.point; + // Handle case where point is stored as string in the API + if (property.point != null) { + return property.point; + } + if (property.string != null) { + return property.point; + } + return undefined; } if (propertyType.value === 'number') { // Handle case where number is stored as string in the API if (property.number != null) { return Number(property.number); } - if (property.string != null) { + if (property.string != null && property.string !== '' && !Number.isNaN(Number(property.string))) { return Number(property.string); } return undefined; } if (propertyType.value === 'date') { - return property.time; + // Handle case where date is stored as string in the API + if (property.time != null) { + return new Date(property.time); + } + if (property.string != null && property.string !== '') { + return new Date(property.string); + } + return undefined; } } }; From 1be5847dea702c83c249fa3ba2ba5ffab4de1c41 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Thu, 15 Jan 2026 11:49:55 +0100 Subject: [PATCH 3/8] update changeset --- .changeset/fix-number-property-parsing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fix-number-property-parsing.md b/.changeset/fix-number-property-parsing.md index 70116265..38ada01e 100644 --- a/.changeset/fix-number-property-parsing.md +++ b/.changeset/fix-number-property-parsing.md @@ -2,4 +2,4 @@ "@graphprotocol/hypergraph": patch --- -fix number property parsing when API returns value as string +fix number, date, point and boolean property parsing when API returns value only on the string field \ No newline at end of file From d25d0f02bbc4f34bfb3b8aa15a6bf754d04ab45c Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Thu, 15 Jan 2026 11:52:01 +0100 Subject: [PATCH 4/8] Update packages/hypergraph/src/utils/convert-property-value.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- packages/hypergraph/src/utils/convert-property-value.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hypergraph/src/utils/convert-property-value.ts b/packages/hypergraph/src/utils/convert-property-value.ts index 162aa79e..4c8130e9 100644 --- a/packages/hypergraph/src/utils/convert-property-value.ts +++ b/packages/hypergraph/src/utils/convert-property-value.ts @@ -12,7 +12,7 @@ export const convertPropertyValue = ( return property.string; } if (propertyType.value === 'boolean') { - // Handle case where number is stored as string in the API + // Handle case where boolean is stored as string in the API if (property.boolean != null) { return Boolean(property.boolean); } From 8ddc3d700064fdd7f97ea0a416e190d56f929e11 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Thu, 15 Jan 2026 11:52:15 +0100 Subject: [PATCH 5/8] Update packages/hypergraph/src/utils/convert-property-value.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- packages/hypergraph/src/utils/convert-property-value.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/hypergraph/src/utils/convert-property-value.ts b/packages/hypergraph/src/utils/convert-property-value.ts index 4c8130e9..b85ef452 100644 --- a/packages/hypergraph/src/utils/convert-property-value.ts +++ b/packages/hypergraph/src/utils/convert-property-value.ts @@ -16,8 +16,8 @@ export const convertPropertyValue = ( if (property.boolean != null) { return Boolean(property.boolean); } - if ((property.string != null && property.string === '1') || property.string === '0') { - return Boolean(property.string); + if (property.string != null && (property.string === '1' || property.string === '0')) { + return property.string === '1'; } return undefined; } From 76669d1ea30905062a25d95650cdbfc3cb4ab6a6 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Thu, 15 Jan 2026 11:52:28 +0100 Subject: [PATCH 6/8] Update packages/hypergraph/src/utils/convert-property-value.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- packages/hypergraph/src/utils/convert-property-value.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hypergraph/src/utils/convert-property-value.ts b/packages/hypergraph/src/utils/convert-property-value.ts index b85ef452..dcf9141d 100644 --- a/packages/hypergraph/src/utils/convert-property-value.ts +++ b/packages/hypergraph/src/utils/convert-property-value.ts @@ -27,7 +27,7 @@ export const convertPropertyValue = ( return property.point; } if (property.string != null) { - return property.point; + return property.string; } return undefined; } From bdf5ec9728ae62c11fe5d978ff7eb4868b7c2964 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Thu, 15 Jan 2026 11:53:03 +0100 Subject: [PATCH 7/8] Update packages/hypergraph/src/utils/convert-property-value.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../hypergraph/src/utils/convert-property-value.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/hypergraph/src/utils/convert-property-value.ts b/packages/hypergraph/src/utils/convert-property-value.ts index dcf9141d..95a3a171 100644 --- a/packages/hypergraph/src/utils/convert-property-value.ts +++ b/packages/hypergraph/src/utils/convert-property-value.ts @@ -44,10 +44,16 @@ export const convertPropertyValue = ( if (propertyType.value === 'date') { // Handle case where date is stored as string in the API if (property.time != null) { - return new Date(property.time); + const timeDate = new Date(property.time); + if (!Number.isNaN(timeDate.getTime())) { + return timeDate; + } } if (property.string != null && property.string !== '') { - return new Date(property.string); + const stringDate = new Date(property.string); + if (!Number.isNaN(stringDate.getTime())) { + return stringDate; + } } return undefined; } From 172fcaf51f1dc85aab6857d04d10ade1ec08bccd Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Thu, 15 Jan 2026 11:55:54 +0100 Subject: [PATCH 8/8] fix date parsing --- .../hypergraph/src/utils/convert-property-value.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/hypergraph/src/utils/convert-property-value.ts b/packages/hypergraph/src/utils/convert-property-value.ts index 95a3a171..96cc88c1 100644 --- a/packages/hypergraph/src/utils/convert-property-value.ts +++ b/packages/hypergraph/src/utils/convert-property-value.ts @@ -44,16 +44,10 @@ export const convertPropertyValue = ( if (propertyType.value === 'date') { // Handle case where date is stored as string in the API if (property.time != null) { - const timeDate = new Date(property.time); - if (!Number.isNaN(timeDate.getTime())) { - return timeDate; - } - } - if (property.string != null && property.string !== '') { - const stringDate = new Date(property.string); - if (!Number.isNaN(stringDate.getTime())) { - return stringDate; - } + return property.time; + } + if (property.string != null) { + return property.time; } return undefined; }