Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions apps/events/src/components/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const Playground = () => {
jobOffers: {},
},
},
first: 2,
});
const [isDeleting, setIsDeleting] = useState(false);
const [isCreating, setIsCreating] = useState(false);
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 @@ -5,4 +5,5 @@ export type QueryPublicParams<S extends Entity.AnyNoContext> = {
enabled: boolean;
// TODO: for multi-level nesting it should only allow the allowed properties instead of Record<string, Record<string, never>>
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
first?: number;
};
21 changes: 15 additions & 6 deletions packages/hypergraph-react/src/internal/use-query-public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -290,7 +295,7 @@ export const parseResult = <S extends Entity.AnyNoContext>(
};

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

Expand Down Expand Up @@ -327,6 +332,7 @@ export const useQueryPublic = <S extends Entity.AnyNoContext>(type: S, params?:
mappingEntry?.typeIds,
relationTypeIdsLevel1,
relationTypeIdsLevel2,
// TODO should `first` be in here?
Copy link

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

The first parameter should be included in the queryKey array to ensure cache entries vary by first value; add first after relationTypeIdsLevel2.

Suggested change
// TODO should `first` be in here?
first,

Copilot uses AI. Check for mistakes.

],
queryFn: async () => {
let queryDocument = entitiesQueryDocumentLevel0;
Expand All @@ -337,11 +343,14 @@ export const useQueryPublic = <S extends Entity.AnyNoContext>(type: S, params?:
queryDocument = entitiesQueryDocumentLevel2;
}

console.log('first', first);
Copy link

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

Remove this debug console.log statement to avoid noisy logs in production.

Suggested change
console.log('first', first);

Copilot uses AI. Check for mistakes.


const result = await request<EntityQueryResult>(GEO_API_TESTNET_ENDPOINT, queryDocument, {
spaceId: space,
typeIds: mappingEntry?.typeIds || [],
relationTypeIdsLevel1,
relationTypeIdsLevel2,
first,
});
return result;
},
Expand Down
5 changes: 3 additions & 2 deletions packages/hypergraph-react/src/use-query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type QueryParams<S extends Entity.AnyNoContext> = {
// TODO: for multi-level nesting it should only allow the allowed properties instead of Record<string, Record<string, never>>
include?: { [K in keyof Schema.Schema.Type<S>]?: Record<string, Record<string, never>> } | undefined;
space?: string;
first?: number;
};

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

export function useQuery<const S extends Entity.AnyNoContext>(type: S, params: QueryParams<S>) {
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');
Expand Down
Loading