Skip to content

Commit 8a09ffd

Browse files
authored
fix useSpaces and Space.findManyPublic for new API (#578)
1 parent 4dd8ce3 commit 8a09ffd

7 files changed

Lines changed: 54 additions & 24 deletions

File tree

.changeset/eighty-hornets-kiss.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@graphprotocol/hypergraph-react": patch
3+
"@graphprotocol/hypergraph": patch
4+
---
5+
6+
fix useSpaces and Space.findManyPublic for new API
7+

apps/events/src/Boot.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ declare module '@tanstack/react-router' {
1414

1515
export function Boot() {
1616
return (
17-
<HypergraphAppProvider syncServerUri="http://localhost:3030" appId="93bb8907085a4a0e83dd62b0dc98e793">
17+
<HypergraphAppProvider
18+
syncServerUri="http://localhost:3030"
19+
appId="93bb8907085a4a0e83dd62b0dc98e793"
20+
apiOrigin="https://testnet-api.geobrowser.io"
21+
>
1822
<RouterProvider router={router} />
1923
</HypergraphAppProvider>
2024
);

apps/events/src/routes/index.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { store } from '@graphprotocol/hypergraph';
2-
import { useHypergraphApp, useSpaces } from '@graphprotocol/hypergraph-react';
2+
import { useHypergraphApp, usePublicSpaces, useSpaces } from '@graphprotocol/hypergraph-react';
33
import { createFileRoute, Link } from '@tanstack/react-router';
44
import { useSelector } from '@xstate/store/react';
55
import { useEffect, useState } from 'react';
@@ -17,6 +17,13 @@ window.HYPERGRAPH_STORE = store;
1717
function Index() {
1818
const { data: publicSpaces } = useSpaces({ mode: 'public' });
1919
const { data: privateSpaces } = useSpaces({ mode: 'private' });
20+
21+
const { data: publicSpaces2, invalidSpaces } = usePublicSpaces({
22+
filter: { editorId: 'b0043a26-cb81-379c-1217-dfd2283b67b8' },
23+
});
24+
25+
console.log({ invalidSpaces });
26+
2027
const [spaceName, setSpaceName] = useState('');
2128

2229
const accountInboxes = useSelector(store, (state) => state.context.accountInboxes);
@@ -124,6 +131,18 @@ function Index() {
124131
</li>
125132
);
126133
})}
134+
v2
135+
{publicSpaces2?.map((space) => {
136+
return (
137+
<li key={space.id}>
138+
<Card>
139+
<CardHeader>
140+
<CardTitle>{space.name}</CardTitle>
141+
</CardHeader>
142+
</Card>
143+
</li>
144+
);
145+
})}
127146
</ul>
128147

129148
<div className="flex flex-col gap-2">

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function RouteComponent() {
117117
console.log({ topics });
118118

119119
const { data: spaces } = usePublicSpaces({
120-
filter: { memberAccountAddress: '0xE86b4a182779ae6320cA04ad43Fe6a1bed051e24' },
120+
filter: { memberId: 'cbbb9a68568e4e88938080ad0706f365' },
121121
});
122122
console.log('spaces', spaces);
123123

docs/docs/query-public-data.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ When you only need the list of public spaces (with optional avatar metadata) you
1212
import { usePublicSpaces } from '@graphprotocol/hypergraph-react';
1313

1414
const { data: spaces, invalidSpaces, isPending } = usePublicSpaces({
15-
filter: { editorAccountAddress: '0x1234...' },
15+
filter: { editorId: '0x1234...' },
1616
});
1717
```
1818

@@ -30,11 +30,11 @@ You can restrict the result set to spaces where a given account is a member or a
3030

3131
```ts
3232
await Space.findManyPublic({
33-
filter: { memberAccountAddress: '0x1234...' },
33+
filter: { memberId: '23kd4...' },
3434
});
3535

3636
await Space.findManyPublic({
37-
filter: { editorAccountAddress: '0x1234...' },
37+
filter: { editorId: '23kd4...' },
3838
});
3939
```
4040

packages/hypergraph-react/src/hooks/use-spaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { useEffect } from 'react';
66
import { useHypergraphApp } from '../HypergraphAppContext.js';
77

88
const publicSpacesQueryDocument = gql`
9-
query Spaces($accountAddress: String!) {
10-
spaces(filter: {members: {some: {address: {is: $accountAddress}}}}) {
9+
query Spaces($memberId: UUID!) {
10+
spaces(filter: {members: {some: {memberSpaceId: {is: $memberId}}}}) {
1111
id
1212
page {
1313
name

packages/hypergraph/src/space/find-many-public.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ query spaces {
3232
`;
3333

3434
const memberSpacesQueryDocument = `
35-
query memberSpaces($accountAddress: String!) {
36-
spaces(filter: {members: {some: {address: {is: $accountAddress}}}}) {
35+
query memberSpaces($accountId: UUID!) {
36+
spaces(filter: {members: {some: {memberSpaceId: {is: $accountId}}}}) {
3737
${spaceFields}
3838
}
3939
}
4040
`;
4141

4242
const editorSpacesQueryDocument = `
43-
query editorSpaces($accountAddress: String!) {
44-
spaces(filter: {editors: {some: {address: {is: $accountAddress}}}}) {
43+
query editorSpaces($accountId: UUID!) {
44+
spaces(filter: {editors: {some: {memberSpaceId: {is: $accountId}}}}) {
4545
${spaceFields}
4646
}
4747
}
@@ -73,7 +73,7 @@ type SpacesQueryResult = {
7373
};
7474

7575
type SpacesQueryVariables = {
76-
accountAddress: string;
76+
accountId: string;
7777
};
7878

7979
type SpaceQueryEntry = NonNullable<SpacesQueryResult['spaces']>[number];
@@ -115,35 +115,35 @@ export const parseSpacesQueryResult = (queryResult: SpacesQueryResult) => {
115115
};
116116

117117
export type FindManyPublicFilter =
118-
| Readonly<{ memberAccountAddress: string; editorAccountAddress?: never }>
119-
| Readonly<{ editorAccountAddress: string; memberAccountAddress?: never }>
120-
| Readonly<{ memberAccountAddress?: undefined; editorAccountAddress?: undefined }>;
118+
| Readonly<{ memberId: string; editorId?: never }>
119+
| Readonly<{ editorId: string; memberId?: never }>
120+
| Readonly<{ memberId?: undefined; editorId?: undefined }>;
121121

122122
export type FindManyPublicParams = Readonly<{
123123
filter?: FindManyPublicFilter;
124124
}>;
125125

126126
export const findManyPublic = async (params?: FindManyPublicParams) => {
127127
const filter = params?.filter;
128-
const memberAccountAddress = filter?.memberAccountAddress;
129-
const editorAccountAddress = filter?.editorAccountAddress;
128+
const memberId = filter?.memberId;
129+
const editorId = filter?.editorId;
130130

131-
if (memberAccountAddress && editorAccountAddress) {
132-
throw new Error('Provide only one of memberAccountAddress or editorAccountAddress when calling findManyPublic().');
131+
if (memberId && editorId) {
132+
throw new Error('Provide only one of memberId or editorId when calling findManyPublic().');
133133
}
134134

135135
const endpoint = `${Config.getApiOrigin()}/v2/graphql`;
136136

137-
if (memberAccountAddress) {
137+
if (memberId) {
138138
const queryResult = await request<SpacesQueryResult, SpacesQueryVariables>(endpoint, memberSpacesQueryDocument, {
139-
accountAddress: memberAccountAddress,
139+
accountId: memberId,
140140
});
141141
return parseSpacesQueryResult(queryResult);
142142
}
143143

144-
if (editorAccountAddress) {
144+
if (editorId) {
145145
const queryResult = await request<SpacesQueryResult, SpacesQueryVariables>(endpoint, editorSpacesQueryDocument, {
146-
accountAddress: editorAccountAddress,
146+
accountId: editorId,
147147
});
148148
return parseSpacesQueryResult(queryResult);
149149
}

0 commit comments

Comments
 (0)