diff --git a/.changeset/kind-peas-sniff.md b/.changeset/kind-peas-sniff.md new file mode 100644 index 00000000..ad2aa2b1 --- /dev/null +++ b/.changeset/kind-peas-sniff.md @@ -0,0 +1,7 @@ +--- +"@graphprotocol/hypergraph-react": patch +"@graphprotocol/hypergraph": patch +--- + +add temporary backlinksTotalCountsTypeId1 to Entity.findManyPublic and useEntities + \ No newline at end of file diff --git a/apps/events/src/routes/podcasts.lazy.tsx b/apps/events/src/routes/podcasts.lazy.tsx index 05c8003c..78821660 100644 --- a/apps/events/src/routes/podcasts.lazy.tsx +++ b/apps/events/src/routes/podcasts.lazy.tsx @@ -17,6 +17,7 @@ function RouteComponent() { projects: {}, }, orderBy: { property: 'dateFounded', direction: 'asc' }, + backlinksTotalCountsTypeId1: '972d201a-d780-4568-9e01-543f67b26bee', }); console.log({ data, isLoading, isError }); return ( @@ -27,7 +28,7 @@ function RouteComponent() { {data?.map((podcast) => (

- {podcast.dateFounded.toISOString()} {podcast.name} + {podcast.backlinksTotalCountsTypeId1} - {podcast.dateFounded.toISOString()} {podcast.name}

{podcast.projects.map((project) => (
diff --git a/packages/hypergraph-react/src/hooks/use-entities.tsx b/packages/hypergraph-react/src/hooks/use-entities.tsx index d311e486..79ffbb7a 100644 --- a/packages/hypergraph-react/src/hooks/use-entities.tsx +++ b/packages/hypergraph-react/src/hooks/use-entities.tsx @@ -17,10 +17,11 @@ type UseEntitiesParams = { direction: 'asc' | 'desc'; } | undefined; + backlinksTotalCountsTypeId1?: string | undefined; }; export function useEntities(type: S, params: UseEntitiesParams) { - const { mode, filter, include, space, first, offset, orderBy } = params; + const { mode, filter, include, space, first, offset, orderBy, backlinksTotalCountsTypeId1 } = params; const publicResult = useEntitiesPublic(type, { enabled: mode === 'public', filter, @@ -29,6 +30,7 @@ export function useEntities(type: S, offset, space, orderBy, + backlinksTotalCountsTypeId1, }); const localResult = useEntitiesPrivate(type, { enabled: mode === 'private', filter, include, space }); @@ -41,7 +43,7 @@ export function useEntities(type: S, return { ...publicResult, - data: localResult.entities, + data: localResult.entities as (Entity.Entity & { backlinksTotalCountsTypeId1?: number })[], deleted: localResult.deletedEntities, }; } diff --git a/packages/hypergraph-react/src/internal/types.ts b/packages/hypergraph-react/src/internal/types.ts index 259198b8..7760b684 100644 --- a/packages/hypergraph-react/src/internal/types.ts +++ b/packages/hypergraph-react/src/internal/types.ts @@ -15,4 +15,5 @@ export type QueryPublicParams = { direction: 'asc' | 'desc'; } | undefined; + backlinksTotalCountsTypeId1?: string | undefined; }; diff --git a/packages/hypergraph-react/src/internal/use-entities-public.tsx b/packages/hypergraph-react/src/internal/use-entities-public.tsx index e8b9b7a1..fc1dee5d 100644 --- a/packages/hypergraph-react/src/internal/use-entities-public.tsx +++ b/packages/hypergraph-react/src/internal/use-entities-public.tsx @@ -7,7 +7,16 @@ import type { QueryPublicParams } from './types.js'; import { useHypergraphSpaceInternal } from './use-hypergraph-space-internal.js'; export const useEntitiesPublic = (type: S, params?: QueryPublicParams) => { - const { enabled = true, filter, include, space: spaceFromParams, first = 100, offset, orderBy } = params ?? {}; + const { + enabled = true, + filter, + include, + space: spaceFromParams, + first = 100, + offset, + orderBy, + backlinksTotalCountsTypeId1, + } = params ?? {}; const { space: spaceFromContext } = useHypergraphSpaceInternal(); const space = spaceFromParams ?? spaceFromContext; @@ -29,9 +38,18 @@ export const useEntitiesPublic = (type: S, first, offset, orderBy, + backlinksTotalCountsTypeId1, ], queryFn: async () => { - return Entity.findManyPublic(type, { filter, include, space, first, offset, orderBy }); + return Entity.findManyPublic(type, { + filter, + include, + space, + first, + offset, + orderBy, + backlinksTotalCountsTypeId1, + }); }, enabled, }); diff --git a/packages/hypergraph/src/entity/find-many-public.ts b/packages/hypergraph/src/entity/find-many-public.ts index de8e01bc..0098363f 100644 --- a/packages/hypergraph/src/entity/find-many-public.ts +++ b/packages/hypergraph/src/entity/find-many-public.ts @@ -19,10 +19,11 @@ export type FindManyPublicParams = { direction: 'asc' | 'desc'; } | undefined; + backlinksTotalCountsTypeId1?: string | undefined; }; const entitiesQueryDocumentLevel0 = gql` -query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { +query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { entities( filter: { and: [{ 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 time point } + backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { + totalCount + } } } `; const entitiesQueryDocumentLevel1 = gql` -query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { +query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { entities( first: $first filter: { and: [{ @@ -65,6 +69,9 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI time point } + backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { + totalCount + } relationsList( filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}}, ) { @@ -98,7 +105,7 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI `; const entitiesQueryDocumentLevel2 = gql` -query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { +query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { entities( first: $first filter: { and: [{ @@ -117,6 +124,9 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI time point } + backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { + totalCount + } relationsList( filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}}, ) { @@ -142,6 +152,9 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI time point } + backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { + totalCount + } relationsList( filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel2}}, # 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 `; const entitiesOrderedByPropertyQueryDocumentLevel0 = gql` -query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!) { +query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { entities: entitiesOrderedByProperty( filter: { and: [{ relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, @@ -200,12 +213,15 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int time point } + backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { + totalCount + } } } `; const entitiesOrderedByPropertyQueryDocumentLevel1 = gql` -query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!) { +query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { entities: entitiesOrderedByProperty( first: $first filter: { and: [{ @@ -226,6 +242,9 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy time point } + backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { + totalCount + } relationsList( filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}}, ) { @@ -259,7 +278,7 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy `; const entitiesOrderedByPropertyQueryDocumentLevel2 = gql` -query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!) { +query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int, $propertyId: UUID!, $sortDirection: SortOrder!, $backlinksTotalCountsTypeId1: UUID, $backlinksTotalCountsTypeId1Present: Boolean!) { entities: entitiesOrderedByProperty( first: $first filter: { and: [{ @@ -280,6 +299,9 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy time point } + backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { + totalCount + } relationsList( filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel1}}, ) { @@ -305,6 +327,9 @@ query entitiesOrderedByProperty($spaceId: UUID!, $typeIds: [UUID!]!, $relationTy time point } + backlinksTotalCountsTypeId1: backlinks(filter: { spaceId: {is: $spaceId}, fromEntity: { typeIds: { is: [$backlinksTotalCountsTypeId1] } }}) @include(if: $backlinksTotalCountsTypeId1Present) { + totalCount + } relationsList( filter: {spaceId: {is: $spaceId}, typeId:{ in: $relationTypeIdsLevel2}}, ) { @@ -352,6 +377,9 @@ type EntityQueryResult = { time: string; point: string; }[]; + backlinksTotalCountsTypeId1: { + totalCount: number; + } | null; relationsList: { id: string; entity: { @@ -412,7 +440,7 @@ type GraphSortDirection = 'ASC' | 'DESC'; export const parseResult = (queryData: EntityQueryResult, type: S) => { const schemaWithId = Utils.addIdSchemaField(type); const decode = Schema.decodeUnknownEither(schemaWithId); - const data: Entity.Entity[] = []; + const data: (Entity.Entity & { backlinksTotalCountsTypeId1?: number })[] = []; const invalidEntities: Record[] = []; for (const queryEntity of queryData.entities) { @@ -454,7 +482,11 @@ export const parseResult = (queryData: Ent if (Either.isRight(decodeResult)) { // injecting the schema to the entity to be able to access it in the preparePublish function - data.push({ ...decodeResult.right, __schema: type }); + data.push({ + ...decodeResult.right, + __schema: type, + backlinksTotalCountsTypeId1: queryEntity.backlinksTotalCountsTypeId1?.totalCount, + }); } else { invalidEntities.push(rawEntity); } @@ -466,7 +498,7 @@ export const findManyPublic = async ( type: S, params?: FindManyPublicParams, ) => { - const { filter, include, space, first = 100, offset = 0, orderBy } = params ?? {}; + const { filter, include, space, first = 100, offset = 0, orderBy, backlinksTotalCountsTypeId1 } = params ?? {}; // constructing the relation type ids for the query const relationTypeIds = Utils.getRelationTypeIds(type, include); @@ -534,6 +566,13 @@ export const findManyPublic = async ( queryVariables.sortDirection = sortDirection; } + if (backlinksTotalCountsTypeId1) { + queryVariables.backlinksTotalCountsTypeId1 = backlinksTotalCountsTypeId1; + queryVariables.backlinksTotalCountsTypeId1Present = true; + } else { + queryVariables.backlinksTotalCountsTypeId1Present = false; + } + const result = await request(`${Graph.TESTNET_API_ORIGIN}/graphql`, queryDocument, queryVariables); const { data, invalidEntities } = parseResult(result, type); diff --git a/packages/hypergraph/src/entity/search-many-public.ts b/packages/hypergraph/src/entity/search-many-public.ts index 12b14bb4..781ce573 100644 --- a/packages/hypergraph/src/entity/search-many-public.ts +++ b/packages/hypergraph/src/entity/search-many-public.ts @@ -279,6 +279,7 @@ export const searchManyPublic = async ( offset, }); + // @ts-expect-error TODO: fix this const { data, invalidEntities } = parseResult({ entities: result.search }, type); return { data, invalidEntities }; };