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.
Types and functions are located in github.com/oreqizer/go-relaygen/relay
.
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)
}
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"
MIT