Skip to content

Commit

Permalink
Updated the documentation on using the plugins (#2553)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrey Leybovich <[email protected]>
  • Loading branch information
aleybovich and Andrey Leybovich authored Feb 15, 2023
1 parent cf1607a commit e36095f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/content/recipes/modelgen-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion docs/content/reference/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e36095f

Please sign in to comment.