This repository contains a small sample project I am developing as a part of my Master Thesis. The goal of the master thesis is to evaluate architectural differences of microservice architectures when using REST or GraphQL as API models.
This repository contains the GraphQL implementation of the case study.
This example project models a small online shop. The architecture consists of four microservices, responsible for processing orders, managing inventory, processing payments, and shipping.
The easiest way to build and run the project is with a Docker installation available.
- Create the file
.env
in the root directory of the project. Use.env.template
to see an example of the contents. You can leave the*_CLIENT_SECRET
keys out for now. - Run
docker-compose up -d
to start up the project. If the images are already available locally, add the--build
flag to force rebuilding the images. - Wait until the service
keycloak
is available (you can check availability at the Traefik Dashboard), then navigate a browser tohttp://host.docker.internal:8080/auth/
. - Click on Administration Console and log in with the credentials specified in
.env
. Then import the project realm by hovering over Master and clicking on Add realm. Select the filesetup/realm-export.json
and click Create. - Create a user by clicking on Users and then Add User. Specify the username of the user and then click Save. Set the credentials of the user by selecting the Credentials tab. Enter the password twice, disable the Temporary switch and click Set Password. Optional: Assign the user a role by selecting the tab Role Mappings, select a role the user should be assigned (e.g. admin) and click Add selected >.
- Set up the secrets of the services by clicking on Clients.
For each client (inventory, order, payment and shipping), click on the respective client, select the tab Credentials and copy the secret.
If the secret hidden with asterisks, click Regenerate Secret.
Configure the copied secret in the
.env
file for the respective service. - Restart the reconfigured services with
docker-compose up -d
. Make sure, that the servicegateway
started correctly. It waits for the availability of the dependant services, but can time-out if they take a long time to start.
The services are now up and running. An access token can be obtained with the following request by using the client external and the credentials of the user you created.
POST http://host.docker.internal:8080/auth/realms/ma-graphql-shop/protocol/openid-connect/token
Content-Type: application/x-www-form-urlencoded
grant_type=password&client_id=external&client_secret=<secret>&username=admin&password=<password>
The access token can be specified with the Bearer
scheme in the HTTP Authorization
header, or using GraphQL Playground.
GraphQL Playground is available at the following locations:
The access token must be specified in JSON format:
{
"authorization": "Bearer <token>"
}