diff --git a/.changeset/crazy-beans-spend.md b/.changeset/crazy-beans-spend.md new file mode 100644 index 00000000..7680e791 --- /dev/null +++ b/.changeset/crazy-beans-spend.md @@ -0,0 +1,45 @@ +--- +"@graphprotocol/hypergraph-react": patch +"@graphprotocol/hypergraph": patch +--- + +Extend Entity.Schema to allow querying for relation entity values + +In the following example we define a Project entity and a Podcast entity with the relation `projects` to the Project entity. In the Type.Relation you now can define the properties of the relation entity as a second argument. In the mapping you also need to define the properties of the relation entity instead of just the property id of the relation. + +```ts +export const Project = Entity.Schema( + { + name: Type.String, + }, + { + types: [Id('69732974-c632-490d-81a3-12ea567b2a8e')], + properties: { + name: Id('a126ca53-0c8e-48d5-b888-82c734c38935'), + }, + }, +); + +export const Podcast = Entity.Schema( + { + name: Type.String, + projects: Type.Relation(Project, { + properties: { + website: Type.optional(Type.String), + }, + }), + }, + { + types: [Id('69732974-c632-490d-81a3-12ea567b2a8e')], + properties: { + name: Id('a126ca53-0c8e-48d5-b888-82c734c38935'), + projects: { + propertyId: Id('71931b5f-1d6a-462e-81d9-5b8e85fb5c4b'), + properties: { + website: Id('eed38e74-e679-46bf-8a42-ea3e4f8fb5fb'), + }, + }, + }, + }, +); +``` \ No newline at end of file diff --git a/apps/events/src/routeTree.gen.ts b/apps/events/src/routeTree.gen.ts index de3d360a..fe31d430 100644 --- a/apps/events/src/routeTree.gen.ts +++ b/apps/events/src/routeTree.gen.ts @@ -23,9 +23,15 @@ import { Route as SpaceSpaceIdPlaygroundRouteImport } from './routes/space/$spac import { Route as SpaceSpaceIdEventsRouteImport } from './routes/space/$spaceId/events' import { Route as SpaceSpaceIdChatRouteImport } from './routes/space/$spaceId/chat' +const PodcastsLazyRouteImport = createFileRoute('/podcasts')() const PlaygroundLazyRouteImport = createFileRoute('/playground')() const LoginLazyRouteImport = createFileRoute('/login')() +const PodcastsLazyRoute = PodcastsLazyRouteImport.update({ + id: '/podcasts', + path: '/podcasts', + getParentRoute: () => rootRouteImport, +} as any).lazy(() => import('./routes/podcasts.lazy').then((d) => d.Route)) const PlaygroundLazyRoute = PlaygroundLazyRouteImport.update({ id: '/playground', path: '/playground', @@ -98,6 +104,7 @@ export interface FileRoutesByFullPath { '/authenticate-success': typeof AuthenticateSuccessRoute '/login': typeof LoginLazyRoute '/playground': typeof PlaygroundLazyRoute + '/podcasts': typeof PodcastsLazyRoute '/account-inbox/$inboxId': typeof AccountInboxInboxIdRoute '/friends/$accountAddress': typeof FriendsAccountAddressRoute '/space/$spaceId': typeof SpaceSpaceIdRouteWithChildren @@ -113,6 +120,7 @@ export interface FileRoutesByTo { '/authenticate-success': typeof AuthenticateSuccessRoute '/login': typeof LoginLazyRoute '/playground': typeof PlaygroundLazyRoute + '/podcasts': typeof PodcastsLazyRoute '/account-inbox/$inboxId': typeof AccountInboxInboxIdRoute '/friends/$accountAddress': typeof FriendsAccountAddressRoute '/space/$spaceId/chat': typeof SpaceSpaceIdChatRoute @@ -128,6 +136,7 @@ export interface FileRoutesById { '/authenticate-success': typeof AuthenticateSuccessRoute '/login': typeof LoginLazyRoute '/playground': typeof PlaygroundLazyRoute + '/podcasts': typeof PodcastsLazyRoute '/account-inbox/$inboxId': typeof AccountInboxInboxIdRoute '/friends/$accountAddress': typeof FriendsAccountAddressRoute '/space/$spaceId': typeof SpaceSpaceIdRouteWithChildren @@ -145,6 +154,7 @@ export interface FileRouteTypes { | '/authenticate-success' | '/login' | '/playground' + | '/podcasts' | '/account-inbox/$inboxId' | '/friends/$accountAddress' | '/space/$spaceId' @@ -160,6 +170,7 @@ export interface FileRouteTypes { | '/authenticate-success' | '/login' | '/playground' + | '/podcasts' | '/account-inbox/$inboxId' | '/friends/$accountAddress' | '/space/$spaceId/chat' @@ -174,6 +185,7 @@ export interface FileRouteTypes { | '/authenticate-success' | '/login' | '/playground' + | '/podcasts' | '/account-inbox/$inboxId' | '/friends/$accountAddress' | '/space/$spaceId' @@ -190,6 +202,7 @@ export interface RootRouteChildren { AuthenticateSuccessRoute: typeof AuthenticateSuccessRoute LoginLazyRoute: typeof LoginLazyRoute PlaygroundLazyRoute: typeof PlaygroundLazyRoute + PodcastsLazyRoute: typeof PodcastsLazyRoute AccountInboxInboxIdRoute: typeof AccountInboxInboxIdRoute FriendsAccountAddressRoute: typeof FriendsAccountAddressRoute SpaceSpaceIdRoute: typeof SpaceSpaceIdRouteWithChildren @@ -197,6 +210,13 @@ export interface RootRouteChildren { declare module '@tanstack/react-router' { interface FileRoutesByPath { + '/podcasts': { + id: '/podcasts' + path: '/podcasts' + fullPath: '/podcasts' + preLoaderRoute: typeof PodcastsLazyRouteImport + parentRoute: typeof rootRouteImport + } '/playground': { id: '/playground' path: '/playground' @@ -318,6 +338,7 @@ const rootRouteChildren: RootRouteChildren = { AuthenticateSuccessRoute: AuthenticateSuccessRoute, LoginLazyRoute: LoginLazyRoute, PlaygroundLazyRoute: PlaygroundLazyRoute, + PodcastsLazyRoute: PodcastsLazyRoute, AccountInboxInboxIdRoute: AccountInboxInboxIdRoute, FriendsAccountAddressRoute: FriendsAccountAddressRoute, SpaceSpaceIdRoute: SpaceSpaceIdRouteWithChildren, diff --git a/apps/events/src/routes/__root.tsx b/apps/events/src/routes/__root.tsx index 426949e4..ed2ee452 100644 --- a/apps/events/src/routes/__root.tsx +++ b/apps/events/src/routes/__root.tsx @@ -33,6 +33,9 @@ export const Route = createRootRoute({