Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sijad/entgql
CRUD gqlgen code generator for ent models
https://github.com/sijad/entgql
code-generator crud ent gqlgen graphql
Last synced: about 2 months ago
JSON representation
CRUD gqlgen code generator for ent models
- Host: GitHub
- URL: https://github.com/sijad/entgql
- Owner: sijad
- License: mit
- Created: 2020-09-08T19:50:33.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-17T18:18:43.000Z (over 4 years ago)
- Last Synced: 2024-11-16T12:52:34.750Z (about 2 months ago)
- Topics: code-generator, crud, ent, gqlgen, graphql
- Language: Go
- Homepage:
- Size: 65.4 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
🚧🚧 this is pre-alpha software 🚧🚧
entgql
Simple, Efficient, CRUD GraphQL API Generator for ent. and gqlgen### Quick Start
it's recommended to install entgql using [Go modules](https://github.com/golang/go/wiki/Modules#quick-start).
1. create [a new gqlgen project](https://gqlgen.com/getting-started/)
2. [install ent.](https://entgo.io/docs/getting-started/) and generate your models
3. install entgql by running `go get github.com/sijad/entgql/cmd/entgql`
4. generate CRUD code for your ent schema using `go run github.com/sijad/entgql/cmd/entgql generate ./ent/schema`
5. edit `./graph/resolver.go` and add ent client to the resolver struct:
```diff
-type Resolver struct{}
+import "your.com/project/path/ent"
+
+type Resolver struct {
+ EntClient *ent.Client
+}
```
6. edit `./server.go` to [create a new client](https://entgo.io/docs/crud/#create-a-new-client) and pass it to resolvers:
```diff
+import "your.com/project/path/ent"
+import _ "your.com/dialect/driver"func main() {
// ...
+ client, err := ent.Open("dialect-name", "dialet-options")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer client.Close()- srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
+ srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{EntClient: client}}))
// ...
```
7. start your GraphQL server `go run server.go`### Credits
inspired by [Nexus](https://www.nexusjs.org/) and [PostGraphile](https://www.graphile.org/postgraphile/)