Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-number-property-parsing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphprotocol/hypergraph": patch
---

fix number, date, point and boolean property parsing when API returns value only on the string field
8 changes: 7 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -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": []
}
Expand Down
3 changes: 2 additions & 1 deletion apps/events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 33 additions & 0 deletions apps/events/test-script.ts
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion packages/hypergraph/src/entity/find-many-public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export const parseResult = <S extends Schema.Schema.AnyNoContext, IncludeSpaceId
const value = queryEntity.valuesList.find((a) => a.propertyId === result.value);
if (value) {
const rawValue = Utils.convertPropertyValue(value, propType);
if (rawValue) {
if (rawValue !== undefined) {
rawEntity[String(prop.name)] = rawValue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hypergraph/src/entity/find-one-public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const parseResult = <S extends Schema.Schema.AnyNoContext, IncludeSpaceIds exten
const value = queryEntity.valuesList.find((a) => a.propertyId === result.value);
if (value) {
const rawValue = Utils.convertPropertyValue(value, propType);
if (rawValue) {
if (rawValue !== undefined) {
rawEntity[String(prop.name)] = rawValue;
}
}
Expand Down
36 changes: 32 additions & 4 deletions packages/hypergraph/src/utils/convert-property-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,44 @@ export const convertPropertyValue = (
return property.string;
}
if (propertyType.value === 'boolean') {
return Boolean(property.boolean);
// Handle case where boolean 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 property.string === '1';
}
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.string;
}
return undefined;
}
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 && 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 property.time;
}
if (property.string != null) {
return property.time;
}
return undefined;
}
}
};
2 changes: 1 addition & 1 deletion packages/hypergraph/src/utils/convert-relations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Loading