|
| 1 | +--- |
| 2 | +title: TypeSync |
| 3 | +description: To create an app with custom data types. |
| 4 | +version: 0.0.1 |
| 5 | +tags: [typesync, hypergraph-cli, schema] |
| 6 | +--- |
| 7 | + |
| 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) |
| 14 | + |
| 15 | +## 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 | + |
| 25 | +Selecting all the options by pressing `a` followed by `Yes` |
| 26 | + |
| 27 | + |
| 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 |
| 30 | +``` |
| 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```. |
| 34 | + |
| 35 | + |
| 36 | + |
| 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. |
| 58 | +
|
| 59 | +Example of the generated schema (```src/schema.ts```): |
| 60 | +```typescript |
| 61 | +import { Id } from '@graphprotocol/grc-20'; |
| 62 | +import type { Mapping } from '@graphprotocol/typesync/Mapping'; |
| 63 | +
|
| 64 | +export const mapping: Mapping = { |
| 65 | + AcademicYear: { |
| 66 | + typeIds: [Id.Id("27e097b7-fba0-4fdd-a264-b0ed70f79e0a")], |
| 67 | + properties: { |
| 68 | + description: Id.Id("9b1f76ff-9711-404c-861e-59dc3fa7d037"), |
| 69 | + name: Id.Id("a126ca53-0c8e-48d5-b888-82c734c38935") |
| 70 | + }, |
| 71 | + }, |
| 72 | +} |
| 73 | +``` |
0 commit comments