Implement GraphQL Federation.
flowchart LR
Gateway["Gateway"]
Subgraph1["Subgraph1
users"]
Subgraph2["Subgraph2
contact"]
Client -->|8082| Gateway -->|4000| Subgraph1
Gateway -->|4001| Subgraph2
go install github.com/99designs/gqlgen@latest
go get github.com/99designs/gqlgen/graphql/handler
schema.graphqls
type Service {
name: String!
version: String!
schema: String!
}
gqlgen generate
vscode ➜ /workspaces/go-graphql-federation-example/users (main) $ go run server.go
2023/07/25 04:31:12 connect to http://localhost:4000/ for GraphQL playground
vscode ➜ /workspaces/go-graphql-federation-example (main) $ curl -X POST -H "Content-Type: Application/json" -d '{"query":"{ todos { id } }"}' http://localhost:4000/query
{"data":{"todos":[{"id":"TODO-1"},{"id":"TODO-2"}]}}
vscode ➜ /workspaces/go-graphql-federation-example (main) $
go install github.com/movio/bramble/cmd/bramble@latest
touch config.json
cd cmd/bramble/
go run main.go -conf ./config.json
vscode ➜ /workspaces/go-graphql-federation-example (main) $ curl -X POST -H "Content-Type: Application/json" -d '{"query":"{ todos { id } }"}' http://localhost:8082/query
{"data":{"todos":[{"id":"TODO-1"},{"id":"TODO-2"}]}}
vscode ➜ /workspaces/go-graphql-federation-example (main) $
vscode ➜ /workspaces/go-graphql-federation-example (main) $ curl -X POST -H "Content-Type: Application/json" -d '{"query":"{ todos { id text } }"}' http://localhost:8082/query
{"data":{"todos":[{"id":"TODO-1","text":"My Todo 1"},{"id":"TODO-2","text":"My Todo 2"}]}}vscode ➜ /workspaces/go-graphql-federation-example (main) $
root ➜ /workspaces/go-graphql-federation-example/contact (main) $ curl -X POST -H "Content-Type: Application/json" -d '{"query":"{ contacts { firstname } }"}' http://localhost:8082/query
{"data":{"contacts":[{"firstname":"mirai"}]}}
root ➜ /workspaces/go-graphql-federation-example/contact (main) $
mkdir -p contact
go mod init github.com/danny-yamamoto/go-graphql-federation-example/contact
go get -u github.com/99designs/gqlgen
go install github.com/99designs/gqlgen@latest
go get github.com/99designs/gqlgen/graphql/handler
touch schema.graphqls
touch gqlgen.yml
gqlgen generate