Skip to content

Commit 40def7a

Browse files
committed
integrate public queryies without relations
1 parent 4bbdc82 commit 40def7a

File tree

16 files changed

+260
-311
lines changed

16 files changed

+260
-311
lines changed

apps/events/src/components/playground.tsx

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
_useCreateEntityPublic,
3-
_useDeleteEntityPublic,
4-
useHypergraphApp,
5-
useQuery,
6-
useSpace,
7-
} from '@graphprotocol/hypergraph-react';
1+
import { _useDeleteEntityPublic, useHypergraphApp, useQuery, useSpace } from '@graphprotocol/hypergraph-react';
82
import { useState } from 'react';
93
import { Event } from '../schema';
104
import { Button } from './ui/button';
@@ -24,13 +18,11 @@ export const Playground = ({ spaceId }: { spaceId: string }) => {
2418
space: spaceId,
2519
});
2620
const [isDeleting, setIsDeleting] = useState(false);
27-
const [isCreating, setIsCreating] = useState(false);
2821
const { getSmartSessionClient } = useHypergraphApp();
2922

3023
const { name } = useSpace({ mode: 'public', space: spaceId });
3124

3225
const deleteEntity = _useDeleteEntityPublic(Event, { space: spaceId });
33-
const createEntity = _useCreateEntityPublic(Event, { space: spaceId });
3426

3527
console.log({ isLoading, isError, data });
3628

@@ -39,29 +31,6 @@ export const Playground = ({ spaceId }: { spaceId: string }) => {
3931
<h2 className="text-lg font-bold">Space: {name}</h2>
4032
{isLoading && <div>Loading...</div>}
4133
{isError && <div>Error</div>}
42-
<Button
43-
disabled={isCreating}
44-
onClick={async () => {
45-
setIsCreating(true);
46-
const walletClient = await getSmartSessionClient();
47-
if (!walletClient) {
48-
alert('Wallet client not found');
49-
setIsCreating(false);
50-
return;
51-
}
52-
const { success, cid, txResult } = await createEntity(
53-
{
54-
name: 'Test Event 42 by Nik',
55-
sponsors: [],
56-
},
57-
{ walletClient },
58-
);
59-
console.log('created', { success, cid, txResult });
60-
setIsCreating(false);
61-
}}
62-
>
63-
Create
64-
</Button>
6534
{data?.map((event) => (
6635
<div key={event.id}>
6736
<h2>{event.name}</h2>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useQuery } from '@graphprotocol/hypergraph-react';
2+
import { Project } from '../schema';
3+
4+
export const Projects = ({ spaceId }: { spaceId: string }) => {
5+
const { data, isLoading, isError } = useQuery(Project, {
6+
mode: 'public',
7+
// include: {
8+
// sponsors: {
9+
// jobOffers: {},
10+
// },
11+
// },
12+
// filter: {
13+
// or: [{ name: { startsWith: 'test' } }, { name: { startsWith: 'ETH' } }],
14+
// },
15+
first: 100,
16+
space: spaceId,
17+
});
18+
console.log({ isLoading, isError, data });
19+
20+
return (
21+
<div>
22+
<h2 className="text-lg font-bold">Projects</h2>
23+
{isLoading && <div>Loading...</div>}
24+
{isError && <div>Error</div>}
25+
{data?.map((project) => (
26+
<div key={project.id}>
27+
<h2>{project.name}</h2>
28+
<pre className="text-xs">{JSON.stringify(project, null, 2)}</pre>
29+
</div>
30+
))}
31+
</div>
32+
);
33+
};

apps/events/src/routes/playground.lazy.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { HypergraphSpaceProvider } from '@graphprotocol/hypergraph-react';
2-
import { createLazyFileRoute } from '@tanstack/react-router';
31
import { CreateEvents } from '@/components/create-events';
42
import { CreatePropertiesAndTypesEvent } from '@/components/create-properties-and-types-event';
5-
import { Event } from '@/components/event';
63
import { Playground } from '@/components/playground';
4+
import { Projects } from '@/components/projects';
5+
import { HypergraphSpaceProvider } from '@graphprotocol/hypergraph-react';
6+
import { createLazyFileRoute } from '@tanstack/react-router';
77

88
export const Route = createLazyFileRoute('/playground')({
99
component: RouteComponent,
@@ -13,8 +13,9 @@ function RouteComponent() {
1313
const space = 'a393e509-ae56-4d99-987c-bed71d9db631';
1414
return (
1515
<>
16-
<Event spaceId={space} entityId="cf7c620b-d724-498f-b134-8280dc8249ae" />
16+
{/* <Event spaceId={space} entityId="cf7c620b-d724-498f-b134-8280dc8249ae" /> */}
1717
<Playground spaceId={space} />
18+
<Projects spaceId="3f32353d-3b27-4a13-b71a-746f06e1f7db" />
1819
<HypergraphSpaceProvider space={space}>
1920
<div className="flex flex-col gap-4 max-w-(--breakpoint-sm) mx-auto py-8">
2021
<h1 className="text-2xl font-bold">Playground</h1>

apps/events/src/schema.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,33 @@ export const Event = EntitySchema(
9393
},
9494
},
9595
);
96+
97+
export const Image = EntitySchema(
98+
{
99+
url: Type.String,
100+
},
101+
{
102+
types: [Id('ba4e4146-0010-499d-a0a3-caaa7f579d0e')],
103+
properties: {
104+
url: Id('8a743832-c094-4a62-b665-0c3cc2f9c7bc'),
105+
},
106+
},
107+
);
108+
109+
export const Project = EntitySchema(
110+
{
111+
name: Type.String,
112+
description: Type.optional(Type.String),
113+
x: Type.optional(Type.String),
114+
// avatar: Type.Relation(Image),
115+
},
116+
{
117+
types: [Id('484a18c5-030a-499c-b0f2-ef588ff16d50')],
118+
properties: {
119+
name: Id('a126ca53-0c8e-48d5-b888-82c734c38935'),
120+
description: Id('9b1f76ff-9711-404c-861e-59dc3fa7d037'),
121+
x: Id('0d625978-4b3c-4b57-a86f-de45c997c73c'),
122+
// avatar: Id('1155beff-fad5-49b7-a2e0-da4777b8792c'),
123+
},
124+
},
125+
);

apps/privy-login-example/src/components/playground.tsx

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
_useCreateEntityPublic,
3-
_useDeleteEntityPublic,
4-
useHypergraphApp,
5-
useQuery,
6-
useSpace,
7-
} from '@graphprotocol/hypergraph-react';
1+
import { _useDeleteEntityPublic, useHypergraphApp, useQuery, useSpace } from '@graphprotocol/hypergraph-react';
82
import { useState } from 'react';
93
import { Event } from '../schema';
104
import { Button } from './ui/button';
@@ -24,13 +18,11 @@ export const Playground = ({ spaceId }: { spaceId: string }) => {
2418
space: spaceId,
2519
});
2620
const [isDeleting, setIsDeleting] = useState(false);
27-
const [isCreating, setIsCreating] = useState(false);
2821
const { getSmartSessionClient } = useHypergraphApp();
2922

3023
const { name } = useSpace({ mode: 'public', space: spaceId });
3124

3225
const deleteEntity = _useDeleteEntityPublic(Event, { space: spaceId });
33-
const createEntity = _useCreateEntityPublic(Event, { space: spaceId });
3426

3527
console.log({ isLoading, isError, data });
3628

@@ -39,29 +31,6 @@ export const Playground = ({ spaceId }: { spaceId: string }) => {
3931
<h2 className="text-lg font-bold">Space: {name}</h2>
4032
{isLoading && <div>Loading...</div>}
4133
{isError && <div>Error</div>}
42-
<Button
43-
disabled={isCreating}
44-
onClick={async () => {
45-
setIsCreating(true);
46-
const walletClient = await getSmartSessionClient();
47-
if (!walletClient) {
48-
alert('Wallet client not found');
49-
setIsCreating(false);
50-
return;
51-
}
52-
const { success, cid, txResult } = await createEntity(
53-
{
54-
name: 'Test Event 42 by Nik',
55-
sponsors: [],
56-
},
57-
{ walletClient },
58-
);
59-
console.log('created', { success, cid, txResult });
60-
setIsCreating(false);
61-
}}
62-
>
63-
Create
64-
</Button>
6534
{data?.map((event) => (
6635
<div key={event.id}>
6736
<h2>{event.name}</h2>

packages/hypergraph-react/src/HypergraphAppContext.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use client';
22

3-
import { automergeWasmBase64 } from '@automerge/automerge/automerge.wasm.base64';
4-
import * as automerge from '@automerge/automerge/slim';
53
import type { DocHandle } from '@automerge/automerge-repo';
6-
import { Repo } from '@automerge/automerge-repo/slim';
74
import { RepoContext } from '@automerge/automerge-repo-react-hooks';
5+
import { Repo } from '@automerge/automerge-repo/slim';
6+
import { automergeWasmBase64 } from '@automerge/automerge/automerge.wasm.base64';
7+
import * as automerge from '@automerge/automerge/slim';
88
import { Graph } from '@graphprotocol/grc-20';
99
import {
1010
Connect,
@@ -250,9 +250,6 @@ export function HypergraphAppProvider({
250250
const identity = useSelectorStore(store, (state) => state.context.identity);
251251
const privyIdentity = useSelectorStore(store, (state) => state.context.privyIdentity);
252252

253-
console.log('identity', identity);
254-
console.log('privyIdentity', privyIdentity);
255-
256253
const logout = useCallback(() => {
257254
websocketConnection?.close();
258255
setWebsocketConnection(undefined);

packages/hypergraph-react/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export {
2424
} from './HypergraphAppContext.js';
2525
export { HypergraphSpaceProvider } from './HypergraphSpaceContext.js';
2626
export { generateDeleteOps as _generateDeleteOps } from './internal/generate-delete-ops.js';
27-
export { useCreateEntityPublic as _useCreateEntityPublic } from './internal/use-create-entity-public.js';
2827
export { useDeleteEntityPublic as _useDeleteEntityPublic } from './internal/use-delete-entity-public.js';
2928
export { useEntityPublic as _useEntityPublic } from './internal/use-entity-public.js';
3029
export { useQueryPrivate as _useQueryPrivate } from './internal/use-query-private.js';
Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
import { TypeUtils } from '@graphprotocol/hypergraph';
2-
import type * as Schema from 'effect/Schema';
1+
import { PropertyTypeSymbol } from '@graphprotocol/hypergraph/constants';
2+
import * as Option from 'effect/Option';
3+
import * as SchemaAST from 'effect/SchemaAST';
34

45
export const convertPropertyValue = (
56
property: { propertyId: string; string: string; boolean: boolean; number: number; time: string; point: string },
6-
key: string,
7-
type: Schema.Schema.AnyNoContext,
7+
type: SchemaAST.AST,
88
) => {
9-
if (TypeUtils.isBooleanOrOptionalBooleanType(type.fields[key]) && property.boolean !== undefined) {
10-
return Boolean(property.boolean);
9+
const propertyType = SchemaAST.getAnnotation<string>(PropertyTypeSymbol)(type);
10+
if (Option.isSome(propertyType)) {
11+
if (propertyType.value === 'string') {
12+
return property.string;
13+
}
14+
if (propertyType.value === 'boolean') {
15+
return Boolean(property.boolean);
16+
}
17+
if (propertyType.value === 'point') {
18+
return property.point;
19+
}
20+
if (propertyType.value === 'number') {
21+
return Number(property.number);
22+
}
23+
if (propertyType.value === 'date') {
24+
return property.time;
25+
}
1126
}
12-
if (TypeUtils.isPointOrOptionalPointType(type.fields[key]) && property.point !== undefined) {
13-
return property.point;
14-
}
15-
if (TypeUtils.isDateOrOptionalDateType(type.fields[key]) && property.time !== undefined) {
16-
return property.time;
17-
}
18-
if (TypeUtils.isNumberOrOptionalNumberType(type.fields[key]) && property.number !== undefined) {
19-
return Number(property.number);
20-
}
21-
return property.string;
2227
};

packages/hypergraph-react/src/internal/convert-relations.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Mapping } from '@graphprotocol/hypergraph';
21
import type * as Schema from 'effect/Schema';
32
import { convertPropertyValue } from './convert-property-value.js';
43

@@ -23,12 +22,7 @@ type RecursiveQueryEntity = {
2322
}[];
2423
};
2524

26-
export const convertRelations = <S extends Schema.Schema.AnyNoContext>(
27-
queryEntity: RecursiveQueryEntity,
28-
type: S,
29-
mappingEntry: Mapping.MappingEntry,
30-
mapping: Mapping.Mapping,
31-
) => {
25+
export const convertRelations = <S extends Schema.Schema.AnyNoContext>(queryEntity: RecursiveQueryEntity, type: S) => {
3226
const rawEntity: Record<string, string | boolean | number | unknown[] | Date> = {};
3327

3428
for (const [key, relationId] of Object.entries(mappingEntry?.relations ?? {})) {

0 commit comments

Comments
 (0)