Skip to content

Commit 850e827

Browse files
committed
resolve relation type ids level 1
1 parent 419522a commit 850e827

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

apps/events/src/components/playground.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { useQuery } from '@graphprotocol/hypergraph-react';
22
import { Event } from '../schema';
33

44
export const Playground = () => {
5-
const { data: entityData, isLoading, isError } = useQuery(Event, { mode: 'public' });
5+
const {
6+
data: entityData,
7+
isLoading,
8+
isError,
9+
} = useQuery(Event, {
10+
mode: 'public',
11+
include: { sponsors: {} },
12+
});
613

714
console.log({ isLoading, isError, entityData });
815

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ 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!, $typeIds: [String!]!) {
13+
query entities($spaceId: String!, $typeIds: [String!]!, $relationTypeIdsLevel1: [String!]!) {
1414
entities(spaceId: $spaceId, filter: {
1515
types: { in: $typeIds }
1616
}) {
@@ -20,7 +20,9 @@ query entities($spaceId: String!, $typeIds: [String!]!) {
2020
propertyId
2121
value
2222
}
23-
relations {
23+
relations(filter: {
24+
type: { in: $relationTypeIdsLevel1 }
25+
}) {
2426
to {
2527
id
2628
name
@@ -320,10 +322,10 @@ export const useQueryPublic = <S extends Entity.AnyNoContext>(type: S, params?:
320322
throw new Error(`Mapping entry for ${typeName} not found`);
321323
}
322324

323-
const relationTypeIds: string[] = [];
325+
const relationTypeIdsLevel1: string[] = [];
324326
for (const key in mappingEntry?.relations ?? {}) {
325327
if (include?.[key] && mappingEntry?.relations?.[key]) {
326-
relationTypeIds.push(mappingEntry?.relations?.[key]);
328+
relationTypeIdsLevel1.push(mappingEntry?.relations?.[key]);
327329
}
328330
}
329331

@@ -333,7 +335,7 @@ export const useQueryPublic = <S extends Entity.AnyNoContext>(type: S, params?:
333335
const result = await request<EntityQueryResult>(GEO_API_TESTNET_ENDPOINT, entitiesQueryDocument, {
334336
spaceId: space,
335337
typeIds: mappingEntry?.typeIds || [],
336-
relationTypeIds,
338+
relationTypeIdsLevel1,
337339
});
338340
return result;
339341
},

0 commit comments

Comments
 (0)