Skip to content

molaux/sequelize-graphql-schema-builder-example

Repository files navigation

The goal is to convert a MySQL Workbench Model to a complete GraphQL API for CRUD operations.

This example uses a slightly modified version of the Skila sample model from MySQL : removed unwanted schemas, renamed redundant foreign keys indexes names and modified lastUpdate fields default values that sqlite does not implements.

The sample data script has been modified for sqlite.

What it does ?

The project loads arbitrary sequelize models, sync it to a Sqlite database stored in memory, and convert it to a complete GraphQL API.

Here, the Sequelize models are generated from a sample MySQL Workbench schema but you can use your own schema file or directly paste your models to src/models (you have to remove its content before).

Install

$ composer install
$ yarn

The project is written for node / ECMAScript module and targetted to use at least node 18. If you use nvm, issue :

$ nvm use

(Re)generate the models (optionnal)

$ bin/mysql-workbench-schema-export --export=node-Sequelize6 --config=config/mysql-worbench-exporter.json data/sakila-db/sakila-modified.mwb

As written above, your models can be generated by other tools like sequelize-automate, or you can use your own MySQL Workbench schema too (You should then comment the sample data insertion in server.js).

Test

$ yarn test

Playground

Have a look at configuration files in the root directory and its config subdirectory.

$ yarn start-dev

Note that sample data will be injected at startup.

The playground should be available at http://localhost:3331/api.

API documentation

Sequelize GraphQL Schema Builder

Branches

To keep the example simple, branches exists to keep somme demonstartions independant. The master branch combine theme all together.

About

Converts a MySQL Workbench schema to a GraphQL API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published