Skip to content

Commit a7b74ed

Browse files
Upgraded to latest Platformatic (#25)
* Upgraded to latest Platformatic Signed-off-by: marcopiraccini <[email protected]> * Upgraded to latest Platformatic Signed-off-by: marcopiraccini <[email protected]> --------- Signed-off-by: marcopiraccini <[email protected]>
1 parent 8f1d743 commit a7b74ed

File tree

36 files changed

+12061
-7500
lines changed

36 files changed

+12061
-7500
lines changed

assets/step-1-create.png

4.71 KB
Loading

assets/step-2-openapi.png

1.42 KB
Loading

assets/step-2-run.png

12.5 KB
Loading

assets/step-6-mutation.png

15.8 KB
Loading

assets/step-8-create-app.png

35.5 KB
Loading

assets/step-8-deploy-ok.png

102 KB
Loading

assets/step-8-deploy-test.png

93.8 KB
Loading

assets/step-8-deploy.png

72.1 KB
Loading

assets/step-8-org.png

35.9 KB
Loading

assets/step-8-workspace-ids-2.png

32.9 KB
Loading

assets/step-8-workspace-ids.png

118 KB
Loading

assets/step-8-workspace-ready.png

91 KB
Loading

assets/step-8-workspace.png

65.4 KB
Loading

package-lock.json

+434-7,465
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"test": " c8 tap --no-cov -j1 --ts"
99
},
1010
"dependencies": {
11-
"@slidev/cli": "^0.42.0",
11+
"@slidev/cli": "^0.42.4",
1212
"slidev-theme-platformatic": "^0.1.2",
1313
"@slidev/theme-default": "*",
1414
"@slidev/theme-seriph": "*"
1515
},
1616
"devDependencies": {
17-
"c8": "^7.13.0",
18-
"tap": "^16.3.4"
17+
"c8": "^7.14.0",
18+
"tap": "^16.3.6"
1919
}
2020
}

slides.md

+132-22
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,15 @@ npx platformatic db migrations apply
242242
```
243243

244244
- You can now reload your GraphiQL and OpenAPI pages and you will
245-
automatically see the updated schemas as the migrations are auto-applied.
245+
automatically see the updated schemas.
246246

247-
- In case you edit the migrations file before running the rollback,
248-
the database will be on a non-consistent state.
249-
You might need to delete the `db.sqlite` file and restart the server:
250-
```shell
251-
rm db.sqlite
252-
npm start
253-
```
254247
---
255248

256249
# Step 2: Create DB schema (3/3)
257250

258251
- Note that migration `001.do.sql` is applied:
259252

260-
<img src="/assets/step-2-run.png" width="500" class="center">
253+
<img src="/assets/step-2-run.png" width="600" class="center">
261254

262255
Platformatic is now exposing the 'quotes' entity through GraphQL and OpenAPI!
263256

@@ -494,15 +487,13 @@ module.exports = async function (app) {}
494487

495488
- ...and the configuration in `platformatic.db.json`:
496489

497-
```json{3-7}
498-
{
490+
```json{2-7}
499491
...
500492
"plugins": {
501493
"paths": [
502494
"plugin.js"
503495
]
504496
}
505-
}
506497
507498
```
508499

@@ -516,7 +507,14 @@ See: https://github.com/platformatic/platformatic/issues/55
516507
# Step 5: Plugins
517508

518509
- Platformatic DB can be extended with [**Fastify Plugins**](https://www.fastify.io/docs/latest/Reference/Plugins/)
519-
- When Platformatic DB starts, loads the plugins (try adding a `app.log.info` in `plugin.js`).
510+
- When Platformatic DB starts, loads the plugins (try adding a `app.log.info` in `plugin.js`):
511+
512+
```javascript{2}
513+
module.exports = async function (app) {
514+
app.log.info('plugin loaded')
515+
}
516+
```
517+
See the log on the server:
520518

521519
```shell {2}
522520
[10:09:20.052] INFO (146270): running 003.do.sql
@@ -562,7 +560,7 @@ module.exports = async function plugin (app) {
562560

563561
- We can extract a `incrementQuoteLikes` function for reuse in `plugin.js`:
564562

565-
```js{5-13,18-20}
563+
```js{4-12,16-18}
566564
const S = require('fluent-json-schema')
567565
module.exports = async function plugin (app) {
568566
app.log.info('plugin loaded')
@@ -607,9 +605,11 @@ module.exports = async function plugin (app) {
607605
}
608606

609607
```
608+
---
610609
611-
- Try the mutation with GraphiQL
610+
# Try the mutation with GraphiQL
612611
612+
<img src="/assets/step-6-mutation.png" class="center">
613613
614614
<!--
615615
mutation {
@@ -628,15 +628,15 @@ npm install
628628
npm start
629629
```
630630
631-
This should start:
631+
You should see this:
632632
```shell {8}
633-
➜ npm start
633+
➜ npm start
634634

635635
> start
636636
> astro dev --port 3000
637637

638-
🚀 astro v1.3.1 started in 38ms
639-
638+
🚀 astro v1.9.2 started in 72ms
639+
640640
┃ Local http://localhost:3000/
641641
┃ Network use --host to expose
642642
```
@@ -663,7 +663,7 @@ Apparently, `vite` starts on http://localhost:3000/ on linux, and http://127.0.
663663
}
664664
```
665665
666-
- Restart the Platformatic DB server
666+
- ~~Restart the Platformatic DB server~~ (not needed! 🎉)
667667
668668
<!--
669669
BONUS STEP.
@@ -672,14 +672,124 @@ BONUS STEP.
672672
673673
---
674674
675-
# Open with the browser
675+
# Step 7: Open with the browser
676676
677677
<img src="/assets/step-7-ui.png" width="500" class="center">
678678
679679
---
680680
681-
# Next Steps
682681
682+
# Step 8: Deploy on Platformatic Cloud
683+
684+
- Point your browser to https://platformatic.cloud
685+
- Login with github (you may beed to accept the terms and conditions if not done yet)
686+
- You should see the **Dashboard** page on your personal organization, which is created automatically. Click on "Create an App"
687+
688+
<div flex justify-center m-4>
689+
<img src="/assets/step-8-org.png" width="400"/>
690+
</div>
691+
---
692+
693+
# Step 8: Create an Application
694+
695+
<div flex justify-center m-4>
696+
<img src="/assets/step-8-create-app.png"/>
697+
</div>
698+
699+
---
700+
701+
# Step 8: Create a Wokspace
702+
703+
<div flex justify-center m-4>
704+
<img src="/assets/step-8-workspace.png"/>
705+
</div>
706+
707+
---
708+
709+
# Step 8: Wokspace ID and Key
710+
711+
<div flex justify-center m-4>
712+
<img src="/assets/step-8-workspace-ids.png"/>
713+
</div>
714+
715+
---
716+
717+
# Step 8: Download the Workspace env
718+
719+
- You can also download the `env` file with both workspaceId and the key.
720+
- The file is called `${workspace-name}.plt.txt`
721+
- Save it in `movie-quotes/apps/movie-quotes-api` folder in your project
722+
723+
<div flex justify-center m-4>
724+
<img src="/assets/step-8-workspace-ids-2.png" width="500"/>
725+
</div>
726+
727+
---
728+
729+
# Step 8: Now the Workspace is ready!
730+
731+
<div flex justify-center m-4>
732+
<img src="/assets/step-8-workspace-ready.png"/>
733+
</div>
734+
735+
---
736+
737+
# Step 8: Deploy using the CLI
738+
739+
- Go in the `movie-quotes-api` folder:
740+
```bash
741+
cd ./movie-quotes/apps/movie-quotes-api
742+
```
743+
744+
- Launch the deployment:
745+
746+
```bash
747+
npx platformatic deploy --keys=./test-workspace-demo.plt.txt
748+
```
749+
750+
<div flex justify-center m-4>
751+
<img src="/assets/step-8-deploy.png"/>
752+
</div>
753+
754+
---
755+
756+
# Step 8: Check the deployment:
757+
758+
<div flex justify-center m-4>
759+
<img src="/assets/step-8-deploy-ok.png" width="800"/>
760+
</div>
761+
762+
---
763+
764+
# Step 8: Test the deployment:
765+
766+
```bash
767+
curl https://gorgeous-vacuous-young-chalk.deploy.space/quotes
768+
```
769+
770+
771+
<div flex justify-center m-4>
772+
<img src="/assets/step-8-deploy-test.png" width="500"/>
773+
</div>
774+
775+
776+
---
777+
778+
# Step 8: Connect the UI to the deployed API
779+
780+
- Open `movie-quotes/apps/movie-quotes-frontend/.env` and change `PUBLIC_GRAPHQL_API_ENDPOINT` to the deployed API endpoint (use the actual URL):
781+
782+
783+
```js
784+
PUBLIC_GRAPHQL_API_ENDPOINT=https://gorgeous-vacuous-young-chalk.deploy.space/graphql
785+
```
786+
787+
- Restart the frontend dev server and check the UI is still working
788+
789+
---
790+
791+
# Next Steps
792+
683793
- Add security integrating with a third party authentication service (like [Auth0](https://auth0.com/), see how [here](https://oss.platformatic.dev/docs/next/guides/jwt-auth0)).
684794
- Add authorizations at API level (see [references](https://oss.platformatic.dev/docs/next/reference/db-authorization/introduction))
685795
- Generate [TypeScript](https://www.typescriptlang.org/) types
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db.sqlite
2+
node_modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db.sqlite
2+
node_modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db.sqlite
2+
node_modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db.sqlite
2+
node_modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db.sqlite
2+
node_modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
db.sqlite
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db.sqlite
2+
node_modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db.sqlite
2+
node_modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Entity } from '@platformatic/sql-mapper';
2+
import { EntityTypes, Movie,Quote } from './types'
3+
4+
declare module 'fastify' {
5+
interface FastifyInstance {
6+
getSchema<T extends 'Movie' | 'Quote'>(schemaId: T): {
7+
'$id': string,
8+
title: string,
9+
description: string,
10+
type: string,
11+
properties: {
12+
[x in keyof EntityTypes[T]]: { type: string, nullable?: boolean }
13+
},
14+
required: string[]
15+
};
16+
}
17+
}
18+
19+
declare module '@platformatic/sql-mapper' {
20+
interface Entities {
21+
movie: Entity<Movie>,
22+
quote: Entity<Quote>,
23+
}
24+
}

0 commit comments

Comments
 (0)