lychee
A simple example of GraphQL microservices federated in Golang. This project will soon provide some CMS features.
This repository is a work in progress...
Setup
go get -u github.com/aquiseb/lychee
go get ./...
Start
Open each microservice in a separate terminal tab. Start each of them with
cd micro-xxxxx
./start.sh
The federation of each of these microservices is done with the micro-federation
module.
cd micro-federation
go run main.go
Failed downloading ...
https://github.com/oxequa/realize/issues/253#issuecomment-532045314
or
go get -v gopkg.in/urfave/cli.v2 \
&& go get -v github.com/oxequa/realize
Configuration
The configuration is handled by viper.
Add a _config
file in your microservice.
Versioning
Versioning is handled by govvv.
To change the version, edit the VERSION
file.
Build
Each microservice must be built separately.
Add a VERSION
file and specify the version of the microservice.
govvv build
Static assets
lychee uses go-bindata to convert any file into managable Go source code.
Useful for embedding binary data (like GraphQL schemas) into a go program.
Write your microservice schema package, then generate bindata.go
.
go-bindata -ignore=\.go -pkg=schema -o=schema/bindata.go schema/...
Here's how to use it from within main.go.
// GetSchema returns the schema of Post
func GetSchema() string {
s, _ := schema.Asset("schema/schema.graphql")
stringSchema := string(s)
return stringSchema
}
Graphql Queries
Post
Simple
{
post(id: "2") {
title
reviews {
edges {
node {
id
stars
}
}
}
}
Advanced
{
post(id: "1") {
id
title
reviews {
edges {
node {
id
stars
post {
id
title
reviews {
edges {
node {
id
stars
}
}
}
}
}
}
}
}
}
lastname
is provided by micro-post for the moment! This is an awesome federation feature.
{
allUsers {
id
firstname
lastname
}
}
Troubleshooting
graphql: panic occurred: runtime error: invalid memory address or nil pointer dereference
Chances are that you forgot to pass DB to a resolver. Passing DB enables underlying connections (like ReviewConnection) or infinite subqueries to use DB.
s := PostReviewsResolver{
DB: p.DB,
reviews: reviews,
}
Inspirations