Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instructions for enabling autobinding #2079

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions docs/content/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,17 @@ This example is great, but in the real world fetching most objects is expensive.
todo unless the user actually asked for it. So lets replace the generated `Todo` model with something slightly more
realistic.

Create a new file called `graph/model/todo.go`
First let's enable `autobind`, allowing gqlgen to use your custom models if it can find them rather than generating them. We do this by uncommenting the `autobind` config line in `gqlgen.yml`:

```yml
# gqlgen will search for any type names in the schema in these go packages
# if they match it will use them, otherwise it will generate them.
autobind:
- "github.com/[username]/gqlgen-todos/graph/model"
```

Next, create a new file called `graph/model/todo.go`

```go
package model

Expand All @@ -205,10 +215,6 @@ type Todo struct {
}
```

> Note
>
> By default gqlgen will use any models in the model directory that match on name, this can be configured in `gqlgen.yml`.

And run `go run github.com/99designs/gqlgen generate`.

>
Expand Down