pebbles is a GraphQL federation gateway.
It binds different GraphQL services via Relay Global Object Identification. This means that any global object must have unique id. For example, Human object may have id human_1
, and Animal object -- animal_1
, so when resolving Node interface in each service you could know by only id what object client is querying. In order to bind two types which spreads across multiple services, they must implement Node interface, ie
# Service A
interface Node {
id: ID!
}
type Human implements Node {
id: ID!
name: String!
}
type Query {
node(id: ID!): Node
getHumans: [Human!]!
}
type Mutation {
saveHuman(name: String!): Human!
}
# Service B
interface Node {
id: ID!
}
type Human implements Node {
id: ID!
phone: String!
}
type Animal {
name: String!
owner: Human!
}
type Query {
node(id: ID!): Node
getAnimals: [Animal!]!
}
type Subscription {
animalAdded: Animal!
}
# Pebbles resulting Schema
interface Node {
id: ID!
}
type Human implements Node {
id: ID!
name: String!
phone: String!
}
type Animal {
name: String!
owner: Human!
}
type Query {
node(id: ID!): Node
getHumans: [Human!]!
getAnimals: [Animal!]!
}
type Mutation {
saveHuman(name: String!): Human!
}
type Subscription {
animalAdded: Animal!
}
Our main goals are simple:
- Work with every valid schema, even with most complicated ones;
- Provide extendable schemas -- extend types, interfaces, directives and etc without unnecessary duplication;
- Support for Subscription queries (experimental);
- Customize as you grow -- all our building blocks are interfaces, so you can write your own.
package main
import (
"fmt"
"net/http"
"github.com/buildbuildio/pebbles"
)
func main() {
urls := []string{
"http://localhost:3000",
}
gw, err := pebbles.NewGateway(
urls,
pebbles.WithDefaultPlayground(),
)
if err != nil {
panic(err)
}
sm := http.NewServeMux()
sm.HandleFunc("/graphql", gw.Handler)
server := http.Server{
Addr: fmt.Sprintf("0.0.0.0:%d", 8000),
Handler: sm,
}
fmt.Println("Starting server...")
if err = server.ListenAndServe(); err != nil {
panic(err)
}
}
Thanks to nautilus/gateway and movio/bramble for inspiration to write this project. Check them, they're both great in their own way ;)