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/plain-turkeys-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphprotocol/hypergraph-react": patch
"@graphprotocol/hypergraph": patch
---

add Type.Backlink

Comment on lines +6 to +7
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The changeset description is too brief and lacks proper capitalization. Consider providing a more descriptive message that explains what the change does, such as "Add Type.Backlink support for GraphQL alias per relation and backlinks".

Suggested change
add Type.Backlink
Add Type.Backlink support for GraphQL alias per relation and backlinks.

Copilot uses AI. Check for mistakes.
46 changes: 31 additions & 15 deletions apps/events/src/routes/podcasts.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Entity } from '@graphprotocol/hypergraph';
import { useEntities } from '@graphprotocol/hypergraph-react';
import { createLazyFileRoute } from '@tanstack/react-router';
import { useEffect } from 'react';
import { Podcast } from '@/schema';

export const Route = createLazyFileRoute('/podcasts')({
Expand All @@ -11,25 +9,43 @@ export const Route = createLazyFileRoute('/podcasts')({
function RouteComponent() {
const space = 'e252f9e1-d3ad-4460-8bf1-54f93b02f220';

useEffect(() => {
setTimeout(async () => {
const result = await Entity.findOnePublic(Podcast, {
id: 'f5d27d3e-3a51-452d-bac2-702574381633',
space: space,
include: {
listenOn: {},
},
});
console.log('findOnePublic result:', result);
}, 1000);
}, []);
// useEffect(() => {
// setTimeout(async () => {
// const result = await Entity.searchManyPublic(Podcast, {
// query: 'Joe',
// space: space,
// // include: {
// // listenOn: {},
// // },
// });
// console.log('searchManyPublic result:', result);
// }, 1000);
// }, []);

// const { data: podcast } = useEntity(Podcast, {
// id: 'f5d27d3e-3a51-452d-bac2-702574381633',
// mode: 'public',
// space: space,
// include: {
// listenOn: {},
// hosts: {
// avatar: {},
// },
// episodes: {},
// },
// });
// console.log({ podcast });

Comment on lines +12 to 38
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

Large blocks of commented-out code should be removed rather than left in the codebase. If this code is needed for reference, consider preserving it in git history or documentation instead.

Suggested change
// useEffect(() => {
// setTimeout(async () => {
// const result = await Entity.searchManyPublic(Podcast, {
// query: 'Joe',
// space: space,
// // include: {
// // listenOn: {},
// // },
// });
// console.log('searchManyPublic result:', result);
// }, 1000);
// }, []);
// const { data: podcast } = useEntity(Podcast, {
// id: 'f5d27d3e-3a51-452d-bac2-702574381633',
// mode: 'public',
// space: space,
// include: {
// listenOn: {},
// hosts: {
// avatar: {},
// },
// episodes: {},
// },
// });
// console.log({ podcast });

Copilot uses AI. Check for mistakes.
const { data, isLoading, isError } = useEntities(Podcast, {
mode: 'public',
first: 100,
first: 10,
space: space,
include: {
listenOn: {},
hosts: {
avatar: {},
},
episodes: {},
},
orderBy: { property: 'dateFounded', direction: 'asc' },
backlinksTotalCountsTypeId1: '972d201a-d780-4568-9e01-543f67b26bee',
Expand Down
35 changes: 35 additions & 0 deletions apps/events/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,39 @@ export const GenericEntity = Entity.Schema(
},
);

export const Episode2 = Entity.Schema(
{
name: Type.String,
description: Type.optional(Type.String),
airDate: Type.Date,
avatar: Type.Relation(Image),
duration: Type.optional(Type.Number), // in seconds
audioUrl: Type.optional(Type.String),
listenOn: Type.Relation(GenericEntity, {
properties: {
website: Type.optional(Type.String),
},
}),
},
{
types: [Id('972d201a-d780-4568-9e01-543f67b26bee')],
properties: {
name: Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
description: Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'),
airDate: Id('77999397-f78d-44a7-bbc5-d93a617af47c'),
duration: Id('76996acc-d10f-4cd5-9ac9-4a705b8e03b4'),
audioUrl: Id('87f919d5-560b-408c-be8d-318e2c5c098b'),
avatar: Id('1155beff-fad5-49b7-a2e0-da4777b8792c'),
listenOn: {
propertyId: Id('1367bac7-dcea-4b80-86ad-a4a4cdd7c2cb'),
properties: {
website: Id('eed38e74-e679-46bf-8a42-ea3e4f8fb5fb'),
},
},
},
},
);

export const Podcast = Entity.Schema(
{
name: Type.String,
Expand All @@ -176,6 +209,7 @@ export const Podcast = Entity.Schema(
website: Type.optional(Type.String),
},
}),
episodes: Type.Backlink(Episode2),
},
{
types: [Id('4c81561d-1f95-4131-9cdd-dd20ab831ba2')],
Expand All @@ -193,6 +227,7 @@ export const Podcast = Entity.Schema(
website: Id('eed38e74-e679-46bf-8a42-ea3e4f8fb5fb'),
},
},
episodes: Id('f1873bbc-381f-4604-abad-76fed4f6d73f'),
},
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Constants, Entity, Utils } from '@graphprotocol/hypergraph';
import { Constants, Entity } from '@graphprotocol/hypergraph';
import { useInfiniteQuery as useInfiniteQueryTanstack } from '@tanstack/react-query';
import * as Option from 'effect/Option';
import type * as Schema from 'effect/Schema';
Expand All @@ -13,24 +13,12 @@ export const useEntitiesPublicInfinite = <S extends Schema.Schema.AnyNoContext>(
const { enabled = true, filter, include, space: spaceFromParams, first = 2, offset = 0 } = params ?? {};
const { space: spaceFromContext } = useHypergraphSpaceInternal();
const space = spaceFromParams ?? spaceFromContext;

// constructing the relation type ids for the query
const relationTypeIds = Utils.getRelationTypeIds(type, include);

const typeIds = SchemaAST.getAnnotation<string[]>(Constants.TypeIdsSymbol)(type.ast as SchemaAST.TypeLiteral).pipe(
Option.getOrElse(() => []),
);

const result = useInfiniteQueryTanstack({
queryKey: [
'hypergraph-public-entities',
space,
typeIds,
relationTypeIds.level1,
relationTypeIds.level2,
filter,
'infinite',
],
queryKey: ['hypergraph-public-entities', space, typeIds, include, filter, 'infinite'],
queryFn: async ({ pageParam }) => {
return Entity.findManyPublic(type, { filter, include, space, first, offset: pageParam });
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Constants, Entity, Utils } from '@graphprotocol/hypergraph';
import { Constants, Entity } from '@graphprotocol/hypergraph';
import { useQuery as useQueryTanstack } from '@tanstack/react-query';
import * as Option from 'effect/Option';
import type * as Schema from 'effect/Schema';
Expand All @@ -19,10 +19,6 @@ export const useEntitiesPublic = <S extends Schema.Schema.AnyNoContext>(type: S,
} = params ?? {};
const { space: spaceFromContext } = useHypergraphSpaceInternal();
const space = spaceFromParams ?? spaceFromContext;

// constructing the relation type ids for the query
const relationTypeIds = Utils.getRelationTypeIds(type, include);

const typeIds = SchemaAST.getAnnotation<string[]>(Constants.TypeIdsSymbol)(type.ast as SchemaAST.TypeLiteral).pipe(
Option.getOrElse(() => []),
);
Expand All @@ -32,8 +28,7 @@ export const useEntitiesPublic = <S extends Schema.Schema.AnyNoContext>(type: S,
'hypergraph-public-entities',
space,
typeIds,
relationTypeIds.level1,
relationTypeIds.level2,
include,
filter,
first,
offset,
Expand Down
Loading
Loading