You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/getting-started.md
+6-22Lines changed: 6 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,36 +24,23 @@ cd gqlgen-todos
24
24
go mod init github.com/[username]/gqlgen-todos
25
25
```
26
26
27
-
Next, create a `tools.go` file and add gqlgen as a [tool dependency for your module](https://go.dev/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module).
27
+
Next, add `github.com/99designs/gqlgen` to your project, as a [tool dependency](https://go.dev/doc/modules/managing-dependencies#tools).
28
28
29
-
```go
30
-
//go:build tools
31
-
32
-
package tools
33
-
34
-
import (
35
-
_ "github.com/99designs/gqlgen"
36
-
)
37
-
```
38
-
39
-
To automatically add the dependency to your `go.mod` run
40
29
```shell
41
-
go mod tidy
30
+
go get -tool github.com/99designs/gqlgen
42
31
```
43
32
44
33
By default you'll be using the latest version of gqlgen, but if you want to specify a particular version you can use `go get` (replacing `VERSION` with the particular version desired)
45
34
```shell
46
-
go get -d github.com/99designs/gqlgen@VERSION
35
+
go get -tool github.com/99designs/gqlgen@VERSION
47
36
```
48
37
49
-
50
-
51
38
## Building the server
52
39
53
40
### Create the project skeleton
54
41
55
42
```shell
56
-
go run github.com/99designs/gqlgen init
43
+
go tool gqlgen init
57
44
```
58
45
59
46
This will create our suggested package layout. You can modify these paths in gqlgen.yml if you need to.
@@ -239,10 +226,7 @@ type Todo struct {
239
226
}
240
227
```
241
228
242
-
And run `go run github.com/99designs/gqlgen generate`.
243
-
244
-
>
245
-
> If you run into this error `package github.com/99designs/gqlgen: no Go files` while executing the `generate` command above, follow the instructions in [this](https://github.com/99designs/gqlgen/issues/800#issuecomment-888908950) comment for a possible solution.
229
+
And run `go tool gqlgen generate`.
246
230
247
231
Now if we look in `graph/schema.resolvers.go` we can see a new resolver, lets implement it and fix `CreateTodo`.
At the top of our `resolver.go`, between `package` and `import`, add the following line:
268
252
269
253
```go
270
-
//go:generate go run github.com/99designs/gqlgen generate
254
+
//go:generate go tool gqlgen generate
271
255
```
272
256
273
257
This magic comment tells `go generate` what command to run when we want to regenerate our code. To run go generate recursively over your entire project, use this command:
Copy file name to clipboardExpand all lines: docs/content/recipes/modelgen-hook.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ func main() {
64
64
}
65
65
```
66
66
67
-
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).
67
+
In `resolver.go`, add `//go:generate go run generate.go` (or replace `//go:generate go tool gqlgen` if you have it there).
68
68
69
69
Now you can run `go generate ./...` to generate the code.
Copy file name to clipboardExpand all lines: docs/content/reference/plugins.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,9 @@ func main() {
49
49
50
50
```
51
51
52
-
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.
52
+
In `resolver.go`, add `//go:generate go run generate.go` (or replace `//go:generate go tool gqlgen` if you have it there).
53
+
54
+
Now you can run `go generate ./...` to generate code using your plugin.
0 commit comments