Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oreqizer/go-relaygen
Go generator for implementation-agnostic Relay utilities. :grapes:
https://github.com/oreqizer/go-relaygen
Last synced: 21 days ago
JSON representation
Go generator for implementation-agnostic Relay utilities. :grapes:
- Host: GitHub
- URL: https://github.com/oreqizer/go-relaygen
- Owner: oreqizer
- Created: 2019-12-06T12:16:09.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T11:53:18.000Z (11 months ago)
- Last Synced: 2024-05-27T20:51:34.087Z (5 months ago)
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RelayGen
[![godoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/oreqizer/go-relaygen)
[![Build Status](https://travis-ci.org/oreqizer/go-relaygen.svg?branch=master)](https://travis-ci.org/oreqizer/go-relaygen)
[![codecov](https://codecov.io/gh/oreqizer/go-relaygen/branch/master/graph/badge.svg)](https://codecov.io/gh/oreqizer/go-relaygen)A `go generate` based toolset for [Relay](https://facebook.github.io/relay/docs/en/graphql-server-specification.html) compliant **GraphQL** servers.
> An evolution of [go-relay](https://github.com/oreqizer/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 ` where you want to generate your connection utilities.
> Supports nested ID fields, e.g. `Person.ID`
The only function you care about is `ConnectionFromArray`.
Make your types satisfy the `Node` interface and create the `ConnectionArgs` object, feed it into it and you'll get a `Connection`.
```go
//go:generate go run github.com/oreqizer/go-relaygen User LocalIDpackage 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.
```go
var global = relay.ToGlobalID("User", "asdf") // Returns a base64 encoded stringvar local = relay.FromGlobalID(global) // local.Type == "User", local.ID == "asdf"
```## License
MIT