Skip to content

Commit 86d8628

Browse files
authored
add first filter (#314)
1 parent 6fc00da commit 86d8628

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

apps/events/src/components/playground.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const Playground = () => {
1717
jobOffers: {},
1818
},
1919
},
20+
first: 2,
2021
});
2122
const [isDeleting, setIsDeleting] = useState(false);
2223
const [isCreating, setIsCreating] = useState(false);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export type QueryPublicParams<S extends Entity.AnyNoContext> = {
55
enabled: boolean;
66
// TODO: for multi-level nesting it should only allow the allowed properties instead of Record<string, Record<string, never>>
77
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
8+
first?: number | undefined;
89
};

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import { GEO_API_TESTNET_ENDPOINT } from './constants.js';
1010
import type { QueryPublicParams } from './types.js';
1111

1212
const entitiesQueryDocumentLevel0 = gql`
13-
query entities($spaceId: UUID!, $typeIds: [UUID!]!) {
13+
query entities($spaceId: UUID!, $typeIds: [UUID!]!, $first: Int) {
1414
entities(
1515
filter: {
1616
relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, spaceIds: {in: [$spaceId]}},
17+
first: $first
1718
) {
1819
id
1920
name
@@ -26,8 +27,10 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!) {
2627
`;
2728

2829
const entitiesQueryDocumentLevel1 = gql`
29-
query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!) {
30-
entities(filter: {
30+
query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $first: Int) {
31+
entities(
32+
first: $first
33+
filter: {
3134
relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, spaceIds: {in: [$spaceId]}}) {
3235
id
3336
name
@@ -53,8 +56,10 @@ query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUI
5356
`;
5457

5558
const entitiesQueryDocumentLevel2 = gql`
56-
query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!) {
57-
entities(filter: {
59+
query entities($spaceId: UUID!, $typeIds: [UUID!]!, $relationTypeIdsLevel1: [UUID!]!, $relationTypeIdsLevel2: [UUID!]!, $first: Int) {
60+
entities(
61+
first: $first
62+
filter: {
5863
relations: {some: {typeId: {is: "8f151ba4-de20-4e3c-9cb4-99ddf96f48f1"}, toEntityId: {in: $typeIds}}}, spaceIds: {in: [$spaceId]}}) {
5964
id
6065
name
@@ -290,7 +295,7 @@ export const parseResult = <S extends Entity.AnyNoContext>(
290295
};
291296

292297
export const useQueryPublic = <S extends Entity.AnyNoContext>(type: S, params?: QueryPublicParams<S>) => {
293-
const { enabled = true, include } = params ?? {};
298+
const { enabled = true, include, first = 100 } = params ?? {};
294299
const { space } = useHypergraphSpaceInternal();
295300
const mapping = useSelector(store, (state) => state.context.mapping);
296301

@@ -327,6 +332,7 @@ export const useQueryPublic = <S extends Entity.AnyNoContext>(type: S, params?:
327332
mappingEntry?.typeIds,
328333
relationTypeIdsLevel1,
329334
relationTypeIdsLevel2,
335+
// TODO should `first` be in here?
330336
],
331337
queryFn: async () => {
332338
let queryDocument = entitiesQueryDocumentLevel0;
@@ -342,6 +348,7 @@ export const useQueryPublic = <S extends Entity.AnyNoContext>(type: S, params?:
342348
typeIds: mappingEntry?.typeIds || [],
343349
relationTypeIdsLevel1,
344350
relationTypeIdsLevel2,
351+
first,
345352
});
346353
return result;
347354
},

packages/hypergraph-react/src/use-query.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type QueryParams<S extends Entity.AnyNoContext> = {
1010
// TODO: for multi-level nesting it should only allow the allowed properties instead of Record<string, Record<string, never>>
1111
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
1212
space?: string;
13+
first?: number | undefined;
1314
};
1415

1516
// @ts-expect-error TODO: remove this function
@@ -144,8 +145,8 @@ const getDiff = <S extends Entity.AnyNoContext>(
144145
const preparePublishDummy = () => undefined;
145146

146147
export function useQuery<const S extends Entity.AnyNoContext>(type: S, params: QueryParams<S>) {
147-
const { mode, filter, include, space } = params;
148-
const publicResult = useQueryPublic(type, { enabled: mode === 'public', include });
148+
const { mode, filter, include, space, first } = params;
149+
const publicResult = useQueryPublic(type, { enabled: mode === 'public', include, first });
149150
const localResult = useQueryLocal(type, { enabled: mode === 'private', filter, include, space });
150151
// const mapping = useSelector(store, (state) => state.context.mapping);
151152
// const generateUpdateOps = useGenerateUpdateOps(type, mode === 'merged');

0 commit comments

Comments
 (0)