The workflow depends on php
and composer
since it uses a fork of MySQL Workbench Schema Exporter / Node exporter to generate Sequelize models. Thus, the API is driven by MySQL Workbench
$ cd backend
$ yarn ci
The project is written as node / ECMAScript module and node is run with --experimental-specifier-resolution=node
. You need at least node 14. If you use nvm, issue :
$ nvm use
For demonstration purpose, the project uses a SQLLite in memory database : see config/model.json
. Just adjust this configuration file to persist (or use an existing one) database. For more informations, see Sequelize documentation.
The boilerplate can handle as many Sequelize models as you need. The default repository is named «own» :
$ yarn generate:models
This command lets you regenerate all the models from the MySQL Workbench file docs/Model.mwb
.
Note that this command will ovewrite all models present in src/models/own
, you should not modify these files. For that purpose, an extensions mechanism handles files in src/models/own/extensions
. To handle multiple MySQL Workbench autogenerated schemas, you shoud have a look to config/mysql-workbench-exporter.json
and package.json
.
Once you regenerated models files, you can (if needed) create a migration file automatically :
$ yarn generate:migration -r own -n last-changes
These migrations will be handled by Umzug at the server start.
The workflow embeds a Jest test suite that handles many aspects of the server : it plays queries and mutations, then checks responses to them. This test suite observes events triggered by subscriptions in response to each request and checks there is no extra data.
The provided test suite introduce the ability to log in and check basic functionality.
tests/gql/*.gql
: The ordered requests to playtests/subscriptions/*.gql
: The subscriptions to listen totests/json/*.json
: The expected results
$ yarn test
Start against dev env and provide a playground that should be available at http://localhost:3331/api :
$ yarn start:dev
By default, a user admin
(password admin
) is created by migrations executed at start time (see migrations/3-default-user.cjs
). Note that by definition SQLLite in memory database is not persistent, so migrations is reexecuted at each restart.
Start against prod env :
$ yarn start:prod
In order to convert the Sequelize models to a GraphQL schema, the system uses Sequelize GraphQL Schema Builder. This piece of code transforms a Sequelize schema in a ready to use GraphQL API that exposes queries, mutations and subscriptions for each Sequelize entity you generated. In addition, it exposes data types used by MUI CRUDF to generate creation / update forms and validate data on client side.
The system instanciates the schema for GraphQL server from src/schema/index.js
. Here, controllers built by Sequelize GraphQL Schema Builder are merged with custom one :
src/schema/authentication
handles all authentication and security policysrc/schema/country
demonstrates how to extend Sequelize GraphQL Schema Builder auto generated APIsrc/schema/configuration
is a custom controller that exposes a configuration API to client and et a method to share it with other controllers.