Skip to content

Commit e686482

Browse files
committed
add backlinksTotalCountsTypeId1
1 parent 2f00ab7 commit e686482

6 files changed

Lines changed: 83 additions & 15 deletions

File tree

.changeset/kind-peas-sniff.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@graphprotocol/hypergraph-react": patch
3+
"@graphprotocol/hypergraph": patch
4+
---
5+
6+
add temporary backlinksTotalCountsTypeId1 to Entity.findManyPublic and useEntities
7+

apps/events/src/routes/podcasts.lazy.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { Podcast } from '@/schema';
12
import { useEntities } from '@graphprotocol/hypergraph-react';
23
import { createLazyFileRoute } from '@tanstack/react-router';
3-
import { Podcast } from '@/schema';
44

55
export const Route = createLazyFileRoute('/podcasts')({
66
component: RouteComponent,
@@ -17,6 +17,7 @@ function RouteComponent() {
1717
projects: {},
1818
},
1919
orderBy: { property: 'dateFounded', direction: 'asc' },
20+
backlinksTotalCountsTypeId1: '972d201a-d780-4568-9e01-543f67b26bee',
2021
});
2122
console.log({ data, isLoading, isError });
2223
return (
@@ -27,7 +28,7 @@ function RouteComponent() {
2728
{data?.map((podcast) => (
2829
<div key={podcast.id}>
2930
<h2>
30-
{podcast.dateFounded.toISOString()} {podcast.name}
31+
{podcast.backlinksTotalCountsTypeId1} - {podcast.dateFounded.toISOString()} {podcast.name}
3132
</h2>
3233
{podcast.projects.map((project) => (
3334
<div key={project._relation.id}>

packages/hypergraph-react/src/hooks/use-entities.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ type UseEntitiesParams<S extends Schema.Schema.AnyNoContext> = {
1717
direction: 'asc' | 'desc';
1818
}
1919
| undefined;
20+
backlinksTotalCountsTypeId1?: string | undefined;
2021
};
2122

2223
export function useEntities<const S extends Schema.Schema.AnyNoContext>(type: S, params: UseEntitiesParams<S>) {
23-
const { mode, filter, include, space, first, offset, orderBy } = params;
24+
const { mode, filter, include, space, first, offset, orderBy, backlinksTotalCountsTypeId1 } = params;
2425
const publicResult = useEntitiesPublic(type, {
2526
enabled: mode === 'public',
2627
filter,
@@ -29,6 +30,7 @@ export function useEntities<const S extends Schema.Schema.AnyNoContext>(type: S,
2930
offset,
3031
space,
3132
orderBy,
33+
backlinksTotalCountsTypeId1,
3234
});
3335
const localResult = useEntitiesPrivate(type, { enabled: mode === 'private', filter, include, space });
3436

@@ -41,7 +43,7 @@ export function useEntities<const S extends Schema.Schema.AnyNoContext>(type: S,
4143

4244
return {
4345
...publicResult,
44-
data: localResult.entities,
46+
data: localResult.entities as (Entity.Entity<S> & { backlinksTotalCountsTypeId1?: number })[],
4547
deleted: localResult.deletedEntities,
4648
};
4749
}

packages/hypergraph-react/src/internal/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ export type QueryPublicParams<S extends Schema.Schema.AnyNoContext> = {
1515
direction: 'asc' | 'desc';
1616
}
1717
| undefined;
18+
backlinksTotalCountsTypeId1?: string | undefined;
1819
};

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ import type { QueryPublicParams } from './types.js';
77
import { useHypergraphSpaceInternal } from './use-hypergraph-space-internal.js';
88

99
export const useEntitiesPublic = <S extends Schema.Schema.AnyNoContext>(type: S, params?: QueryPublicParams<S>) => {
10-
const { enabled = true, filter, include, space: spaceFromParams, first = 100, offset, orderBy } = params ?? {};
10+
const {
11+
enabled = true,
12+
filter,
13+
include,
14+
space: spaceFromParams,
15+
first = 100,
16+
offset,
17+
orderBy,
18+
backlinksTotalCountsTypeId1,
19+
} = params ?? {};
1120
const { space: spaceFromContext } = useHypergraphSpaceInternal();
1221
const space = spaceFromParams ?? spaceFromContext;
1322

@@ -29,9 +38,18 @@ export const useEntitiesPublic = <S extends Schema.Schema.AnyNoContext>(type: S,
2938
first,
3039
offset,
3140
orderBy,
41+
backlinksTotalCountsTypeId1,
3242
],
3343
queryFn: async () => {
34-
return Entity.findManyPublic(type, { filter, include, space, first, offset, orderBy });
44+
return Entity.findManyPublic(type, {
45+
filter,
46+
include,
47+
space,
48+
first,
49+
offset,
50+
orderBy,
51+
backlinksTotalCountsTypeId1,
52+
});
3553
},
3654
enabled,
3755
});

packages/hypergraph/src/entity/find-many-public.ts

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ export type FindManyPublicParams<S extends Schema.Schema.AnyNoContext> = {
1919
direction: 'asc' | 'desc';
2020
}
2121
| undefined;
22+
backlinksTotalCountsTypeId1?: string | undefined;
2223
};
2324

2425
const entitiesQueryDocumentLevel0 = gql`
25-
query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) {
26+
query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) {
2627
entities(
2728
filter: { and: [{
2829
relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}},
@@ -41,12 +42,15 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: Entity
4142
time
4243
point
4344
}
45+
backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) {
46+
totalCount
47+
}
4448
}
4549
}
4650
`;
4751

4852
const entitiesQueryDocumentLevel1 = gql`
49-
query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) {
53+
query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) {
5054
entities(
5155
first: $first
5256
filter: { and: [{
@@ -65,6 +69,9 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI
6569
time
6670
point
6771
}
72+
backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) {
73+
totalCount
74+
}
6875
relationsList(
6976
filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}},
7077
) {
@@ -98,7 +105,7 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI
98105
`;
99106

100107
const entitiesQueryDocumentLevel2 = gql`
101-
query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) {
108+
query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) {
102109
entities(
103110
first: $first
104111
filter: { and: [{
@@ -117,6 +124,9 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI
117124
time
118125
point
119126
}
127+
backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) {
128+
totalCount
129+
}
120130
relationsList(
121131
filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}},
122132
) {
@@ -142,6 +152,9 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI
142152
time
143153
point
144154
}
155+
backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) {
156+
totalCount
157+
}
145158
relationsList(
146159
filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel2}},
147160
# filter: {spaceId: {is: $spaceId}, toEntity: {relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $relationTypeIdsLevel2}}}}}
@@ -179,7 +192,7 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI
179192
`;
180193

181194
const entitiesOrderedByPropertyQueryDocumentLevel0 = gql`
182-
query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!) {
195+
query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) {
183196
entities: entitiesOrderedByProperty(
184197
filter: { and: [{
185198
relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}},
@@ -200,12 +213,15 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int
200213
time
201214
point
202215
}
216+
backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) {
217+
totalCount
218+
}
203219
}
204220
}
205221
`;
206222

207223
const entitiesOrderedByPropertyQueryDocumentLevel1 = gql`
208-
query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!) {
224+
query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) {
209225
entities: entitiesOrderedByProperty(
210226
first: $first
211227
filter: { and: [{
@@ -226,6 +242,9 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy
226242
time
227243
point
228244
}
245+
backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) {
246+
totalCount
247+
}
229248
relationsList(
230249
filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}},
231250
) {
@@ -259,7 +278,7 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy
259278
`;
260279

261280
const entitiesOrderedByPropertyQueryDocumentLevel2 = gql`
262-
query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!) {
281+
query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) {
263282
entities: entitiesOrderedByProperty(
264283
first: $first
265284
filter: { and: [{
@@ -280,6 +299,9 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy
280299
time
281300
point
282301
}
302+
backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) {
303+
totalCount
304+
}
283305
relationsList(
284306
filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}},
285307
) {
@@ -305,6 +327,9 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy
305327
time
306328
point
307329
}
330+
backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) {
331+
totalCount
332+
}
308333
relationsList(
309334
filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel2}},
310335
) {
@@ -352,6 +377,9 @@ type EntityQueryResult = {
352377
time: string;
353378
point: string;
354379
}[];
380+
backlinksTotalCountsTypeId1: {
381+
totalCount: number;
382+
} | null;
355383
relationsList: {
356384
id: string;
357385
entity: {
@@ -412,7 +440,7 @@ type GraphSortDirection = 'ASC' | 'DESC';
412440
export const parseResult = <S extends Schema.Schema.AnyNoContext>(queryData: EntityQueryResult, type: S) => {
413441
const schemaWithId = Utils.addIdSchemaField(type);
414442
const decode = Schema.decodeUnknownEither(schemaWithId);
415-
const data: Entity.Entity<S>[] = [];
443+
const data: (Entity.Entity<S> & { backlinksTotalCountsTypeId1?: number })[] = [];
416444
const invalidEntities: Record<string, unknown>[] = [];
417445

418446
for (const queryEntity of queryData.entities) {
@@ -454,7 +482,11 @@ export const parseResult = <S extends Schema.Schema.AnyNoContext>(queryData: Ent
454482

455483
if (Either.isRight(decodeResult)) {
456484
// injecting the schema to the entity to be able to access it in the preparePublish function
457-
data.push({ ...decodeResult.right, __schema: type });
485+
data.push({
486+
...decodeResult.right,
487+
__schema: type,
488+
backlinksTotalCountsTypeId1: queryEntity.backlinksTotalCountsTypeId1?.totalCount,
489+
});
458490
} else {
459491
invalidEntities.push(rawEntity);
460492
}
@@ -466,7 +498,7 @@ export const findManyPublic = async <S extends Schema.Schema.AnyNoContext>(
466498
type: S,
467499
params?: FindManyPublicParams<S>,
468500
) => {
469-
const { filter, include, space, first = 100, offset = 0, orderBy } = params ?? {};
501+
const { filter, include, space, first = 100, offset = 0, orderBy, backlinksTotalCountsTypeId1 } = params ?? {};
470502

471503
// constructing the relation type ids for the query
472504
const relationTypeIds = Utils.getRelationTypeIds(type, include);
@@ -534,6 +566,13 @@ export const findManyPublic = async <S extends Schema.Schema.AnyNoContext>(
534566
queryVariables.sortDirection = sortDirection;
535567
}
536568

569+
if (backlinksTotalCountsTypeId1) {
570+
queryVariables.backlinksTotalCountsTypeId1 = backlinksTotalCountsTypeId1;
571+
queryVariables.backlinksTotalCountsTypeId1Present = true;
572+
} else {
573+
queryVariables.backlinksTotalCountsTypeId1Present = false;
574+
}
575+
537576
const result = await request<EntityQueryResult>(`${Graph.TESTNET_API_ORIGIN}/graphql`, queryDocument, queryVariables);
538577

539578
const { data, invalidEntities } = parseResult(result, type);

0 commit comments

Comments
 (0)