https://github.com/theopenlane/gqlgen-plugins
plugins used in the gqlgen code generation lifecycle
https://github.com/theopenlane/gqlgen-plugins
codegen gqlgen gqlgen-hooks graphql
Last synced: 5 months ago
JSON representation
plugins used in the gqlgen code generation lifecycle
- Host: GitHub
- URL: https://github.com/theopenlane/gqlgen-plugins
- Owner: theopenlane
- License: apache-2.0
- Created: 2024-08-25T22:14:45.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2026-01-29T01:37:11.000Z (6 months ago)
- Last Synced: 2026-01-29T11:17:43.298Z (6 months ago)
- Topics: codegen, gqlgen, gqlgen-hooks, graphql
- Language: Go
- Homepage:
- Size: 271 KB
- Stars: 6
- Watchers: 1
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
[](https://goreportcard.com/report/github.com/theopenlane/gqlgen-plugins)
[](https://buildkite.com/theopenlane/gqlgen-plugins?branch=main)
[](https://sonarcloud.io/summary/new_code?id=theopenlane_gqlgen-plugins)
[](https://opensource.org/licenses/Apache-2.0)
# gqlgen-plugins
[gqlgen](https://gqlgen.com/reference/plugins/) provides a way to hook into the
gqlgen code generation lifecycle. This repo contains several hooks that can be
used:
- bulkgen
- resovlergen
- searchgen
- fieldgen
## ResolverGen
This hook will override the default generated resolver functions with the
templates for CRUD operations.
## BulkGen
Creates resolvers to do bulk operations for a schema for both bulk input or a
csv file upload input.
## FieldGen
This plugin is designed to programmatically add additional fields to your graphql schema based on existing fields
in the schema or the schema name
## SearchGen
Creates search resolvers to search on fields within the ent schema. You must
pass in the package import name of the `generated` ent code, e.g.
`github.com/theopenlane/core/internal/ent/generated`. If the package is not
named `generated` it is added as an alias.
```go
api.AddPlugin(searchgen.New("github.com/theopenlane/core/internal/ent/generated")), // add the search plugin
```
## Usage
Add the plugins to the `generate.go` `main` function to be included in the
setup:
```go
func main() {
cfg, err := config.LoadConfigFromDefaultLocations()
if err != nil {
fmt.Fprintln(os.Stderr, "failed to load config", err.Error())
os.Exit(2)
}
if err := api.Generate(cfg,
api.ReplacePlugin(resolvergen.New()), // replace the resolvergen plugin
api.AddPlugin(bulkgen.New()), // add the bulkgen plugin
api.AddPlugin(searchgen.New("github.com/theopenlane/core/internal/ent/generated")), // add the search plugin
); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(3)
}
}
```