Skip to content

Commit f89023b

Browse files
authored
fix datetime and shedule (#584)
1 parent 07a4c8c commit f89023b

12 files changed

Lines changed: 75 additions & 19 deletions

.changeset/bright-planes-unite.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@graphprotocol/hypergraph": patch
3+
"@graphprotocol/hypergraph-react": patch
4+
---
5+
6+
- Rename `time` field to `datetime` in GraphQL valuesList queries
7+
- Add `ScheduleString` type for querying schedule fields

packages/hypergraph-react/src/prepare-publish.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ query entityToPublish($entityId: UUID!, $spaceId: UUID!) {
2525
text
2626
boolean
2727
float
28-
time
28+
datetime
2929
point
30+
schedule
3031
}
3132
relationsList(filter: {spaceId: {is: $spaceId}}) {
3233
id
@@ -42,8 +43,9 @@ type EntityToPublishQueryResult = {
4243
text: string;
4344
boolean: boolean;
4445
float: number;
45-
time: string;
46+
datetime: string;
4647
point: string;
48+
schedule: string;
4749
}[];
4850
relationsList: {
4951
id: string;
@@ -155,7 +157,7 @@ export const preparePublish = async <S extends Schema.Schema.AnyNoContext>({
155157
} else if (propertyType.value === 'date') {
156158
const dateValue = entity[prop.name] as Date;
157159
const newValue = dateValue.toISOString().split('T')[0];
158-
hasChanged = existingValueEntry?.time !== newValue;
160+
hasChanged = existingValueEntry?.datetime !== newValue;
159161
typedValue = { property: propertyId.value, type: 'date', value: newValue };
160162
} else if (propertyType.value === 'point') {
161163
const [lon, lat] = entity[prop.name] as [number, number];

packages/hypergraph-react/test/prepare-publish.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ describe('preparePublish', () => {
282282
{ propertyId: 'ed49ed7b17b34df6b0b511f78d82e151', text: 'Same Name' },
283283
{ propertyId: 'a427183d35194c96b80a5a0c64daed41', float: 30 },
284284
{ propertyId: 'e425955442b146e484c3f8681987770f', boolean: true },
285-
{ propertyId: 'b5c0e2c79ac9415e8ffe34f8b530f126', time: '1993-01-01' },
285+
{ propertyId: 'b5c0e2c79ac9415e8ffe34f8b530f126', datetime: '1993-01-01' },
286286
{ propertyId: '45e707a5436442fbbb0b927a5a8bc061', point: '0,0' },
287287
],
288288
relationsList: [],
@@ -630,7 +630,7 @@ describe('preparePublish', () => {
630630
valuesList: [
631631
{ propertyId: '2a8b9c7d4e5f6a7b8c9d0e1f2a3b4c5d', text: 'Existing Entity' },
632632
{ propertyId: 'eaf9f4f856474228aff58725368fc87c', float: 75 },
633-
{ propertyId: '9b53690fea6d4bd8b4d39ea01e7f837f', time: '2023-01-01' },
633+
{ propertyId: '9b53690fea6d4bd8b4d39ea01e7f837f', datetime: '2023-01-01' },
634634
],
635635
relationsList: [],
636636
},

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ query ${queryName}(${variableDefinitions}) {
8989
text
9090
boolean
9191
float
92-
time
92+
datetime
9393
point
94+
schedule
9495
}
9596
${level1Relations}
9697
}
@@ -102,8 +103,9 @@ type ValuesList = {
102103
text: string;
103104
boolean: boolean;
104105
float: number;
105-
time: string;
106+
datetime: string;
106107
point: string;
108+
schedule: string;
107109
}[];
108110

109111
type RawEntity = Record<string, string | boolean | number | unknown[] | Date | string[]>;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ query entity($id: UUID!, $spaceId: UUID!) {
4242
text
4343
boolean
4444
float
45-
time
45+
datetime
4646
point
47+
schedule
4748
}${relationsSelectionBlock}
4849
}
4950
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ query searchEntities($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $firs
4444
text
4545
boolean
4646
float
47-
time
47+
datetime
4848
point
49+
schedule
4950
}
5051
${relationsSelection}
5152
}

packages/hypergraph/src/type/type.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ export const Date = (propertyId: string) => {
135135
return Schema.Date.pipe(Schema.annotations({ [PropertyIdSymbol]: propertyId, [PropertyTypeSymbol]: 'date' }));
136136
};
137137

138+
/**
139+
* Creates a ScheduleString schema with the specified GRC-20 property ID
140+
*/
141+
export const ScheduleString = (propertyId: string) => {
142+
return Schema.String.pipe(Schema.annotations({ [PropertyIdSymbol]: propertyId, [PropertyTypeSymbol]: 'schedule' }));
143+
};
144+
138145
export const Point = (propertyId: string) =>
139146
Schema.transform(Schema.String, Schema.Array(Schema.Number), {
140147
strict: true,

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ import * as Option from 'effect/Option';
33
import * as SchemaAST from 'effect/SchemaAST';
44

55
export const convertPropertyValue = (
6-
property: { propertyId: string; text: string; boolean: boolean; float: number; time: string; point: string },
6+
property: {
7+
propertyId: string;
8+
text: string;
9+
boolean: boolean;
10+
float: number;
11+
datetime: string;
12+
point: string;
13+
schedule: string;
14+
},
715
type: SchemaAST.AST,
816
) => {
917
const propertyType = SchemaAST.getAnnotation<string>(Constants.PropertyTypeSymbol)(type);
@@ -43,8 +51,17 @@ export const convertPropertyValue = (
4351
}
4452
if (propertyType.value === 'date') {
4553
// Handle case where date is stored as string in the API
46-
if (property.time != null) {
47-
return property.time;
54+
if (property.datetime != null) {
55+
return property.datetime;
56+
}
57+
if (property.text != null) {
58+
return property.text;
59+
}
60+
return undefined;
61+
}
62+
if (propertyType.value === 'schedule') {
63+
if (property.schedule != null) {
64+
return property.schedule;
4865
}
4966
if (property.text != null) {
5067
return property.text;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ type ValueList = {
1313
text: string;
1414
boolean: boolean;
1515
float: number;
16-
time: string;
16+
datetime: string;
1717
point: string;
18+
schedule: string;
1819
}[];
1920

2021
type RelationsListItem = {

packages/hypergraph/src/utils/relation-query-helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ const buildRelationsListFragment = (info: RelationTypeIdInfo, level: 1 | 2, spac
112112
text
113113
boolean
114114
float
115-
time
115+
datetime
116116
point
117+
schedule
117118
}
118119
}
119120
${toEntitySelectionHeader} {
@@ -124,8 +125,9 @@ const buildRelationsListFragment = (info: RelationTypeIdInfo, level: 1 | 2, spac
124125
text
125126
boolean
126127
float
127-
time
128+
datetime
128129
point
130+
schedule
129131
}
130132
${nestedPlaceholder}
131133
}

0 commit comments

Comments
 (0)