GraphQL + gRPC Ice Cream Shop
--------
| auth |
--------
- -
- -
grpc gprc
- -
- -
------------- --------------- -------- -----------
| api-users | < - - graphql - - > | api-gateway | - - - grpc - - - | user | < --- > | user_db |
------------- GET /graphiql --------------- -------- -----------
POST /query -
-
grpc
-
-
------------- ----------------
| ice_cream | < --- > | ice_cream_db |
------------- ----------------
The overall operations can be found in the api_gateway/graph_schema.go
.
The following operations are protected, only authenticated users will be able to use them:
createIceCream
updateIceCream
deleteIceCream
This project requires the google.protobuf
proto package and expects to import from the /usr/local/include
directory.
Download the applicable release on github, and the downloaded zip archive contains the bin
and include
directory.
Extract the archive and copy the bin/protoc
to your GOBIN
path and copy the contents of the include
directory to your /usr/local/include
directory.
This project uses the golang-migrate/migrate
package to manage the database migration.
To run db migration for each services, one has to go the service root folder and have the DB_URL
environment set, then run the following command:
migrate -database "$DB_URL" -path migrations up
To reset the db, one can use the following command:
migrate -database "$DB_URL" drop
To start the entire stack in a single command with docker-compose
:
docker-compose up -d
By default, the application stack can be accessed at localhost:8000
, use /graphiql
if an interactive experience is preferred, otherwise /query
To stop:
docker-compose down
To reset the data volumes while stopping the docker services:
docker-compose down -v
To apply changes in microservice:
docker-compose up --build -d
Note: In the auth section there is the JWT_SECRET_KEY
value that can be & should be changed to some secure value
From the project root, to deploy the entire stack:
helm install <release-name> helmcharts
To access the application stack, in the terminal:
kubectl get svc/api-gateway
Visit CLUSTER-IP
address from the output at port 8000 as shown in the sample below:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
api-gateway ClusterIP 10.43.114.123 <none> 8000/TCP 5m37s
To take down the entire stack:
helm uninstall <release-name>
The gg_icecreamshop.ice_cream.import
is built from the Dockerfile.ice_cream
with the target of import
docker build -f Dockerfile.ice_cream --target=import -t seanwong/gg-icecreamshop.ice_cream.import .
If you are using the docker-compose
or kubernetes
method to start the project, there is no need to perform this step
The ice icream microservice has the import cli tool included in cmd/import/main.go
. Presently, it only accepts a -url
flag and the JSON has to conform to the schema as shown in the sample ice creams json.
Sample invocation From the ice cream microservice root dir:
go run cmd/import/main.go -url http://somehost/somejson.json
The import command is an idempotent operation, ice creams that are already exists wil be skipped.
Note: If the -url
flag is not supplied, it will default to the sample ice creams json.