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

fix useSpaces and Space.findManyPublic for new API

6 changes: 5 additions & 1 deletion apps/events/src/Boot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ declare module '@tanstack/react-router' {

export function Boot() {
return (
<HypergraphAppProvider syncServerUri="http://localhost:3030" appId="93bb8907085a4a0e83dd62b0dc98e793">
<HypergraphAppProvider
syncServerUri="http://localhost:3030"
appId="93bb8907085a4a0e83dd62b0dc98e793"
apiOrigin="https://testnet-api.geobrowser.io"
>
<RouterProvider router={router} />
</HypergraphAppProvider>
);
Expand Down
21 changes: 20 additions & 1 deletion apps/events/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { store } from '@graphprotocol/hypergraph';
import { useHypergraphApp, useSpaces } from '@graphprotocol/hypergraph-react';
import { useHypergraphApp, usePublicSpaces, useSpaces } from '@graphprotocol/hypergraph-react';
import { createFileRoute, Link } from '@tanstack/react-router';
import { useSelector } from '@xstate/store/react';
import { useEffect, useState } from 'react';
Expand All @@ -17,6 +17,13 @@ window.HYPERGRAPH_STORE = store;
function Index() {
const { data: publicSpaces } = useSpaces({ mode: 'public' });
const { data: privateSpaces } = useSpaces({ mode: 'private' });

const { data: publicSpaces2, invalidSpaces } = usePublicSpaces({
filter: { editorId: 'b0043a26-cb81-379c-1217-dfd2283b67b8' },
});

console.log({ invalidSpaces });

const [spaceName, setSpaceName] = useState('');

const accountInboxes = useSelector(store, (state) => state.context.accountInboxes);
Expand Down Expand Up @@ -124,6 +131,18 @@ function Index() {
</li>
);
})}
v2
{publicSpaces2?.map((space) => {
return (
<li key={space.id}>
<Card>
<CardHeader>
<CardTitle>{space.name}</CardTitle>
</CardHeader>
</Card>
</li>
);
})}
</ul>

<div className="flex flex-col gap-2">
Expand Down
2 changes: 1 addition & 1 deletion apps/events/src/routes/podcasts.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function RouteComponent() {
console.log({ topics });

const { data: spaces } = usePublicSpaces({
filter: { memberAccountAddress: '0xE86b4a182779ae6320cA04ad43Fe6a1bed051e24' },
filter: { memberId: 'cbbb9a68568e4e88938080ad0706f365' },
});
console.log('spaces', spaces);

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/query-public-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ When you only need the list of public spaces (with optional avatar metadata) you
import { usePublicSpaces } from '@graphprotocol/hypergraph-react';

const { data: spaces, invalidSpaces, isPending } = usePublicSpaces({
filter: { editorAccountAddress: '0x1234...' },
filter: { editorId: '0x1234...' },
});
```

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

```ts
await Space.findManyPublic({
filter: { memberAccountAddress: '0x1234...' },
filter: { memberId: '23kd4...' },
});

await Space.findManyPublic({
filter: { editorAccountAddress: '0x1234...' },
filter: { editorId: '23kd4...' },
});
```

Expand Down
4 changes: 2 additions & 2 deletions packages/hypergraph-react/src/hooks/use-spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { useEffect } from 'react';
import { useHypergraphApp } from '../HypergraphAppContext.js';

const publicSpacesQueryDocument = gql`
query Spaces($accountAddress: String!) {
spaces(filter: {members: {some: {address: {is: $accountAddress}}}}) {
query Spaces($memberId: UUID!) {
spaces(filter: {members: {some: {memberSpaceId: {is: $memberId}}}}) {
id
page {
name
Expand Down
32 changes: 16 additions & 16 deletions packages/hypergraph/src/space/find-many-public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ query spaces {
`;

const memberSpacesQueryDocument = `
query memberSpaces($accountAddress: String!) {
spaces(filter: {members: {some: {address: {is: $accountAddress}}}}) {
query memberSpaces($accountId: UUID!) {
spaces(filter: {members: {some: {memberSpaceId: {is: $accountId}}}}) {
${spaceFields}
}
}
`;

const editorSpacesQueryDocument = `
query editorSpaces($accountAddress: String!) {
spaces(filter: {editors: {some: {address: {is: $accountAddress}}}}) {
query editorSpaces($accountId: UUID!) {
spaces(filter: {editors: {some: {memberSpaceId: {is: $accountId}}}}) {
${spaceFields}
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ type SpacesQueryResult = {
};

type SpacesQueryVariables = {
accountAddress: string;
accountId: string;
};

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

export type FindManyPublicFilter =
| Readonly<{ memberAccountAddress: string; editorAccountAddress?: never }>
| Readonly<{ editorAccountAddress: string; memberAccountAddress?: never }>
| Readonly<{ memberAccountAddress?: undefined; editorAccountAddress?: undefined }>;
| Readonly<{ memberId: string; editorId?: never }>
| Readonly<{ editorId: string; memberId?: never }>
| Readonly<{ memberId?: undefined; editorId?: undefined }>;

export type FindManyPublicParams = Readonly<{
filter?: FindManyPublicFilter;
}>;

export const findManyPublic = async (params?: FindManyPublicParams) => {
const filter = params?.filter;
const memberAccountAddress = filter?.memberAccountAddress;
const editorAccountAddress = filter?.editorAccountAddress;
const memberId = filter?.memberId;
const editorId = filter?.editorId;

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

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

if (memberAccountAddress) {
if (memberId) {
const queryResult = await request<SpacesQueryResult, SpacesQueryVariables>(endpoint, memberSpacesQueryDocument, {
accountAddress: memberAccountAddress,
accountId: memberId,
});
return parseSpacesQueryResult(queryResult);
}

if (editorAccountAddress) {
if (editorId) {
const queryResult = await request<SpacesQueryResult, SpacesQueryVariables>(endpoint, editorSpacesQueryDocument, {
accountAddress: editorAccountAddress,
accountId: editorId,
});
return parseSpacesQueryResult(queryResult);
}
Expand Down
Loading