From a4e508e56b9380ae7f3ab625cc9e62ca045cd122 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Thu, 19 Jun 2025 12:20:06 +0200 Subject: [PATCH] query by type and properly invalidate queries --- apps/events/src/components/playground.tsx | 8 +++++++- apps/events/src/components/todos2.tsx | 5 +++-- apps/events/src/mapping.ts | 8 ++++---- apps/events/src/schema.ts | 4 ++-- .../hypergraph-react/src/internal/use-query-public.tsx | 10 ++++++---- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/apps/events/src/components/playground.tsx b/apps/events/src/components/playground.tsx index c4750080..b3644455 100644 --- a/apps/events/src/components/playground.tsx +++ b/apps/events/src/components/playground.tsx @@ -6,5 +6,11 @@ export const Playground = () => { console.log({ isLoading, isError, entityData }); - return
{JSON.stringify(entityData, null, 2)}
; + return ( +
+ {isLoading &&
Loading...
} + {isError &&
Error
} +
{JSON.stringify(entityData, null, 2)}
+
+ ); }; diff --git a/apps/events/src/components/todos2.tsx b/apps/events/src/components/todos2.tsx index fcca3ab9..832edbe1 100644 --- a/apps/events/src/components/todos2.tsx +++ b/apps/events/src/components/todos2.tsx @@ -237,8 +237,9 @@ export const Todos2 = () => { setIsPublishDiffModalOpen(false); setPublishData(null); setTimeout(() => { - queryClient.invalidateQueries({ queryKey: [`entities:${Todo2.name}`] }); - queryClient.invalidateQueries({ queryKey: [`entities:geo:${Todo2.name}`] }); + queryClient.invalidateQueries({ + queryKey: ['hypergraph-public-entities', Todo2.name], + }); }, 1000); } } catch (error) { diff --git a/apps/events/src/mapping.ts b/apps/events/src/mapping.ts index ea54aabb..1f6732d2 100644 --- a/apps/events/src/mapping.ts +++ b/apps/events/src/mapping.ts @@ -12,11 +12,11 @@ export const mapping: Mapping = { 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'), - }, - relations: { - any: Id.Id('8f151ba4-de20-4e3c-9cb4-99ddf96f48f1'), + // description: Id.Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'), }, + // relations: { + // any: Id.Id('8f151ba4-de20-4e3c-9cb4-99ddf96f48f1'), + // }, }, // Todo2: { // typeIds: [Id.Id('LJuM8ju67mCv78FhAiK9k9')], diff --git a/apps/events/src/schema.ts b/apps/events/src/schema.ts index 087bca64..250818bd 100644 --- a/apps/events/src/schema.ts +++ b/apps/events/src/schema.ts @@ -26,7 +26,7 @@ export class RelationEntry extends Entity.Class('RelationEntry')( export class Event extends Entity.Class('Event')({ name: Type.Text, - description: Type.Text, + // description: Type.Text, // publishDate: Type.Text, - any: Type.Relation(RelationEntry), + // any: Type.Relation(RelationEntry), }) {} diff --git a/packages/hypergraph-react/src/internal/use-query-public.tsx b/packages/hypergraph-react/src/internal/use-query-public.tsx index 36444fb6..6349bbd9 100644 --- a/packages/hypergraph-react/src/internal/use-query-public.tsx +++ b/packages/hypergraph-react/src/internal/use-query-public.tsx @@ -10,8 +10,10 @@ import { GEO_API_TESTNET_ENDPOINT } from './constants.js'; import type { QueryPublicParams } from './types.js'; const entitiesQueryDocument = gql` -query entities($spaceId: String!) { - entities(spaceId: $spaceId, filter: {}) { +query entities($spaceId: String!, $typeIds: [String!]!) { + entities(spaceId: $spaceId, filter: { + types: { in: $typeIds } + }) { id name values { @@ -177,11 +179,11 @@ export const useQueryPublic = (type: S, params?: } const result = useQueryTanstack({ - queryKey: [`entities:geo:${typeName}`], + queryKey: ['hypergraph-public-entities', typeName, space, mappingEntry?.typeIds], queryFn: async () => { const result = await request(GEO_API_TESTNET_ENDPOINT, entitiesQueryDocument, { spaceId: space, - typeId: mappingEntry?.typeIds[0], + typeIds: mappingEntry?.typeIds || [], relationTypeIds, }); return result;