Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shellbear/go-graphql-example
A production ready Go GraphQL example server.
https://github.com/shellbear/go-graphql-example
ent example go golang gqlgen graphql schema sqlite webserver
Last synced: 6 days ago
JSON representation
A production ready Go GraphQL example server.
- Host: GitHub
- URL: https://github.com/shellbear/go-graphql-example
- Owner: shellbear
- Created: 2019-05-16T19:55:10.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-06-12T22:54:15.000Z (5 months ago)
- Last Synced: 2024-06-20T02:05:03.368Z (5 months ago)
- Topics: ent, example, go, golang, gqlgen, graphql, schema, sqlite, webserver
- Language: Go
- Homepage: https://shellbear.me/blog/go-graphql-api
- Size: 440 KB
- Stars: 13
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](.github/images/gopher.jpg)
## Usage
Using `go run`:
```shell
> go run main.go
2020/xx/xx xx:xx:xx connect to http://127.0.0.1:8080/ for GraphQL playground
```Using `go build`:
```shell
> 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/](http://127.0.1:8080/)
[![playground](.github/images/playground.png)](http://127.0.1:8080/)
## Development
After making changes to `ent/schema` or `graph` directory make sure to run the generate command:
```shell
go generate ./...
```## Database
Database models are handled with [ent](https://entgo.io/).
Follow the [instructions](https://entgo.io/docs/getting-started/) to install the ent CLI.
To add a new model:
```shell
ent init [Model]
```And start editing the new Model schema in `ent/schema/[model].go`.
Then run the code generation tool:
```shell
go generate ./...
```## GraphQL
GraphQL API is managed with [gqlgen](https://gqlgen.com/).
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:
```shell
go generate ./...
```And implement code logic inside `graph/[schema].resolers.go`.
## Built with
- [ent](https://github.com/ent/ent)
- [gqlgen](https://github.com/99designs/gqlgen)
- [go-sqlite3](https://github.com/mattn/go-sqlite3)