go-graphql-example
go-graphql-example copied to clipboard
A production ready Go GraphQL example server.
go-graphql-example
An example go web server implementing a GraphQL api with a Sqlite database.
Read the full article: https://shellbear.me/blog/go-graphql-api
Usage
Using go run
:
> go run main.go
2020/xx/xx xx:xx:xx connect to http://127.0.0.1:8080/ for GraphQL playground
Using go build
:
> go build -o go-graphql-example .
> ./go-graphql-example
2020/xx/xx xx:xx:xx connect to http://127.0.0.1:8080/ for GraphQL playground
You can access the GraphQL playground at: http://127.0.1:8080/
Development
After making changes to ent/schema
or graph
directory make sure to run the generate command:
go generate ./...
Database
Database models are handled with ent.
Follow the instructions to install the ent CLI.
To add a new model:
ent init [Model]
And start editing the new Model schema in ent/schema/[model].go
.
Then run the code generation tool:
go generate ./...
GraphQL
GraphQL API is managed with gqlgen.
To update the API, edit the schema in graph/schema.graphqls
or a create a new schema named: graph/*.graphqls
.
After making changes, run the code generation tool:
go generate ./...
And implement code logic inside graph/[schema].resolers.go
.