Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/witty-coats-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphprotocol/hypergraph-react": patch
"@graphprotocol/hypergraph": patch
---

add param `offset` for Entity.findManyPublic, Entity.searchManyPublic, useEntities

Comment on lines +6 to +7

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This line contains trailing whitespace. Consider removing it to maintain code cleanliness.

Suggested change
add param `offset` for Entity.findManyPublic, Entity.searchManyPublic, useEntities
add param `offset` for Entity.findManyPublic, Entity.searchManyPublic, useEntities

Copilot uses AI. Check for mistakes.
5 changes: 3 additions & 2 deletions apps/events/src/routes/podcasts.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
12 changes: 4 additions & 8 deletions apps/events/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
},
},
);
Expand All @@ -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'),
},
Expand Down
5 changes: 3 additions & 2 deletions packages/hypergraph-react/src/hooks/use-entities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ type UseEntitiesParams<S extends Schema.Schema.AnyNoContext> = {
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
space?: string | undefined;
first?: number | undefined;
offset?: number | undefined;
};

export function useEntities<const S extends Schema.Schema.AnyNoContext>(type: S, params: UseEntitiesParams<S>) {
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') {
Expand Down
1 change: 1 addition & 0 deletions packages/hypergraph-react/src/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export type QueryPublicParams<S extends Schema.Schema.AnyNoContext> = {
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
space?: string | undefined;
first?: number | undefined;
offset?: number | undefined;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { QueryPublicParams } from './types.js';
import { useHypergraphSpaceInternal } from './use-hypergraph-space-internal.js';

export const useEntitiesPublic = <S extends Schema.Schema.AnyNoContext>(type: S, params?: QueryPublicParams<S>) => {
const { enabled = true, filter, include, space: spaceFromParams, first = 100 } = params ?? {};
const { enabled = true, filter, include, space: spaceFromParams, first = 100, offset } = params ?? {};

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The offset parameter should have a default value of 0 to be consistent with the implementation in findManyPublic and searchManyPublic functions. Without a default, if offset is undefined, it will be passed as undefined to Entity.findManyPublic, though the function itself has a default value that will handle it. For consistency and clarity, consider adding the default here:

const { enabled = true, filter, include, space: spaceFromParams, first = 100, offset = 0 } = params ?? {};
Suggested change
const { enabled = true, filter, include, space: spaceFromParams, first = 100, offset } = params ?? {};
const { enabled = true, filter, include, space: spaceFromParams, first = 100, offset = 0 } = params ?? {};

Copilot uses AI. Check for mistakes.
const { space: spaceFromContext } = useHypergraphSpaceInternal();
const space = spaceFromParams ?? spaceFromContext;

Expand All @@ -27,9 +27,10 @@ export const useEntitiesPublic = <S extends Schema.Schema.AnyNoContext>(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,
});
Expand Down
13 changes: 9 additions & 4 deletions packages/hypergraph/src/entity/find-many-public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ export type FindManyPublicParams<S extends Schema.Schema.AnyNoContext> = {
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | 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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -292,7 +296,7 @@ export const findManyPublic = async <S extends Schema.Schema.AnyNoContext>(
type: S,
params?: FindManyPublicParams<S>,
) => {
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);
Expand All @@ -318,6 +322,7 @@ export const findManyPublic = async <S extends Schema.Schema.AnyNoContext>(
relationTypeIdsLevel2: relationTypeIds.level2,
first,
filter: filterParams,
offset,
});

const { data, invalidEntities } = parseResult(result, type);
Expand Down
16 changes: 9 additions & 7 deletions packages/hypergraph/src/entity/search-many-public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export type SearchManyPublicParams<S extends Schema.Schema.AnyNoContext> = {
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | 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: [{
Expand All @@ -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
Expand All @@ -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: [{
Expand All @@ -51,7 +52,7 @@ query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $relationType
}, $filter]}
spaceId: $spaceId
first: $first
offset: 0
offset: $offset
) {
id
name
Expand Down Expand Up @@ -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: [{
Expand All @@ -105,7 +106,7 @@ query search($query: String!, $spaceId: UUID!, $typeIds: [UUID!]!, $relationType
}, $filter]}
spaceId: $spaceId
first: $first
offset: 0
offset: $offset
) {
id
name
Expand Down Expand Up @@ -248,7 +249,7 @@ export const searchManyPublic = async <S extends Schema.Schema.AnyNoContext>(
type: S,
params?: SearchManyPublicParams<S>,
) => {
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);
Expand All @@ -275,6 +276,7 @@ export const searchManyPublic = async <S extends Schema.Schema.AnyNoContext>(
relationTypeIdsLevel2: relationTypeIds.level2,
first,
filter: filterParams,
offset,
});

const { data, invalidEntities } = parseResult({ entities: result.search }, type);
Expand Down
Loading