Skip to content

Commit 00d3047

Browse files
authored
update docs (#293)
1 parent 2c1fad8 commit 00d3047

File tree

6 files changed

+107
-90
lines changed

6 files changed

+107
-90
lines changed

docs/docs/intro.md

Lines changed: 0 additions & 47 deletions
This file was deleted.

docs/docs/providers.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,40 @@ It has one mandatory prop: `mapping`. This is the mapping of your schema to the
2020

2121
Further it has an optional prop: `syncServerUri`. This is the URL of the sync server. By default it is set to `https://hypergraph.fly.dev`.
2222

23+
## useHypergraphApp
24+
25+
The `useHypergraphApp` is available inside the `HypergraphAppProvider` and manages the sync server connection and provides serveral useful functions.
26+
27+
```tsx
28+
import { useHypergraphApp } from "@graphprotocol/hypergraph-react";
29+
30+
const App = () => {
31+
const { isConnected, logout } = useHypergraphApp();
32+
return <div>{isConnecting ? "Connecting..."}</div>;
33+
};
34+
```
35+
36+
- `isConnected` is a boolean that indicates that syncing private spaces is not yet possible. You need to wait until it's `false` to query data from private spaces.
37+
- `logout` is a function that logs out the user.
38+
39+
There are serveral more that will be explained in the following sections.
40+
41+
## useHypergraphAuth
42+
43+
The `useHypergraphAuth` is available inside the `HypergraphAppProvider` and manages the authentication state and provides serveral useful functions.
44+
45+
```tsx
46+
import { useHypergraphAuth } from "@graphprotocol/hypergraph-react";
47+
48+
const App = () => {
49+
const { authenticated, identity } = useHypergraphAuth();
50+
return <div>{authenticated ? "Authenticated" : "Not authenticated"}</div>;
51+
};
52+
```
53+
54+
- `authenticated` is a boolean that indicates if the user is authenticated.
55+
- `identity` is the identity of the logged in user.
56+
2357
## HypergraphSpaceProvider
2458
2559
Whenever interact with a space you need to provide the space ID. In order providing the space ID to every hook e.g. useSpace, useQuery, useCreateEntity, etc. you can use the `HypergraphSpaceProvider` to wrap a section of your app with the space ID.
@@ -45,3 +79,4 @@ const SpaceDetails = () => {
4579
```
4680
4781
The `space` prop is the ID of the space. It can be a private or public space.
82+

docs/docs/publishing-public-data.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,69 @@
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-
## Prepare Publish (not yet supported)
5+
## Prepare Publish
66

77
Based on entity Ids, the source space and the target space this function calculates the necessary `Operations` to publish the data.
88

99
```tsx
1010
import { preparePublish } from "@graphprotocol/hypergraph-react";
1111

12-
const { ops, diff } = preparePublish({
13-
entityIds: ["entity-id-1", "entity-id-2"],
14-
privateSourceSpace: "private-source-space-id",
15-
publicTargetSpace: "public-target-space-id",
12+
const { ops } = preparePublish({
13+
entity: entity,
14+
publicSpace: "public-space-id",
1615
});
1716
```
1817

19-
## Publishing Relations
18+
The entity can come from a `useCreateEntity` result or from a `useQuery` result e.g.
2019

2120
```tsx
22-
import { publishOps } from '@graphprotocol/hypergraph-react';
21+
const MyComponent = () => {
22+
const { data: events } = useQuery(Event, { mode: "private" });
23+
24+
const createOpsForPublishing = async (event) => {
25+
const { ops } = preparePublish({
26+
entity: event,
27+
publicSpace: "public-space-id",
28+
});
29+
};
30+
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+
```
42+
43+
## Publish
44+
45+
The `publishOps` function is used to publish the changes to the public space. Here is a full example flow:
46+
47+
```tsx
48+
import { publishOps } from "@graphprotocol/hypergraph-react";
2349

2450
const MyComponent = () => {
2551
const { getSmartSessionClient } = useHypergraphApp();
2652

2753
const publishChanges = async () => {
2854
const smartSessionClient = await getSmartSessionClient();
55+
const publicSpaceId = "public-space-id";
2956

30-
const ops = […];
57+
const { ops } = preparePublish({
58+
entity: entity,
59+
publicSpace: publicSpaceId,
60+
});
3161

3262
const result = await publishOps({
3363
ops,
3464
walletClient: smartSessionClient,
35-
space,
36-
name: 'Create Job Offers',
65+
space: publicSpaceId,
66+
name: "Create Job Offers",
3767
});
38-
}
39-
}
68+
};
69+
};
4070
```

docs/docs/query-private-data.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ useQuery for private data returns:
5151

5252
- data - a list of entities defined in your schema
5353
- invalidEntities - a list of entities that are in your space storage with correct type, but can't be parsed to your schema
54+
- deleted - a list of entities that are marked as deleted, we keep them around to be able to later be able to publish the deleted information to the public knowledge graph
5455

5556
```ts
56-
const { data, invalidEntities } = useQuery(Event, { mode: 'private' });
57+
const { data, invalidEntities, deleted } = useQuery(Event, { mode: 'private' });
5758
```

docs/docs/quickstart.md

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ version: 0.0.1
55
tags: [quickstart, typesync]
66
---
77

8-
# 🚀 Quickstart: An existing example app
8+
# 🚀 Quickstart
9+
10+
If you just want to get started and get a feel for how Hypergraph works, we have created an example app that you can clone and use as a starting point.
11+
12+
## Explore the Example app
913

1014
In order to get started as fast as possible we have created an example app that you can clone and use as a starting point.
1115

@@ -18,65 +22,59 @@ pnpm dev
1822

1923
Open the browser, navigate to `http://localhost:5173` and you should see the app running.
2024

21-
# 🚀 Quickstart: Your First Hypergraph App
25+
## Create a new app using TypeSync
2226

23-
In case you want to define your own schema and mapping you can follow the guide below.
27+
In case you want build an app with your own data types you can follow the guide below.
2428

2529
It will walk you through creating a new, fully-functional React application powered by Hypergraph using our scaffolding tool, **TypeSync**. In just a few minutes, you'll have a local development environment up and running.
2630

27-
This approach is perfect for developers who want to quickly build an application on top of Hypergraph without needing to set up the entire monorepo infrastructure.
28-
29-
## Prerequisites
31+
### Prerequisites
3032

3133
- Node.js >= 22
3234
- pnpm >= 10 (install with `npm install -g pnpm`)
3335

34-
## 1. Get the Hypergraph Toolkit
36+
### 1. Install the Hypergraph CLI
3537

3638
First, clone the Hypergraph repository, which contains TypeSync.
3739

3840
```bash
39-
git clone https://github.com/graphprotocol/hypergraph.git
40-
cd hypergraph
41+
npm install -g @graphprotocol/hypergraph-cli@latest
4142
```
4243

43-
Next, install dependencies and build the required packages. This step ensures that TypeSync and all its components are ready to use.
44+
When using `pnpm` you need to v10 or higher
4445

4546
```bash
46-
pnpm install
47-
pnpm build
47+
pnpm install -g @graphprotocol/hypergraph-cli@latest
48+
pnpm approve-builds -g
49+
# select @tailwindcss/oxide, better-sqlite3, and esbuild
4850
```
4951

50-
## 2. Launch TypeSync
51-
52-
TypeSync is a visual tool that helps you define your data schema and then generates a complete starter application based on your design.
52+
### 2. Launch TypeSync
5353

54-
Navigate to the `typesync` app and start its development server:
54+
TypeSync is a visual tool that helps you define your data schema and then generates a complete starter application based on your design. Launch it with
5555

5656
```bash
57-
cd apps/typesync
58-
pnpm dev
57+
hg typesync --open
5958
```
6059

61-
This will start the TypeSync server. You can now access the **TypeSync Studio** in your browser at `http://localhost:4000`.
60+
This will start the TypeSync server. You can now access the **TypeSync** app in your browser at `http://localhost:3000`.
6261

63-
## 3. Scaffold Your Application
62+
### 3. Scaffold Your Application
6463

6564
In the TypeSync Studio:
6665

6766
1. Give your new application a name and a short description.
68-
2. Use the visual editor to define your data models (we call them "types"). For example, you could create a `Post` type with a `title` (Text) and `content` (Text) properties.
67+
2. Use the visual editor to define your data models (we call them "types"). For example, you could create a `Post` type with a `name` (Text) and `content` (Text) properties.
6968
3. When you're ready, click "Generate App".
7069

71-
TypeSync will create a new directory for your application (e.g., `./my-awesome-app`) within the `hypergraph` monorepo, containing all the files and dependencies you need.
70+
TypeSync will create a new directory for your application (e.g., `./my-awesome-app`) containing all the files and dependencies you need.
7271

73-
## 4. Run Your New App
72+
### 4. Run Your New App
7473

7574
Once your app is generated, open a **new terminal tab**. Navigate into the newly created app directory, install its dependencies, and start the local development server.
7675

7776
```bash
78-
# In a new terminal, from the `hypergraph/apps/typesync` directory
79-
cd ../../my-awesome-app # Adjust the path to match your app's name
77+
cd ./my-awesome-app # Adjust the path to match your app's name
8078
pnpm install
8179
pnpm dev
8280
```
@@ -87,7 +85,7 @@ You're all set! You can now start building your application by editing the files
8785

8886
---
8987

90-
### Edit on GitHub :bust_in_silhouette:
88+
## Edit on GitHub :bust_in_silhouette:
9189

9290
[✏️ Improve this page](https://github.com/graphprotocol/hypergraph/edit/main/docs/docs/quickstart.md)
9391

docs/docusaurus.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ const config = {
103103
title: 'Docs',
104104
items: [
105105
{
106-
label: 'Tutorial',
107-
to: '/docs/intro',
106+
label: 'Quickstart',
107+
to: '/docs/quickstart',
108108
},
109109
],
110110
},
@@ -127,9 +127,9 @@ const config = {
127127
{
128128
label: 'Geo',
129129
to: 'https://geobrowser.io',
130-
}
130+
},
131131
],
132-
}
132+
},
133133
],
134134
copyright: `Copyright © ${new Date().getFullYear()} Geo Browser & contributors.`,
135135
},

0 commit comments

Comments
 (0)