oreqizer / go-relaygen

Go generator for implementation-agnostic Relay utilities. :grapes:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RelayGen

godoc Build Status codecov

A go generate based toolset for Relay compliant GraphQL servers.

An evolution of go-relay project.

It ain't much but it's honest work.

API

Types and functions are located in github.com/oreqizer/go-relaygen/relay.

Connection

Run go run github.com/oreqizer/go-relaygen <name> <local id> where you want to generate your connection utilities.

Supports nested ID fields, e.g. Person.ID

The only function you care about is <Name>ConnectionFromArray.

Make your types satisfy the Node interface and create the ConnectionArgs object, feed it into it and you'll get a <Name>Connection.

//go:generate go run github.com/oreqizer/go-relaygen User LocalID

package example

import (
	"github.com/oreqizer/go-relaygen/relay"
)

const UserType = "User"

type User struct {
	LocalID string
	Name    string
}

func (u *User) ID() string {
	return relay.ToGlobalID(UserType, u.LocalID)
}

IDs

There are two functions - ToGlobalID and FromGlobalID. They behave the same like the JS reference implementation.

var global = relay.ToGlobalID("User", "asdf") // Returns a base64 encoded string

var local = relay.FromGlobalID(global) // local.Type == "User", local.ID == "asdf"

License

MIT

About

Go generator for implementation-agnostic Relay utilities. :grapes:


Languages

Language:Go 100.0%