Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: revised generating typescript interfaces section #4504

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions docs/molgenis/dev_apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,50 @@ Open the index.html file, add update the message with the name of your app. In a

By this point, you should have enough to view your app. Run the `yarn dev` command to start the dev server. The app will be served at [http://localhost:5173](http://localhost:5173).

### Generate typescript types for an app
### Generating interfaces and types for use in MOLGENIS fontend apps

To generate the typescript interfaces for a given schema, run:
`./gradlew generateTypes --args=[schemaName] [full-path+file-name]`
Throughout the EMX2 frontend, we use typescript for stronger typing and validation in our frontend components. To make things easier for developers, we've include a command for autogenerating typescript interfaces and types from an EMX2 schema. This process is outlined in the steps below.
Comment on lines +407 to +409
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somewhat verbose, prefer more direct style of current doc


for example on unix: `./gradlew generateTypes --args='catalogue /Users/john/Code/emx2/molgenis-emx2/apps/nuxt3-ssr/interfaces/generated/types.ts'`
"
or on windows: `.\gradlew generateTypes --args='"catalogue" "C:\Users\john\Code\emx2\molgenis-emx2\apps\nuxt3-ssr\interfaces\generated\types.ts"' `
#### 1. Start a local EMX2 instance

The first param is the schema name, second param is the full path to the file the interfaces get generated into.
Note that the file is either created or overridden, and that the folder must already exist.
Start your local molgenis instance using gradlew. (Note: Postgres will also need to be started.) In the root `molgenis-emx2` directory, run the following command.

```terminal
./gradlew run
```

#### 2. Import your schema

Once your instance is live -

1. Navigate to the local emx2 instance at [http://localhost:8080/](http://localhost:8080/)
2. Sign in as admin or as another user that can create databases
3. Create a new database (e.g., `My new database`)
4. Import your EMX2 file into the new database

Comment on lines +415 to +427
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not have to use this run command of create an new database to generate the types

#### 3. Generate the interfaces and types

In your application folder (`apps/*`), create a directory to store the types (e.g., "types", "interfaces", etc.). The command is `generateTypes`. The syntax to generate the file is described below.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not have to be in the apps folder


```terminal
./gradlew generateTypes --args=[schemaName] [full-path+file-name]
```

##### Definitions

- `schemaName`: the name of the schema you would like to use to generate types and interfaces
- `full-path+file-name`: the full system path to the output file. (Note: the command will throw an error if the output directory does not exist.)

##### Notes

Any changes made to this file will be overwritten when the command is run again. If you would like to keep these changes, we recommend saving them in a new file.

Depending on your operating system, there are some slight differences in the way it should be written. For example, if you wanted to generate types for a schema called `MySchema`, here's how it would be written.

```terminal
# unix
./gradlew generateTypes --args='MySchema /Users/john/Code/emx2/molgenis-emx2/apps/nuxt3-ssr/interfaces/generated/types.ts'

# windows
.\gradlew generateTypes --args='"MySchema" "C:\Users\john\Code\emx2\molgenis-emx2\apps\nuxt3-ssr\interfaces\generated\types.ts"'
```