Skip to content

Commit 7607e7c

Browse files
committed
improve publish data docs
1 parent 87b75ad commit 7607e7c

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

docs/docs/publishing-public-data.md

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
Once you want to share your data with the world you need to publish it. This is done by creating the necessary `Opertations` (Ops) and then publishing them.
44

5+
There are two functions to help you with this:
6+
7+
- `preparePublish` - creates the necessary `Operations` to publish the data
8+
- `publishOps` - publishes the `Operations` to the public space
9+
10+
You can generate the Ops for multiple entities and publish them in one go by concatenating the `ops` arrays.
11+
512
## Prepare Publish
613

714
Based on entity Ids, the source space and the target space this function calculates the necessary `Operations` to publish the data.
@@ -17,42 +24,32 @@ const { ops } = preparePublish({
1724

1825
The entity can come from a `useCreateEntity` result or from a `useQuery` result e.g.
1926

20-
```tsx
21-
const MyComponent = () => {
22-
const { data: events } = useQuery(Event, { mode: "private" });
27+
## Publish
2328

24-
const createOpsForPublishing = async (event) => {
25-
const { ops } = preparePublish({
26-
entity: event,
27-
publicSpace: "public-space-id",
28-
});
29-
};
29+
The `publishOps` function is used to publish the changes to the public space.
3030

31-
return (
32-
<div>
33-
{events.map((event) => (
34-
<button key={event.id} onClick={() => createOpsForPublishing(event)}>
35-
{event.name}
36-
</button>
37-
))}
38-
</div>
39-
);
40-
};
41-
```
31+
```tsx
32+
import { publishOps } from "@graphprotocol/hypergraph-react";
4233

43-
## Publish
34+
const { result } = publishOps({
35+
ops,
36+
walletClient: smartSessionClient,
37+
space: publicSpaceId,
38+
name: "Create Event", // description which can be any string
39+
});
40+
```
4441

45-
The `publishOps` function is used to publish the changes to the public space. Here is a full example flow:
42+
Here is a full example flow:
4643

4744
```tsx
48-
import { publishOps } from "@graphprotocol/hypergraph-react";
45+
import { publishOps, useHypergraphApp } from "@graphprotocol/hypergraph-react";
4946

50-
const MyComponent = () => {
47+
const MyComponent = ({ publicSpaceId }: { publicSpaceId: string }) => {
5148
const { getSmartSessionClient } = useHypergraphApp();
49+
const { data: events } = useQuery(Event, { mode: "private" });
5250

53-
const publishChanges = async () => {
51+
const publishEvent = async (entity) => {
5452
const smartSessionClient = await getSmartSessionClient();
55-
const publicSpaceId = "public-space-id";
5653

5754
const { ops } = preparePublish({
5855
entity: entity,
@@ -63,9 +60,19 @@ const MyComponent = () => {
6360
ops,
6461
walletClient: smartSessionClient,
6562
space: publicSpaceId,
66-
name: "Create Job Offers",
63+
name: "Create Event",
6764
});
6865
};
66+
67+
return (
68+
<div>
69+
{events.map((event) => (
70+
<button key={event.id} onClick={() => publishEvent(event)}>
71+
{event.name}
72+
</button>
73+
))}
74+
</div>
75+
);
6976
};
7077
```
7178

0 commit comments

Comments
 (0)