Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rhzs/gqlgen-todos
This is an improved version for Golang GQLGEN TODO Example
https://github.com/rhzs/gqlgen-todos
dependency-injection golang golang-examples graphql
Last synced: 26 days ago
JSON representation
This is an improved version for Golang GQLGEN TODO Example
- Host: GitHub
- URL: https://github.com/rhzs/gqlgen-todos
- Owner: rhzs
- Created: 2023-07-19T13:13:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-20T03:03:05.000Z (over 1 year ago)
- Last Synced: 2024-09-29T21:21:13.117Z (about 1 month ago)
- Topics: dependency-injection, golang, golang-examples, graphql
- Language: Go
- Homepage:
- Size: 1.38 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GQLGEN Todo Example
This service is to demonstrate how we can develop GraphQL service in Golang.
This example emphasize on how we can structure our Golang code with GraphQL, use dependency injection pattern, and follow Effective Go approach.## Running The Service
To run the service, you can run it directly with `go run cmd/main.go`.
Don't worry about not be able to resolve dependencies, you don't have to download dependencies. It will always be there (committed).
If you wish to regenerate the generated file, you can use `go run github.com/99designs/gqlgen generate`.
## Code Structure
```text
.
├── README.md
├── cmd
│ └── main.go
├── go.mod
├── go.sum
├── gqlgen.yml
├── graph
│ ├── model
│ ├── schema.graphqls
│ └── z_graph.go
├── internal
│ ├── mutation
│ ├── query
│ ├── resolver
│ └── storage
├── tools.go
└── vendor
├── github.com
├── golang.org
├── gopkg.in
└── modules.txt12 directories, 9 files
````internal` folder is created and inside is declaration of GQL handler for `mutation`, `query`, and `resolver`.
The `storage` package used for connecting to database / cache / file storage.
The initialization happened in `cmd/main.go`. In `main.go`, we define how we can inject `TODO Storage` to GraphQL resolver. Later, `TODO Storage` used by `mutation` and `query` resolver.
## Unit Testing
We use `testify` and `mockery` for unit testing approach. This may not be the right taste for some people. For me, this is the robust and easiest way to do.
Testing Coverage Results using `package-cover`:
```text
------------------------------------------------------------------------------------------------------------------------------------------
| Branch | Dir | |
| Cov% | Cov | Stmts | Cov% | Cov | Stmts | Package |
------------------------------------------------------------------------------------------------------------------------------------------
| 100.00 | 0 | 0 | 100.00 | 0 | 0 | github.com/rhzs/gqlgen-todos/graph/ |
| 100.00 | 0 | 0 | 100.00 | 0 | 0 | github.com/rhzs/gqlgen-todos/graph/model/ |
| 100.00 | 5 | 5 | 100.00 | 5 | 5 | github.com/rhzs/gqlgen-todos/internal/mutation/ |
| 100.00 | 2 | 2 | 100.00 | 2 | 2 | github.com/rhzs/gqlgen-todos/internal/query/ |
| 100.00 | 3 | 3 | 100.00 | 3 | 3 | github.com/rhzs/gqlgen-todos/internal/resolver/ |
| 100.00 | 3 | 3 | 100.00 | 3 | 3 | github.com/rhzs/gqlgen-todos/internal/storage/ |
------------------------------------------------------------------------------------------------------------------------------------------
```## Credit
Made in Jakarta with love (c) 2023.