diff --git a/docs/content/recipes/modelgen-hook.md b/docs/content/recipes/modelgen-hook.md index a4b47635fdd..e282da47a02 100644 --- a/docs/content/recipes/modelgen-hook.md +++ b/docs/content/recipes/modelgen-hook.md @@ -16,7 +16,13 @@ the generated data structure. First of all, we need to create a function that will mutate the generated model. Then we can attach the function to the plugin and use it like any other plugin. +Create `generate.go` file in the same folder as `resolver.go` (usually in `graph` folder) and add the following code: + ```go +//go:build ignore + +package main + import ( "fmt" "os" @@ -58,6 +64,10 @@ func main() { } ``` +In `resolver.go`, add `//go:generate go run generate.go` (or replace `//go:generate go run github.com/99designs/gqlgen generate` if you have it there). + +Now you can run `go generate ./...` to generate the code. + Now fields from generated models will contain a additional tag `orm_binding`. This schema: diff --git a/docs/content/reference/plugins.md b/docs/content/reference/plugins.md index b68f62aeebe..7c47e8f0344 100644 --- a/docs/content/reference/plugins.md +++ b/docs/content/reference/plugins.md @@ -10,8 +10,10 @@ default plugins you will need to create your own entrypoint: ## Using a plugin +To use a plugin during code generation, you need to create a new entry point. Create `generate.go` in the same folder as `resolver.go` with the following code: + ```go -// +build ignore +// go:build ignore package main @@ -47,6 +49,8 @@ func main() { ``` +In `resolver.go`, add `//go:generate go run generate.go`. Now you can run `go generate ./...` instead of `go run github.com/99designs/gqlgen generate` to generate the code. + ## Writing a plugin There are currently only two hooks: