pebbles

package module
v0.1.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 16 Imported by: 0

README

buildbuildio/pebbles

pebbles is a GraphQL federation gateway.

How it works

It binds different GraphQL services via Relay Global Object Identification. 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!]!
}

# 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!]!
}

# 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!]!
}

Why use pebbles?

Our main goals are simple:

  1. Work with every valid schema, even with most complicated ones;
  2. Provide extendable schemas -- extend types, interfaces, directives and etc without unnecessary duplication;
  3. Customize as you grow -- all our building blocks are interfaces, so you can write your own.

Example

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)
	}
}

Special thanks

Thanks to nautilus/gateway and movio/bramble for inspiration to write this project. Check them, they're both great in their own way ;)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gateway

type Gateway struct {
	// contains filtered or unexported fields
}

func NewGateway

func NewGateway(urls []string, options ...GatewayOption) (*Gateway, error)

func (*Gateway) Handler

func (g *Gateway) Handler(w http.ResponseWriter, r *http.Request)

type GatewayOption

type GatewayOption func(*Gateway)

func WithDefaultPlayground

func WithDefaultPlayground() GatewayOption

func WithExecutor

func WithExecutor(e executor.Executor) GatewayOption

func WithMerger

func WithMerger(m merger.Merger) GatewayOption

func WithPlanner

func WithPlanner(p planner.Planner) GatewayOption

func WithQueryerFactory

func WithQueryerFactory(f QueryerFactory) GatewayOption

type QueryerFactory

type QueryerFactory func(*planner.PlanningContext, string) queryer.Queryer

type Result

type Result struct {
	Errors gqlerrors.ErrorList    `json:"errors,omitempty"`
	Data   map[string]interface{} `json:"data"`
	// contains filtered or unexported fields
}

type Results

type Results []*Result

func (Results) Emit

func (rs Results) Emit(w http.ResponseWriter, isBatch bool)

Directories

Path Synopsis
IMPORTANT: this is all copy paste, but with some changes to fix data mutation, leading to race conditions in runtime
IMPORTANT: this is all copy paste, but with some changes to fix data mutation, leading to race conditions in runtime
generally copy paste from nautilus/graphql
generally copy paste from nautilus/graphql

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL