Skip to content

Commit

Permalink
Start of Hasura tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Semprini committed Feb 17, 2024
1 parent e148f95 commit 3f17dc3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
Binary file added docs/_static/image/hasura_tut_model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions docs/tutorial-hasura.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Hasura & Django Tutorial
************************

This probably feels like an odd mix. Django is a full ORM and everyone uses Django Rest for an API dont they?

Django and Django Rest Framework do indeed rock, and a great solution when you are providing an API with a known query pattern.

If you have worked on more generic API platforms then you should understand how hard it is to maintain and develop a RESTful API when we start adding things like writable nested fields or sub-object depth to support multiple ways of consuming the API.
This is where GraphQL excels and specifically Hasura for Model Driven Generation. Like Django, Hasura is opinionated but unlike Django it's opnionated approach can be driven purely by configuration - a perfect case for model driven generation.

Django has a great database migration system, which is driven from python classes. Other options here are Liquibase and Flyway but Django migrations are created from the delta between the python class and the DB so gives the flexibility of being able to support multiple DB back-ends - I often use SQLite on my dev machine for example. I also like the data manipulation ability in Django for support and data fix tasks, plus the admin interface gives a lot of data management capability out of the box.

Here's a component diagram of the solution:

.. image:: https://github.com/Semprini/pyMDG/raw/master/docs/_static/image/hasura_tut_component.png

This tutorial won't cover the data modelling side. The Sparx tutorial will take you through this. In the github repo, the pyMDG/sample_recipes/sparxdb folder has a sample.qea file with a simple data model. The model shows how the default generation templates realize many-to-one and many-to-many relationships. Here's the simple data model:

.. image:: https://github.com/Semprini/pyMDG/raw/master/docs/_static/image/hasura_tut_model.png


Generation
^^^^^^^^^^

TBD
12 changes: 6 additions & 6 deletions docs/tutorial-sparx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pyMDG has a specific UML nomenclature, expects Sparx EA project to have a packag
.. image:: https://github.com/Semprini/pyMDG/raw/master/docs/_static/image/sparx_tut_datamodel.png

3. Exporting
3. Exporting - needed for Sparx EA versions before 16

| In the Sparx EA Browser window, single click on the "Tutorial Data Model" package.
| In the top menu bar select "Publish" and choose "Publish As...". I prefer this to "Export Package" as it gives the option to export diagram images if we're generating documentation.
Expand All @@ -62,12 +62,12 @@ pyMDG parses the XMI into the internal classes shown in the metamodel section of
| Our first step is to create a file in our tutorial1 folder called schemagen.yaml.
| We then add info on how our project is set up::
| root_package: Tutorial Data Model
| model_package: Tutorial Data Model
| source: ./tutorial1.xmi
| parser: sparx
| root_package: Tutorial Data Model
| model_package: Tutorial Data Model
| source: ./tutorial1.xmi
| parser: sparx
| Next we add the generation type and where to find our jinja2 templates to the yml::
| Next we add the generation type and where to find our jinja2 templates to the yaml::
| dest_root: ./build
| templates_folder: ./mdg/templates
Expand Down
Binary file modified sample_recipes/sparxdb/sample.qea
Binary file not shown.

0 comments on commit 3f17dc3

Please sign in to comment.