GraphQL Relay support for gqlgen. Using code generation assists the boilerplates creation of nodes, edges & pagination types.
Dependencies:
- go 1.13
go get -u github.com/sebach1/relaygen
For further details about usage, use the relaygen CLI help cmd
relaygen --help
Notice that the default output is given to the STDOUT, so you can preview any generation omitting the > <FILE>
boilerplate.
- Add the base boilerplate to support relay dep injections on golang models:
relaygen -base > <FILENAME>.go
- Add the schema interface & relay definitions:
relaygen -pkg <PKG_NAME> -base -sdl > <FILENAME>.graphql
- Add the golang entity boilerplates as needed:
relaygen -pkg <PKG_NAME> -name <ALIAS_OF_ENTITY> -type <TYPE_OF_ENTITY> > <FILENAME>.go
- Add the entity to your schema definition:
relaygen -pkg <PKG_NAME> -name <ALIAS_OF_ENTITY> -type <TYPE_OF_ENTITY> -sdl > <FILENAME>.go
- Manual step to avoid magic configs. Add the needed config to your
gqlgen.yaml
config file.
models:
PageInfo:
model: <BASE_DEF_PATH>/relay.PageInfo # Notice that "relay" is the default value of the flag when generating the base
Node:
model: <BASE_DEF_PATH>/relay.Node
<ALIAS_OF_ENTITY>Edge:
model: <ENTITY_RELAY_PATH>/<PKG>.<ALIAS_OF_ENTITY>Edge
<ALIAS_OF_ENTITY>Connection:
model: <ENTITY_RELAY_PATH>/<PKG>.<ALIAS_OF_ENTITY>Connection