From 6c6f5d64a714e1c3ef5e58346dec7cedc0f833f9 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 14 Nov 2025 15:07:01 +0100 Subject: [PATCH] add param `offset` for Entity.findManyPublic, Entity.searchManyPublic, useEntities --- .changeset/witty-coats-march.md | 7 +++++++ apps/events/src/routes/podcasts.lazy.tsx | 5 +++-- apps/events/src/schema.ts | 12 ++++-------- .../hypergraph-react/src/hooks/use-entities.tsx | 5 +++-- packages/hypergraph-react/src/internal/types.ts | 1 + .../src/internal/use-entities-public.tsx | 5 +++-- .../hypergraph/src/entity/find-many-public.ts | 13 +++++++++---- .../hypergraph/src/entity/search-many-public.ts | 16 +++++++++------- 8 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 .changeset/witty-coats-march.md diff --git a/.changeset/witty-coats-march.md b/.changeset/witty-coats-march.md new file mode 100644 index 00000000..42e7669f --- /dev/null +++ b/.changeset/witty-coats-march.md @@ -0,0 +1,7 @@ +--- +"@graphprotocol/hypergraph-react": patch +"@graphprotocol/hypergraph": patch +--- + +add param `offset` for Entity.findManyPublic, Entity.searchManyPublic, 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 1507de14..84a937e2 100644 --- a/apps/events/src/routes/podcasts.lazy.tsx +++ b/apps/events/src/routes/podcasts.lazy.tsx @@ -7,11 +7,12 @@ export const Route = createLazyFileRoute('/podcasts')({ }); function RouteComponent() { - const space = '530a70d9-d5ee-410a-850a-cf70e4be2ee5'; + const space = 'e252f9e1-d3ad-4460-8bf1-54f93b02f220'; const { data, isLoading, isError } = useEntities(Podcast, { mode: 'public', - first: 100, + first: 6, + offset: 0, space: space, include: { projects: {}, diff --git a/apps/events/src/schema.ts b/apps/events/src/schema.ts index f46e8b0d..e5350dac 100644 --- a/apps/events/src/schema.ts +++ b/apps/events/src/schema.ts @@ -109,15 +109,11 @@ export const Image = Entity.Schema( export const Project = Entity.Schema( { name: Type.String, - description: Type.optional(Type.String), - x: Type.optional(Type.String), }, { - types: [Id('484a18c5-030a-499c-b0f2-ef588ff16d50')], + types: [Id('484a18c5-030a-499c-b0f2-ef588ff16d50')], // Project type properties: { name: Id('a126ca53-0c8e-48d5-b888-82c734c38935'), - description: Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'), - x: Id('0d625978-4b3c-4b57-a86f-de45c997c73c'), }, }, ); @@ -135,14 +131,14 @@ export const Podcast = Entity.Schema( }), }, { - types: [Id('69732974-c632-490d-81a3-12ea567b2a8e')], + types: [Id('4c81561d-1f95-4131-9cdd-dd20ab831ba2')], properties: { name: Id('a126ca53-0c8e-48d5-b888-82c734c38935'), description: Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'), dateFounded: Id('41aa3d98-47b6-4a97-b7ec-427e575b910e'), - rssFeedUrl: Id('4dd1a486-c1ad-48c6-b261-e4c8edf7ac65'), + rssFeedUrl: Id('a5776138-deb8-436f-8c98-3eccd100d98f'), projects: { - propertyId: Id('71931b5f-1d6a-462e-81d9-5b8e85fb5c4b'), + propertyId: Id('1367bac7-dcea-4b80-86ad-a4a4cdd7c2cb'), properties: { website: Id('eed38e74-e679-46bf-8a42-ea3e4f8fb5fb'), }, diff --git a/packages/hypergraph-react/src/hooks/use-entities.tsx b/packages/hypergraph-react/src/hooks/use-entities.tsx index 13b6eb1e..6932891c 100644 --- a/packages/hypergraph-react/src/hooks/use-entities.tsx +++ b/packages/hypergraph-react/src/hooks/use-entities.tsx @@ -10,11 +10,12 @@ type UseEntitiesParams = { include?: { [K in keyof Schema.Schema.Type]?: Record> } | undefined; space?: string | undefined; first?: number | undefined; + offset?: number | undefined; }; export function useEntities(type: S, params: UseEntitiesParams) { - const { mode, filter, include, space, first } = params; - const publicResult = useEntitiesPublic(type, { enabled: mode === 'public', filter, include, first, space }); + const { mode, filter, include, space, first, offset } = params; + const publicResult = useEntitiesPublic(type, { enabled: mode === 'public', filter, include, first, offset, space }); const localResult = useEntitiesPrivate(type, { enabled: mode === 'private', filter, include, space }); if (mode === 'public') { diff --git a/packages/hypergraph-react/src/internal/types.ts b/packages/hypergraph-react/src/internal/types.ts index 77f50412..fce1ca2d 100644 --- a/packages/hypergraph-react/src/internal/types.ts +++ b/packages/hypergraph-react/src/internal/types.ts @@ -8,4 +8,5 @@ export type QueryPublicParams = { include?: { [K in keyof Schema.Schema.Type]?: Record> } | undefined; space?: string | undefined; first?: number | undefined; + offset?: number | undefined; }; diff --git a/packages/hypergraph-react/src/internal/use-entities-public.tsx b/packages/hypergraph-react/src/internal/use-entities-public.tsx index 73367868..2589aa1c 100644 --- a/packages/hypergraph-react/src/internal/use-entities-public.tsx +++ b/packages/hypergraph-react/src/internal/use-entities-public.tsx @@ -7,7 +7,7 @@ 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 } = params ?? {}; + const { enabled = true, filter, include, space: spaceFromParams, first = 100, offset } = params ?? {}; const { space: spaceFromContext } = useHypergraphSpaceInternal(); const space = spaceFromParams ?? spaceFromContext; @@ -27,9 +27,10 @@ export const useEntitiesPublic = (type: S, relationTypeIds.level2, filter, first, + offset, ], queryFn: async () => { - return Entity.findManyPublic(type, { filter, include, space, first }); + return Entity.findManyPublic(type, { filter, include, space, first, offset }); }, enabled, }); diff --git a/packages/hypergraph/src/entity/find-many-public.ts b/packages/hypergraph/src/entity/find-many-public.ts index 6b1fcdd7..f7827f95 100644 --- a/packages/hypergraph/src/entity/find-many-public.ts +++ b/packages/hypergraph/src/entity/find-many-public.ts @@ -12,16 +12,18 @@ export type FindManyPublicParams = { include?: { [K in keyof Schema.Schema.Type]?: Record> } | undefined; space: string; first?: number | undefined; + offset?: number | undefined; }; const entitiesQueryDocumentLevel0 = gql` -query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!) { +query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { entities( filter: { and: [{ relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, spaceIds: {in: [$spaceId]}, }, $filter]} first: $first + offset: $offset ) { id name @@ -38,13 +40,14 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: Entity `; const entitiesQueryDocumentLevel1 = gql` -query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!) { +query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { entities( first: $first filter: { and: [{ relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, spaceIds: {in: [$spaceId]}, }, $filter]} + offset: $offset ) { id name @@ -89,13 +92,14 @@ 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!) { +query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { entities( first: $first filter: { and: [{ relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, spaceIds: {in: [$spaceId]}, }, $filter]} + offset: $offset ) { id name @@ -292,7 +296,7 @@ export const findManyPublic = async ( type: S, params?: FindManyPublicParams, ) => { - const { filter, include, space, first = 100 } = params ?? {}; + const { filter, include, space, first = 100, offset = 0 } = params ?? {}; // constructing the relation type ids for the query const relationTypeIds = Utils.getRelationTypeIds(type, include); @@ -318,6 +322,7 @@ export const findManyPublic = async ( relationTypeIdsLevel2: relationTypeIds.level2, first, filter: filterParams, + offset, }); 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 8e1caa34..12b14bb4 100644 --- a/packages/hypergraph/src/entity/search-many-public.ts +++ b/packages/hypergraph/src/entity/search-many-public.ts @@ -13,10 +13,11 @@ export type SearchManyPublicParams = { include?: { [K in keyof Schema.Schema.Type]?: Record> } | undefined; space: string | undefined; first?: number | undefined; + offset?: number | undefined; }; const searchQueryDocumentLevel0 = gql` -query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!) { +query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { search( query: $query filter: { and: [{ @@ -25,7 +26,7 @@ query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, }, $filter]} spaceId: $spaceId first: $first - offset: 0 + offset: $offset ) { id name @@ -42,7 +43,7 @@ query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $first: Int, `; const searchQueryDocumentLevel1 = gql` -query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!) { +query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { search( query: $query filter: { and: [{ @@ -51,7 +52,7 @@ query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $relationType }, $filter]} spaceId: $spaceId first: $first - offset: 0 + offset: $offset ) { id name @@ -96,7 +97,7 @@ query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $relationType `; const searchQueryDocumentLevel2 = gql` -query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!) { +query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int, $filter: EntityFilter!, $offset: Int) { search( query: $query filter: { and: [{ @@ -105,7 +106,7 @@ query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $relationType }, $filter]} spaceId: $spaceId first: $first - offset: 0 + offset: $offset ) { id name @@ -248,7 +249,7 @@ export const searchManyPublic = async ( type: S, params?: SearchManyPublicParams, ) => { - const { query, filter, include, space, first = 100 } = params ?? {}; + const { query, filter, include, space, first = 100, offset = 0 } = params ?? {}; // constructing the relation type ids for the query const relationTypeIds = Utils.getRelationTypeIds(type, include); @@ -275,6 +276,7 @@ export const searchManyPublic = async ( relationTypeIdsLevel2: relationTypeIds.level2, first, filter: filterParams, + offset, }); const { data, invalidEntities } = parseResult({ entities: result.search }, type);