diff --git a/apps/events/src/components/playground.tsx b/apps/events/src/components/playground.tsx index 03c7b49f..cd266c40 100644 --- a/apps/events/src/components/playground.tsx +++ b/apps/events/src/components/playground.tsx @@ -17,6 +17,7 @@ export const Playground = () => { jobOffers: {}, }, }, + first: 2, }); const [isDeleting, setIsDeleting] = useState(false); const [isCreating, setIsCreating] = useState(false); diff --git a/packages/hypergraph-react/src/internal/types.ts b/packages/hypergraph-react/src/internal/types.ts index ee4c4f51..f69f5589 100644 --- a/packages/hypergraph-react/src/internal/types.ts +++ b/packages/hypergraph-react/src/internal/types.ts @@ -5,4 +5,5 @@ export type QueryPublicParams = { enabled: boolean; // TODO: for multi-level nesting it should only allow the allowed properties instead of Record> include?: { [K in keyof Schema.Schema.Type]?: Record> } | undefined; + first?: number | undefined; }; diff --git a/packages/hypergraph-react/src/internal/use-query-public.tsx b/packages/hypergraph-react/src/internal/use-query-public.tsx index 40125c24..9efdf6d1 100644 --- a/packages/hypergraph-react/src/internal/use-query-public.tsx +++ b/packages/hypergraph-react/src/internal/use-query-public.tsx @@ -10,10 +10,11 @@ import { GEO_API_TESTNET_ENDPOINT } from './constants.js'; import type { QueryPublicParams } from './types.js'; const entitiesQueryDocumentLevel0 = gql` -query entities($spaceId: UUID!, $typeIds: [UUID!]!) { +query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int) { entities( filter: { relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, spaceIds: {in: [$spaceId]}}, + first: $first ) { id name @@ -26,8 +27,10 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!) { `; const entitiesQueryDocumentLevel1 = gql` -query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!) { - entities(filter: { +query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int) { + entities( + first: $first + filter: { relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, spaceIds: {in: [$spaceId]}}) { id name @@ -53,8 +56,10 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI `; const entitiesQueryDocumentLevel2 = gql` -query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!) { - entities(filter: { +query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int) { + entities( + first: $first + filter: { relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, spaceIds: {in: [$spaceId]}}) { id name @@ -290,7 +295,7 @@ export const parseResult = ( }; export const useQueryPublic = (type: S, params?: QueryPublicParams) => { - const { enabled = true, include } = params ?? {}; + const { enabled = true, include, first = 100 } = params ?? {}; const { space } = useHypergraphSpaceInternal(); const mapping = useSelector(store, (state) => state.context.mapping); @@ -327,6 +332,7 @@ export const useQueryPublic = (type: S, params?: mappingEntry?.typeIds, relationTypeIdsLevel1, relationTypeIdsLevel2, + // TODO should `first` be in here? ], queryFn: async () => { let queryDocument = entitiesQueryDocumentLevel0; @@ -342,6 +348,7 @@ export const useQueryPublic = (type: S, params?: typeIds: mappingEntry?.typeIds || [], relationTypeIdsLevel1, relationTypeIdsLevel2, + first, }); return result; }, diff --git a/packages/hypergraph-react/src/use-query.tsx b/packages/hypergraph-react/src/use-query.tsx index 97ed23a0..1ece799a 100644 --- a/packages/hypergraph-react/src/use-query.tsx +++ b/packages/hypergraph-react/src/use-query.tsx @@ -10,6 +10,7 @@ type QueryParams = { // TODO: for multi-level nesting it should only allow the allowed properties instead of Record> include?: { [K in keyof Schema.Schema.Type]?: Record> } | undefined; space?: string; + first?: number | undefined; }; // @ts-expect-error TODO: remove this function @@ -144,8 +145,8 @@ const getDiff = ( const preparePublishDummy = () => undefined; export function useQuery(type: S, params: QueryParams) { - const { mode, filter, include, space } = params; - const publicResult = useQueryPublic(type, { enabled: mode === 'public', include }); + const { mode, filter, include, space, first } = params; + const publicResult = useQueryPublic(type, { enabled: mode === 'public', include, first }); const localResult = useQueryLocal(type, { enabled: mode === 'private', filter, include, space }); // const mapping = useSelector(store, (state) => state.context.mapping); // const generateUpdateOps = useGenerateUpdateOps(type, mode === 'merged');