Skip to content

Commit a273809

Browse files
committed
fix parsing bug
1 parent cb38fd6 commit a273809

8 files changed

Lines changed: 58 additions & 6 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphprotocol/hypergraph": patch
3+
---
4+
5+
fix number property parsing when API returns value as string

.claude/settings.local.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"permissions": {
3-
"allow": ["Bash(pnpm lint:fix:*)", "Bash(pnpm typecheck:*)", "Bash(pnpm check:*)"],
3+
"allow": [
4+
"Bash(pnpm lint:fix:*)",
5+
"Bash(pnpm typecheck:*)",
6+
"Bash(pnpm check:*)",
7+
"Bash(pnpm --filter events test:script:*)",
8+
"Bash(pnpm test:*)"
9+
],
410
"deny": [],
511
"ask": []
612
}

apps/events/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"dev": "vite --force",
88
"preview": "vite preview",
9-
"typesync": "hypergraph typesync"
9+
"typesync": "hypergraph typesync",
10+
"test:script": "tsx test-script.ts"
1011
},
1112
"dependencies": {
1213
"@graphprotocol/grc-20": "^0.27.0",

apps/events/test-script.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { SystemIds } from '@graphprotocol/grc-20';
2+
import { Config, Entity, Id, Type } from '@graphprotocol/hypergraph';
3+
4+
Config.setApiOrigin('https://testnet-api.geobrowser.io');
5+
6+
const BOUNTY_TYPE_ID = Id('327976dea5ad45769b83b7e7ec6337cf');
7+
const REWARD_PROPERTY_ID = Id('e8e7301136354e84b46b767e7cd530a8');
8+
9+
const Bounty = Entity.Schema(
10+
{
11+
name: Type.String,
12+
description: Type.String,
13+
reward: Type.Number,
14+
},
15+
{
16+
types: [BOUNTY_TYPE_ID],
17+
properties: {
18+
name: SystemIds.NAME_PROPERTY,
19+
description: SystemIds.DESCRIPTION_PROPERTY,
20+
reward: REWARD_PROPERTY_ID,
21+
},
22+
},
23+
);
24+
25+
async function main() {
26+
const bounty = await Entity.findOnePublic(Bounty, {
27+
id: '93c9d09e662840a891fefe4c505f9365',
28+
space: 'b0043a26cb81379c1217dfd2283b67b8',
29+
});
30+
console.log(bounty);
31+
}
32+
33+
main();

packages/hypergraph/src/entity/find-many-public.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export const parseResult = <S extends Schema.Schema.AnyNoContext, IncludeSpaceId
165165
const value = queryEntity.valuesList.find((a) => a.propertyId === result.value);
166166
if (value) {
167167
const rawValue = Utils.convertPropertyValue(value, propType);
168-
if (rawValue) {
168+
if (rawValue !== undefined) {
169169
rawEntity[String(prop.name)] = rawValue;
170170
}
171171
}

packages/hypergraph/src/entity/find-one-public.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const parseResult = <S extends Schema.Schema.AnyNoContext, IncludeSpaceIds exten
9797
const value = queryEntity.valuesList.find((a) => a.propertyId === result.value);
9898
if (value) {
9999
const rawValue = Utils.convertPropertyValue(value, propType);
100-
if (rawValue) {
100+
if (rawValue !== undefined) {
101101
rawEntity[String(prop.name)] = rawValue;
102102
}
103103
}

packages/hypergraph/src/utils/convert-property-value.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ export const convertPropertyValue = (
1818
return property.point;
1919
}
2020
if (propertyType.value === 'number') {
21-
return Number(property.number);
21+
// Handle case where number is stored as string in the API
22+
if (property.number != null) {
23+
return Number(property.number);
24+
}
25+
if (property.string != null) {
26+
return Number(property.string);
27+
}
28+
return undefined;
2229
}
2330
if (propertyType.value === 'date') {
2431
return property.time;

packages/hypergraph/src/utils/convert-relations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export const convertRelations = <_S extends Schema.Schema.AnyNoContext>(
150150
continue;
151151
}
152152
const rawValue = convertPropertyValue(value, propType);
153-
if (rawValue) {
153+
if (rawValue !== undefined) {
154154
nestedRawEntity[String(nestedProp.name)] = rawValue;
155155
}
156156
}

0 commit comments

Comments
 (0)