Skip to content

Commit 8458747

Browse files
authored
query by type and properly invalidate queries (#232)
1 parent c3fa454 commit 8458747

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

apps/events/src/components/playground.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ export const Playground = () => {
66

77
console.log({ isLoading, isError, entityData });
88

9-
return <pre className="text-xs">{JSON.stringify(entityData, null, 2)}</pre>;
9+
return (
10+
<div>
11+
{isLoading && <div>Loading...</div>}
12+
{isError && <div>Error</div>}
13+
<pre className="text-xs">{JSON.stringify(entityData, null, 2)}</pre>
14+
</div>
15+
);
1016
};

apps/events/src/components/todos2.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,9 @@ export const Todos2 = () => {
237237
setIsPublishDiffModalOpen(false);
238238
setPublishData(null);
239239
setTimeout(() => {
240-
queryClient.invalidateQueries({ queryKey: [`entities:${Todo2.name}`] });
241-
queryClient.invalidateQueries({ queryKey: [`entities:geo:${Todo2.name}`] });
240+
queryClient.invalidateQueries({
241+
queryKey: ['hypergraph-public-entities', Todo2.name],
242+
});
242243
}, 1000);
243244
}
244245
} catch (error) {

apps/events/src/mapping.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export const mapping: Mapping = {
1212
typeIds: [Id.Id('4d876b81-787e-41fc-ab5d-075d4da66a3f')],
1313
properties: {
1414
name: Id.Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
15-
description: Id.Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'),
16-
},
17-
relations: {
18-
any: Id.Id('8f151ba4-de20-4e3c-9cb4-99ddf96f48f1'),
15+
// description: Id.Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'),
1916
},
17+
// relations: {
18+
// any: Id.Id('8f151ba4-de20-4e3c-9cb4-99ddf96f48f1'),
19+
// },
2020
},
2121
// Todo2: {
2222
// typeIds: [Id.Id('LJuM8ju67mCv78FhAiK9k9')],

apps/events/src/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class RelationEntry extends Entity.Class<RelationEntry>('RelationEntry')(
2626

2727
export class Event extends Entity.Class<Event>('Event')({
2828
name: Type.Text,
29-
description: Type.Text,
29+
// description: Type.Text,
3030
// publishDate: Type.Text,
31-
any: Type.Relation(RelationEntry),
31+
// any: Type.Relation(RelationEntry),
3232
}) {}

packages/hypergraph-react/src/internal/use-query-public.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import { GEO_API_TESTNET_ENDPOINT } from './constants.js';
1010
import type { QueryPublicParams } from './types.js';
1111

1212
const entitiesQueryDocument = gql`
13-
query entities($spaceId: String!) {
14-
entities(spaceId: $spaceId, filter: {}) {
13+
query entities($spaceId: String!, $typeIds: [String!]!) {
14+
entities(spaceId: $spaceId, filter: {
15+
types: { in: $typeIds }
16+
}) {
1517
id
1618
name
1719
values {
@@ -177,11 +179,11 @@ export const useQueryPublic = <S extends Entity.AnyNoContext>(type: S, params?:
177179
}
178180

179181
const result = useQueryTanstack({
180-
queryKey: [`entities:geo:${typeName}`],
182+
queryKey: ['hypergraph-public-entities', typeName, space, mappingEntry?.typeIds],
181183
queryFn: async () => {
182184
const result = await request<EntityQueryResult>(GEO_API_TESTNET_ENDPOINT, entitiesQueryDocument, {
183185
spaceId: space,
184-
typeId: mappingEntry?.typeIds[0],
186+
typeIds: mappingEntry?.typeIds || [],
185187
relationTypeIds,
186188
});
187189
return result;

0 commit comments

Comments
 (0)