diff --git a/apps/events/src/mapping.ts b/apps/events/src/mapping.ts index b2a39ce1..ea54aabb 100644 --- a/apps/events/src/mapping.ts +++ b/apps/events/src/mapping.ts @@ -2,11 +2,20 @@ import { Id } from '@graphprotocol/grc-20'; import type { Mapping } from '@graphprotocol/hypergraph-react'; export const mapping: Mapping = { + RelationEntry: { + typeIds: [Id.Id('8f151ba4-de20-4e3c-9cb4-99ddf96f48f1')], + properties: { + name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'), + }, + }, Event: { typeIds: [Id.Id('4d876b81-787e-41fc-ab5d-075d4da66a3f')], properties: { name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'), - // description: Id.Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'), + description: Id.Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'), + }, + relations: { + any: Id.Id('8f151ba4-de20-4e3c-9cb4-99ddf96f48f1'), }, }, // Todo2: { diff --git a/apps/events/src/routes/playground.lazy.tsx b/apps/events/src/routes/playground.lazy.tsx index 5fb775c1..16641839 100644 --- a/apps/events/src/routes/playground.lazy.tsx +++ b/apps/events/src/routes/playground.lazy.tsx @@ -9,7 +9,7 @@ export const Route = createLazyFileRoute('/playground')({ function RouteComponent() { return ( - +

Playground

diff --git a/apps/events/src/schema.ts b/apps/events/src/schema.ts index e5d1f101..087bca64 100644 --- a/apps/events/src/schema.ts +++ b/apps/events/src/schema.ts @@ -20,8 +20,13 @@ export class Todo2 extends Entity.Class('Todo2')({ website: Type.Url, }) {} +export class RelationEntry extends Entity.Class('RelationEntry')({ + name: Type.Text, +}) {} + export class Event extends Entity.Class('Event')({ name: Type.Text, - // description: Type.Text, + description: Type.Text, // publishDate: Type.Text, + any: Type.Relation(RelationEntry), }) {} diff --git a/packages/hypergraph-react/src/internal/constants.ts b/packages/hypergraph-react/src/internal/constants.ts index b1a39405..23f8ad8c 100644 --- a/packages/hypergraph-react/src/internal/constants.ts +++ b/packages/hypergraph-react/src/internal/constants.ts @@ -1,4 +1,2 @@ -// const ENDPOINT = 'https://kg-staging.service.pinax.network/graphql'; -export const KG_ENDPOINT = 'https://kg.thegraph.com/graphql'; - -export const GEO_ENDPOINT = 'https://hypergraph.up.railway.app/graphql'; +export const GEO_API_MAINNET_ENDPOINT = 'https://hypergraph-v2.up.railway.app//graphql'; +export const GEO_API_TESTNET_ENDPOINT = 'https://hypergraph-v2-testnet.up.railway.app/graphql'; diff --git a/packages/hypergraph-react/src/internal/generate-delete-ops.tsx b/packages/hypergraph-react/src/internal/generate-delete-ops.tsx index 0b98a684..8b322314 100644 --- a/packages/hypergraph-react/src/internal/generate-delete-ops.tsx +++ b/packages/hypergraph-react/src/internal/generate-delete-ops.tsx @@ -1,6 +1,6 @@ import type { Op } from '@graphprotocol/grc-20'; import { gql, request } from 'graphql-request'; -import { GEO_ENDPOINT } from './constants.js'; +import { GEO_API_TESTNET_ENDPOINT } from './constants.js'; const deleteEntityQueryDocument = gql` query entity($entityId: String!) { @@ -45,7 +45,7 @@ type DeleteEntityResult = { }; export const generateDeleteOps = async ({ id, space }: { id: string; space: string }) => { - const result = await request(GEO_ENDPOINT, deleteEntityQueryDocument, { + const result = await request(GEO_API_TESTNET_ENDPOINT, deleteEntityQueryDocument, { entityId: id, }); if (result.entity === null) { diff --git a/packages/hypergraph-react/src/internal/use-query-public.tsx b/packages/hypergraph-react/src/internal/use-query-public.tsx index 3ee44939..36444fb6 100644 --- a/packages/hypergraph-react/src/internal/use-query-public.tsx +++ b/packages/hypergraph-react/src/internal/use-query-public.tsx @@ -6,50 +6,27 @@ import { gql, request } from 'graphql-request'; import { useMemo } from 'react'; import { useHypergraph } from '../HypergraphSpaceContext.js'; import type { Mapping, MappingEntry } from '../types.js'; -import { GEO_ENDPOINT } from './constants.js'; +import { GEO_API_TESTNET_ENDPOINT } from './constants.js'; import type { QueryPublicParams } from './types.js'; const entitiesQueryDocument = gql` -query entities($spaceId: String!, $typeId: String!, $relationTypeIds: [String!]!) { - entities( - filter: { - currentVersion: { - version: { - versionTypes: {some: {type: {entityId: {equalTo: $typeId}}}} - versionSpaces: {some: {spaceId: {equalTo: $spaceId}}} - } - } +query entities($spaceId: String!) { + entities(spaceId: $spaceId, filter: {}) { + id + name + values { + propertyId + value } - ) { - nodes { - id - name - currentVersion { - versionId - version { - triples { - nodes { - attributeId - textValue - booleanValue - numberValue - valueType - unitOption - } - } - relationsByFromVersionId(filter: {typeOfId: {in: $relationTypeIds}}) { - nodes { - toEntity { - nodeId - id - name - } - typeOf { - id - name - } - } - } + relations { + to { + id + name + } + type { + id + entity { + name } } } @@ -59,39 +36,25 @@ query entities($spaceId: String!, $typeId: String!, $relationTypeIds: [String!]! type EntityQueryResult = { entities: { - nodes: { - id: string; - name: string; - currentVersion: { - versionId: string; - version: { - triples: { - nodes: { - attributeId: string; - textValue: string; - booleanValue: boolean; - numberValue: number; - valueType: 'TEXT' | 'CHECKBOX' | 'POINT' | 'URL' | 'TIME' | 'NUMBER'; - unitOption: unknown; - }[]; - }; - relationsByFromVersionId: { - nodes: { - typeOf: { - name: string; - id: string; - }; - toEntity: { - nodeId: string; - id: string; - name: string; - }; - }[]; - }; + id: string; + name: string; + values: { + propertyId: string; + value: string; + }[]; + relations: { + to: { + id: string; + name: string; + }; + type: { + id: string; + entity: { + name: string; }; }; }[]; - }; + }[]; }; export const parseResult = ( @@ -104,33 +67,33 @@ export const parseResult = ( const data: Entity.Entity[] = []; const invalidEntities: Record[] = []; - for (const queryEntity of queryData.entities.nodes) { - const queryEntityVersion = queryEntity.currentVersion.version; + for (const queryEntity of queryData.entities) { const rawEntity: Record = { id: queryEntity.id, }; + // take the mappingEntry and assign the attributes to the rawEntity for (const [key, value] of Object.entries(mappingEntry?.properties ?? {})) { - const property = queryEntityVersion.triples.nodes.find((a) => a.attributeId === value); + const property = queryEntity.values.find((a) => a.propertyId === value); if (property) { if (type.fields[key] === Type.Checkbox) { - rawEntity[key] = property.booleanValue; + rawEntity[key] = Boolean(property.value); } else if (type.fields[key] === Type.Point) { - rawEntity[key] = property.textValue; + rawEntity[key] = property.value; } else if (type.fields[key] === Type.Url) { - rawEntity[key] = property.textValue; + rawEntity[key] = property.value; } else if (type.fields[key] === Type.Date) { - rawEntity[key] = property.textValue; + rawEntity[key] = property.value; } else if (type.fields[key] === Type.Number) { - rawEntity[key] = Number(property.textValue); + rawEntity[key] = Number(property.value); } else { - rawEntity[key] = property.textValue; + rawEntity[key] = property.value; } } } for (const [key, relationId] of Object.entries(mappingEntry?.relations ?? {})) { - const properties = queryEntityVersion.relationsByFromVersionId.nodes.filter((a) => a.typeOf.id === relationId); + const properties = queryEntity.relations.filter((a) => a.type.id === relationId); if (properties.length === 0) { rawEntity[key] = [] as unknown[]; continue; @@ -158,9 +121,9 @@ export const parseResult = ( } const newRelationEntities = properties.map((property) => ({ - id: property.toEntity.id, - name: property.toEntity.name, - type: relationMappingEntry.typeIds[0], + id: property.to.id, + name: property.to.name, + type: property.type.id, // TODO: should be determined by the actual value __deleted: false, // TODO: should be determined by the actual value @@ -181,7 +144,8 @@ export const parseResult = ( const decodeResult = decode({ ...rawEntity, __deleted: false, - __version: queryEntity.currentVersion.versionId, + // __version: queryEntity.currentVersion.versionId, + __version: '', }); if (Either.isRight(decodeResult)) { @@ -215,7 +179,7 @@ export const useQueryPublic = (type: S, params?: const result = useQueryTanstack({ queryKey: [`entities:geo:${typeName}`], queryFn: async () => { - const result = await request(GEO_ENDPOINT, entitiesQueryDocument, { + const result = await request(GEO_API_TESTNET_ENDPOINT, entitiesQueryDocument, { spaceId: space, typeId: mappingEntry?.typeIds[0], relationTypeIds,