The second tier of RAD tools, automating a UI GraphQL and DNA generation based on a JSON schema file.
-
Clone the repo
$ git clone https://github.com/holochain/RAD-Tools-Phase-2.git
-
Enter nix-shell
$ nix-shell
-
Install root node dependencies
$ npm i
-
Generate your custom Holochain Happ according to the type-spec.json file.
$ npm run happ:generate <type-spec.json>
NB: The type-spec.json is optional and will default to the sample-type-spec.json provided in the src/setup/type-specs folder.
The type-spec.json file is the schema that informs the DNA zome, entry, and entry test content as well as the UI's Apollo GraphQL data layer and UI page content.
The type-spec.json is structured in a pattern wherein the keys represent the name of the current field and its values are the content of said field.
{
"types": {
"<entry-name>": {
"description": "<entry-description>",
"sharing": "<public | private>",
"definition": {
"<entry-field-name>": "<entry-field-type>"
}
}
}
}
Example: Below is an example of a happ that will have a single zome with three entries: user, author and books:
{
"types": {
"user": {
"description": "Create and manage users.",
"sharing": "public",
"definition": {
"name": "string",
"avatar_url": "string"
}
},
"author": {
"description": "Create and manage authors.",
"sharing": "public",
"definition": {
"user": "string",
"nickname": "string",
}
},
"book": {
"description": "Create and manage books.",
"sharing": "public",
"definition": {
"author": "string",
"title": "string",
"topic": "string"
}
}
}
}
- Start your Holochain Happ
$ npm run start
- Generate your new ui in the
ui-src
directory.$ npm run ui:generate <type-spec.json>
-
CD into that directory and run the app with mock data
$ cd ui-src && npm i && npm start:mock
-
Navigate to your browser, where your UI server will automatically start up and open the ui in a browser tab with mock data.
-
Enter nix-shell
$ nix-shell
-
Install all root node dependencies
$ npm i
-
Generate the DNA according to the type-spec.json file.
$ hc:generate-dna <type-spec.json>
NB: The type-spec.json is optional and will default to the sample provided in the src/setup/type-specs folder.
If you are only developing a DNA, you may include the zome object wrapper in your schema and run
hc-generate-dna
to generate multiple zomes. Similarly, you may declare which crud functions you'd like to generate by providing a function object as displayed below.The type-spec.json example with zome wrapper:
{ "zomes": { "<zome-name>": { "types": { "<entry-name>": { "description": "<entry-description>", "sharing": "<public | private>", "definition": { "<entry-field-name>": "<entry-field-type>" }, "functions": { "create": "<boolean>", "update": "<boolean>", "delete": "<boolean>", "get": "<boolean>", "list": "<boolean>" } } } } } }
NB: If no zomes object is provided, a single zome will be generated. Currently, only the DNA is compatible with multiple zomes input from the Type Spec JSON.
- Test your DNA
$ npm hc:test