diff --git a/.changeset/bright-planes-unite.md b/.changeset/bright-planes-unite.md new file mode 100644 index 00000000..d359cc5d --- /dev/null +++ b/.changeset/bright-planes-unite.md @@ -0,0 +1,7 @@ +--- +"@graphprotocol/hypergraph": patch +"@graphprotocol/hypergraph-react": patch +--- + +- Rename `time` field to `datetime` in GraphQL valuesList queries +- Add `ScheduleString` type for querying schedule fields diff --git a/packages/hypergraph-react/src/prepare-publish.ts b/packages/hypergraph-react/src/prepare-publish.ts index 1e11e976..965f767d 100644 --- a/packages/hypergraph-react/src/prepare-publish.ts +++ b/packages/hypergraph-react/src/prepare-publish.ts @@ -25,8 +25,9 @@ query entityToPublish($entityId: UUID!, $spaceId: UUID!) { text boolean float - time + datetime point + schedule } relationsList(filter: {spaceId: {is: $spaceId}}) { id @@ -42,8 +43,9 @@ type EntityToPublishQueryResult = { text: string; boolean: boolean; float: number; - time: string; + datetime: string; point: string; + schedule: string; }[]; relationsList: { id: string; @@ -155,7 +157,7 @@ export const preparePublish = async ({ } else if (propertyType.value === 'date') { const dateValue = entity[prop.name] as Date; const newValue = dateValue.toISOString().split('T')[0]; - hasChanged = existingValueEntry?.time !== newValue; + hasChanged = existingValueEntry?.datetime !== newValue; typedValue = { property: propertyId.value, type: 'date', value: newValue }; } else if (propertyType.value === 'point') { const [lon, lat] = entity[prop.name] as [number, number]; diff --git a/packages/hypergraph-react/test/prepare-publish.test.ts b/packages/hypergraph-react/test/prepare-publish.test.ts index 0f2fc0ff..39e8a8bf 100644 --- a/packages/hypergraph-react/test/prepare-publish.test.ts +++ b/packages/hypergraph-react/test/prepare-publish.test.ts @@ -282,7 +282,7 @@ describe('preparePublish', () => { { propertyId: 'ed49ed7b17b34df6b0b511f78d82e151', text: 'Same Name' }, { propertyId: 'a427183d35194c96b80a5a0c64daed41', float: 30 }, { propertyId: 'e425955442b146e484c3f8681987770f', boolean: true }, - { propertyId: 'b5c0e2c79ac9415e8ffe34f8b530f126', time: '1993-01-01' }, + { propertyId: 'b5c0e2c79ac9415e8ffe34f8b530f126', datetime: '1993-01-01' }, { propertyId: '45e707a5436442fbbb0b927a5a8bc061', point: '0,0' }, ], relationsList: [], @@ -630,7 +630,7 @@ describe('preparePublish', () => { valuesList: [ { propertyId: '2a8b9c7d4e5f6a7b8c9d0e1f2a3b4c5d', text: 'Existing Entity' }, { propertyId: 'eaf9f4f856474228aff58725368fc87c', float: 75 }, - { propertyId: '9b53690fea6d4bd8b4d39ea01e7f837f', time: '2023-01-01' }, + { propertyId: '9b53690fea6d4bd8b4d39ea01e7f837f', datetime: '2023-01-01' }, ], relationsList: [], }, diff --git a/packages/hypergraph/src/entity/find-many-public.ts b/packages/hypergraph/src/entity/find-many-public.ts index c87744df..56a4c39f 100644 --- a/packages/hypergraph/src/entity/find-many-public.ts +++ b/packages/hypergraph/src/entity/find-many-public.ts @@ -89,8 +89,9 @@ query ${queryName}(${variableDefinitions}) { text boolean float - time + datetime point + schedule } ${level1Relations} } @@ -102,8 +103,9 @@ type ValuesList = { text: string; boolean: boolean; float: number; - time: string; + datetime: string; point: string; + schedule: string; }[]; type RawEntity = Record; diff --git a/packages/hypergraph/src/entity/find-one-public.ts b/packages/hypergraph/src/entity/find-one-public.ts index 58cb6807..761ecefb 100644 --- a/packages/hypergraph/src/entity/find-one-public.ts +++ b/packages/hypergraph/src/entity/find-one-public.ts @@ -42,8 +42,9 @@ query entity($id: UUID!, $spaceId: UUID!) { text boolean float - time + datetime point + schedule }${relationsSelectionBlock} } } diff --git a/packages/hypergraph/src/entity/search-many-public.ts b/packages/hypergraph/src/entity/search-many-public.ts index 0932a03c..708e0993 100644 --- a/packages/hypergraph/src/entity/search-many-public.ts +++ b/packages/hypergraph/src/entity/search-many-public.ts @@ -44,8 +44,9 @@ query searchEntities($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $firs text boolean float - time + datetime point + schedule } ${relationsSelection} } diff --git a/packages/hypergraph/src/type/type.ts b/packages/hypergraph/src/type/type.ts index ba230206..8838491b 100644 --- a/packages/hypergraph/src/type/type.ts +++ b/packages/hypergraph/src/type/type.ts @@ -135,6 +135,13 @@ export const Date = (propertyId: string) => { return Schema.Date.pipe(Schema.annotations({ [PropertyIdSymbol]: propertyId, [PropertyTypeSymbol]: 'date' })); }; +/** + * Creates a ScheduleString schema with the specified GRC-20 property ID + */ +export const ScheduleString = (propertyId: string) => { + return Schema.String.pipe(Schema.annotations({ [PropertyIdSymbol]: propertyId, [PropertyTypeSymbol]: 'schedule' })); +}; + export const Point = (propertyId: string) => Schema.transform(Schema.String, Schema.Array(Schema.Number), { strict: true, diff --git a/packages/hypergraph/src/utils/convert-property-value.ts b/packages/hypergraph/src/utils/convert-property-value.ts index d8eed826..b08f493c 100644 --- a/packages/hypergraph/src/utils/convert-property-value.ts +++ b/packages/hypergraph/src/utils/convert-property-value.ts @@ -3,7 +3,15 @@ import * as Option from 'effect/Option'; import * as SchemaAST from 'effect/SchemaAST'; export const convertPropertyValue = ( - property: { propertyId: string; text: string; boolean: boolean; float: number; time: string; point: string }, + property: { + propertyId: string; + text: string; + boolean: boolean; + float: number; + datetime: string; + point: string; + schedule: string; + }, type: SchemaAST.AST, ) => { const propertyType = SchemaAST.getAnnotation(Constants.PropertyTypeSymbol)(type); @@ -43,8 +51,17 @@ export const convertPropertyValue = ( } if (propertyType.value === 'date') { // Handle case where date is stored as string in the API - if (property.time != null) { - return property.time; + if (property.datetime != null) { + return property.datetime; + } + if (property.text != null) { + return property.text; + } + return undefined; + } + if (propertyType.value === 'schedule') { + if (property.schedule != null) { + return property.schedule; } if (property.text != null) { return property.text; diff --git a/packages/hypergraph/src/utils/convert-relations.ts b/packages/hypergraph/src/utils/convert-relations.ts index 12ca1c9c..0d415916 100644 --- a/packages/hypergraph/src/utils/convert-relations.ts +++ b/packages/hypergraph/src/utils/convert-relations.ts @@ -13,8 +13,9 @@ type ValueList = { text: string; boolean: boolean; float: number; - time: string; + datetime: string; point: string; + schedule: string; }[]; type RelationsListItem = { diff --git a/packages/hypergraph/src/utils/relation-query-helpers.ts b/packages/hypergraph/src/utils/relation-query-helpers.ts index fe56e202..934f4656 100644 --- a/packages/hypergraph/src/utils/relation-query-helpers.ts +++ b/packages/hypergraph/src/utils/relation-query-helpers.ts @@ -112,8 +112,9 @@ const buildRelationsListFragment = (info: RelationTypeIdInfo, level: 1 | 2, spac text boolean float - time + datetime point + schedule } } ${toEntitySelectionHeader} { @@ -124,8 +125,9 @@ const buildRelationsListFragment = (info: RelationTypeIdInfo, level: 1 | 2, spac text boolean float - time + datetime point + schedule } ${nestedPlaceholder} } diff --git a/packages/hypergraph/test/entity/find-many-public.test.ts b/packages/hypergraph/test/entity/find-many-public.test.ts index c361f814..e303bcb2 100644 --- a/packages/hypergraph/test/entity/find-many-public.test.ts +++ b/packages/hypergraph/test/entity/find-many-public.test.ts @@ -38,14 +38,22 @@ const Parent = Entity.Schema( const buildValueEntry = ( propertyId: string, - value: Partial<{ text: string; boolean: boolean; float: number; time: string; point: string }> = {}, + value: Partial<{ + text: string; + boolean: boolean; + float: number; + datetime: string; + point: string; + schedule: string; + }> = {}, ) => ({ propertyId, text: value.text ?? '', boolean: value.boolean ?? false, float: value.float ?? 0, - time: value.time ?? new Date(0).toISOString(), + datetime: value.datetime ?? new Date(0).toISOString(), point: value.point ?? '0,0', + schedule: value.schedule ?? '', }); describe('findManyPublic parseResult', () => { diff --git a/packages/hypergraph/test/entity/find-one-public.test.ts b/packages/hypergraph/test/entity/find-one-public.test.ts index 18235d39..fb10f38b 100644 --- a/packages/hypergraph/test/entity/find-one-public.test.ts +++ b/packages/hypergraph/test/entity/find-one-public.test.ts @@ -44,14 +44,22 @@ const Parent = Entity.Schema( const buildValueEntry = ( propertyId: string, - value: Partial<{ text: string; boolean: boolean; float: number; time: string; point: string }> = {}, + value: Partial<{ + text: string; + boolean: boolean; + float: number; + datetime: string; + point: string; + schedule: string; + }> = {}, ) => ({ propertyId, text: value.text ?? '', boolean: value.boolean ?? false, float: value.float ?? 0, - time: value.time ?? new Date(0).toISOString(), + datetime: value.datetime ?? new Date(0).toISOString(), point: value.point ?? '0,0', + schedule: value.schedule ?? '', }); describe('findOnePublic', () => {