This is an example setup showing how graphql-mesh can be integrated in an existing express backend.
This section should help you to set up a local development environment with a running instance of the express backend, a fake graphql api service and a seeded database.
The environment might run with other LTS or major version releases, but the following versions are recommended to avoid issues.
node ^12.16.1
npm ^6.14.3
docker ^20.10.5
If you fulfil the prerequisites you should be able to install the development dependencies by executing the following command:
npm install
The development dependencies are needed to allow easy bootstrap and startup of the individual project packages. It is worth mentioning that we are using lerna to manage multiple independent node projects inside one repository. After a successful installation you should be able to install the package dependencies with the following command:
npm run bootstrap
The project requires a running mysql database which later is used by graphql-mesh as an input source. To make this as easy as possible you only need to follow the follwing instructions.
-
Copy the
.env.example
file with the following command$ cp .env.example .env
. Important note: the.env
file needs to be located in the project root. -
Start a mysql database with the help of docker. To make this work you just need to execute
$ docker-compose up -d
from project root. The initial startup process will take some secounds. If you are interessted in the current state you can execute$ docker-compose logs -f --tail=20
, which prints and follows the latest 20 log output messages. If the database is ready to accept connection you should see the following message:[Note] mysqld: ready for connections.
-
Now you can execute the following command
$ npm run db:initialize
, which will migrate and seed the running mysql database.
By default docker will use the .env
file to set the needed database credentials and options.
After you have succesfully installed all needed depdencies and have a running and seeded database you should be able to start the express backend and the fake graphql api service by simply executing $ npm run start
. If no error occures you can access the fake graphql api on
and the express backend on
We use graphql-voyager to have a better visibility of our graphql schema.
- Frederik Aulich - Initial work - Kiesen
- Angel Svirkov - Initial work - angelsvirkov
- To make path aliasing work in
packages/backend
we need to register thetsconfig-paths
module withts-node-dev
as shown here
To checkout some example queries please use packages/backend/example-queries/*
inside the GraphiQL playground at http://localhost:4848/graphql
This project is licensed under the MIT license - for details take a look at LICENSE.md