Skip to content

shellbear/go-graphql-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

39df49f · Jun 25, 2021

History

2 Commits
Jun 23, 2021
Jun 23, 2021
Jun 23, 2021
Jun 23, 2021
Jun 23, 2021
Jun 25, 2021
Jun 23, 2021
Jun 23, 2021
Jun 23, 2021
Jun 23, 2021

Repository files navigation

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

gopher

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/

playground

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.

Built with

Releases

No releases published

Packages

No packages published

Languages