|
1 | 1 | --- |
2 | 2 | title: TypeSync |
3 | | -description: To create an app with custom data types. |
| 3 | +description: TypeSync is a visual tool that helps you manage your Hypergraph schema and update the schema.ts and mapping.ts for your Hypergraph application. |
4 | 4 | version: 0.0.1 |
5 | 5 | tags: [typesync, hypergraph-cli, schema] |
6 | 6 | --- |
7 | 7 |
|
8 | 8 | # 🧬 TypeSync |
9 | | -To create an app with custom data types, you can use the `TypeSync`, fully-functional React application powered by Hypergraph using our scaffolding tool. In just a few minutes, you'll have a local development environment up and running. |
10 | | -## Pre-requisites |
11 | | -- Node.js >= 22 |
12 | | -- pnpm >= 10 (Install with `npm install -g pnpm`) |
13 | | -- Git SSH Setup (for cloning the repo) |
| 9 | + |
| 10 | +TypeSync is a visual tool that helps you manage your Hypergraph schema and update the schema.ts and mapping.ts for your Hypergraph application. |
14 | 11 |
|
15 | 12 | ## Installation |
16 | | -First install the Hypergraph CLI. |
17 | | -``` |
18 | | -pnpm install -g @graphprotocol/hypergraph-cli@latest |
19 | | -``` |
20 | | -Approve the building scripts by running the following command: |
21 | | -``` |
22 | | -pnpm approve-builds -g |
23 | | -``` |
24 | 13 |
|
25 | | -Selecting all the options by pressing `a` followed by `Yes` |
| 14 | +TypeSync automatically comes with the `hypergraph` package. Once you have it installed it will be available via: |
26 | 15 |
|
27 | 16 |
|
28 | | -## Launching TypeSync |
29 | | -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 |
| 17 | +```bash |
| 18 | +npx hg typesync --open |
| 19 | +# or |
| 20 | +pnpm hg typesync --open |
| 21 | +bunx hg typesync --open |
| 22 | +yarn hg typesync --open |
30 | 23 | ``` |
31 | | -hg typesync --open |
32 | | -``` |
33 | | -This will start the TypeSync server. You can now access the TypeSync app in your browser at ```http://localhost:3000```. |
| 24 | + |
| 25 | +This will start the TypeSync server. You can now access the TypeSync app in your browser at `http://localhost:3000`. The UI will look like this: |
| 26 | + |
34 | 27 |  |
35 | 28 |
|
| 29 | +The UI is split into two main sections: |
| 30 | +- The left side is a list of existing types in the Knowledge Graph to pick from. |
| 31 | +- The right side represents the schema you are currently working on. |
| 32 | + - At the bottom you can find two buttons: |
| 33 | + - `Sync with schema.ts` to sync the current schema to your `schema.ts` file. |
| 34 | + - `Publish Schema` to publish the current schema to the Knowledge Graph. |
| 35 | +- The top right corner you can find a button to `Sign in to Geo Account` to sign in to your Geo Account. This is a prerequisite to publish your schema to the Knowledge Graph. |
| 36 | + |
| 37 | +## Recommended Flow |
| 38 | + |
| 39 | +1. Design your schema |
| 40 | +2. Sync it to your schema.ts file using the `Sync with schema.ts` button |
| 41 | +3. Publish your schema to the Knowledge Graph |
| 42 | + 1. Sign in with Geo Connect. To do so click on the `Sign in to Geo Account` button in the top right corner. |
| 43 | + 2. In "Connect" select an existing public space or create & select a new public space you want to publish your schema to. Note: Can be any space of your choice and doesn't matter which one. |
| 44 | + 3. Click the "Publish Schema" button to publish your schema to the Knowledge Graph. |
36 | 45 |
|
37 | | -## Scaffold Your First Application |
38 | | -In the TypeSync Studio: |
39 | | -1. **Create a New Application**: Click on "New App" to start a new application. Give it a name and description. |
40 | | - |
41 | | -2. **Browse Your Schema**: Use the Schema Browser to explore existing data types or create new ones. |
42 | | - |
43 | | -3. **Select Schema**: Choose the data types you want to include in your application. You can select multiple types or create new ones by clicking "Add Type". Click on "Select Template & Generate". |
44 | | - |
45 | | - |
46 | | -4. **Generate Application**: After selecting your schema, click on "Generate App". TypeSync will create a complete React application with the selected data types. |
47 | | - |
48 | | - |
49 | | - |
50 | | -5. **Run Your Application**: Once the app is generated, you can run it locally. Navigate to the generated app directory and run: |
51 | | - ``` |
52 | | - cd <your-app-name> |
53 | | - pnpm install |
54 | | - pnpm dev |
55 | | - ``` |
56 | | -This will start the application, and you can view it in your browser at `http://localhost:5173`. |
57 | | -You're all set! You can now start building your application by editing the files in the ```src``` directory. The generated ```src/schema.ts``` file contains the Hypergraph schema you defined in TypeSync. |
| 46 | +## Best Practices |
58 | 47 |
|
59 | | -Example of the generated schema (```src/schema.ts```): |
60 | | -```typescript |
61 | | -import type { Mapping } from '@graphprotocol/hypergraph'; |
62 | | -import { Id } from '@graphprotocol/hypergraph'; |
| 48 | +If there is an existing type ideally use this one and adept it to your needs. This will allow for more interoperability with other applications. |
63 | 49 |
|
64 | | -export const mapping: Mapping = { |
65 | | - AcademicYear: { |
66 | | - typeIds: [Id("27e097b7-fba0-4fdd-a264-b0ed70f79e0a")], |
67 | | - properties: { |
68 | | - description: Id("9b1f76ff-9711-404c-861e-59dc3fa7d037"), |
69 | | - name: Id("a126ca53-0c8e-48d5-b888-82c734c38935") |
70 | | - }, |
71 | | - }, |
72 | | -} |
73 | | -``` |
| 50 | +For properties prefer existing properties, but in case you need a different type best to create a new property. |
0 commit comments