graphql

command module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2019 License: MIT Imports: 2 Imported by: 0

README

graphql-orm

Golang GraphQL API generator using gqlgen and gorm

Installation

Before you start, please make sure you have goimports installed:

go get golang.org/x/tools/cmd/goimports
go mod init xxx
go get github.com/maiguangyang/graphql
go mod edit -replace=github.com/satori/go.uuid@v1.2.0=github.com/satori/go.uuid@master
go get github.com/maiguangyang/graphql@latest
go mod tidy

NOTE: Make sure you have Go installed on your system.

  1. Create new project repository
  2. run go run github.com/maiguangyang/graphql init
  3. follow initialization instruction (creating makefile is suggested)
  4. open create model.graphql and create your custom model schema
  5. each time you change model, run make generate or go run github.com/maiguangyang/graphql to recreate generated source codes

Running locally

For running locally you can use:

make run

or without makefile:

DATABASE_URL=sqlite3://test.db PORT=8080 go run *.go

or

DATABASE_URL=mysql://'root:123456@tcp(192.168.33.10:3306)/graphql?charset=utf8mb4&parseTime=True&loc=Local' go run *.go

Example

You can find example project at graphql-orm-example repo

Schema preview in Voyager

GraphQL Voyager tool is very nice tool for previewing your GraphQL Schema, you can run it locally by:

make voyager

or without makefile:

docker run --rm -v `pwd`/gen/schema.graphql:/app/schema.graphql -p 8080:80 graphql/voyager

...after voyager starts up go to https://localhost:8080

All generated stuff is stored in ./gen/ folder.

Building docker image

If you generated Dockerfile initialization it's as easy as running:

docker build -t {IMAGE_NAME} .

If you want to create your own docker image, you can check the example repository for generated Dockerfile: https://github.com/maiguangyang/graphql-example/blob/master/Dockerfile

What's this library for?

While following microservices design patterns we ended up with many "model services". gqlgen is perfect tool, but implementing resolvers in every service is getting more and more cumbersome. Using this tool we only have to update model.graphql and all resolvers get generated automatically.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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