Skip to content

Commit d3e98e6

Browse files
committed
Update docs to use go 1.24 tool dependencies
1 parent b7a335f commit d3e98e6

File tree

9 files changed

+21
-41
lines changed

9 files changed

+21
-41
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
### Minimal graphql.schema and models to reproduce
66

77
### versions
8-
- `go run github.com/99designs/gqlgen version`?
8+
- `go tool gqlgen version`?
99
- `go version`?

.github/workflows/check-init

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ export GO111MODULE=on
55
gqlgen_dir=$(pwd)
66
cd "$(mktemp -d)"
77
go mod init inittest
8-
printf '//go:build tools\npackage tools\nimport _ "github.com/99designs/gqlgen"' | gofmt > tools.go
9-
go mod tidy
8+
go get -tool github.com/99designs/gqlgen
109
go mod edit -replace=github.com/99designs/gqlgen="$gqlgen_dir"
11-
go mod tidy
1210

13-
if ! go run github.com/99designs/gqlgen init ; then
11+
if ! go tool gqlgen init ; then
1412
echo "gqlgen init failed"
1513
exit 125
1614
fi
1715

18-
if ! go run github.com/99designs/gqlgen generate ; then
16+
if ! go tool gqlgen generate ; then
1917
echo "gqlgen generate failed"
2018
exit 125
2119
fi

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ cd example
2222
go mod init example
2323
```
2424

25-
2. Add `github.com/99designs/gqlgen` to your [project's tools.go](https://go.dev/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module)
25+
2. Add `github.com/99designs/gqlgen` to your project, as a [tool dependency](https://go.dev/doc/modules/managing-dependencies#tools)
2626

2727
```shell
28-
printf '//go:build tools\npackage tools\nimport (_ "github.com/99designs/gqlgen"\n _ "github.com/99designs/gqlgen/graphql/introspection")' | gofmt > tools.go
29-
go mod tidy
28+
go get -tool github.com/99designs/gqlgen
3029
```
3130

3231
3. Initialise gqlgen config and generate models
3332

3433
```shell
35-
go run github.com/99designs/gqlgen init
36-
go mod tidy
34+
go tool gqlgen init
3735
```
3836

3937
4. Start the graphql server

_examples/mini-habr-with-subscriptions/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ For testing the API, you can use any GraphQL clients, such as Insomnia, Postman,
226226
`│ └──` [`interface.go`](./internal/storage/interface.go) (Interface for data storage (PostgreSQL, in-memory))<br>
227227
`├── migrations/`<br>
228228
`│ └──` [`001_create_tables.up.sql`](./migrations/001_create_tables.up.sql) (SQL script for database migration (creating tables))<br>
229-
`├── tools/`<br>
230-
`│ └──` [`tools.go`](./tools/tools.go) (Tools for gqlgen code generation)<br>
231229
`├──` [`.env`](./.env) (Environment variables file (database settings, Redis, etc.))<br>
232230
`├──` [`.gitignore`](./.gitignore) (List of ignored files and directories for Git)<br>
233231
`├──` [`docker-compose.yml`](./docker-compose.yml) (Docker Compose configuration for launching the application and dependencies)<br>
@@ -246,4 +244,4 @@ For testing the API, you can use any GraphQL clients, such as Insomnia, Postman,
246244
* GraphQL (gqlgen)
247245
* PostgreSQL 17
248246
* Redis 9
249-
* Docker & Docker Compose
247+
* Docker & Docker Compose

docs/content/getting-started.md

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,23 @@ cd gqlgen-todos
2424
go mod init github.com/[username]/gqlgen-todos
2525
```
2626

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).
2828

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
4029
```shell
41-
go mod tidy
30+
go get -tool github.com/99designs/gqlgen
4231
```
4332

4433
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)
4534
```shell
46-
go get -d github.com/99designs/gqlgen@VERSION
35+
go get -tool github.com/99designs/gqlgen@VERSION
4736
```
4837

49-
50-
5138
## Building the server
5239

5340
### Create the project skeleton
5441

5542
```shell
56-
go run github.com/99designs/gqlgen init
43+
go tool gqlgen init
5744
```
5845

5946
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 {
239226
}
240227
```
241228

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`.
246230

247231
Now if we look in `graph/schema.resolvers.go` we can see a new resolver, lets implement it and fix `CreateTodo`.
248232
```go
@@ -267,7 +251,7 @@ func (r *todoResolver) User(ctx context.Context, obj *model.Todo) (*model.User,
267251
At the top of our `resolver.go`, between `package` and `import`, add the following line:
268252

269253
```go
270-
//go:generate go run github.com/99designs/gqlgen generate
254+
//go:generate go tool gqlgen generate
271255
```
272256

273257
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:

docs/content/recipes/federation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ federation:
3535
For each server to be federated we will create a new gqlgen project.
3636

3737
```bash
38-
go run github.com/99designs/gqlgen
38+
go tool gqlgen generate
3939
```
4040

4141
Update the schema to reflect the federated example
@@ -61,7 +61,7 @@ extend type Product @key(fields: "upc") {
6161
and regenerate
6262

6363
```bash
64-
go run github.com/99designs/gqlgen
64+
go tool gqlgen generate
6565
```
6666

6767
then implement the resolvers

docs/content/recipes/modelgen-hook.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func main() {
6464
}
6565
```
6666

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).
6868

6969
Now you can run `go generate ./...` to generate the code.
7070

docs/content/recipes/subscriptions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ type Subscription {
158158

159159
## Implementing your Resolver
160160

161-
After regenerating your code with `go run github.com/99designs/gqlgen generate` you'll find a
161+
After regenerating your code with `go tool gqlgen generate` you'll find a
162162
new resolver for your subscription. It will look like any other resolver, except it expects
163163
a `<-chan *model.Time` (or whatever your type is). This is a
164164
[channel](https://go.dev/tour/concurrency/2). Channels in Go are used to send objects to a

docs/content/reference/plugins.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ func main() {
4949

5050
```
5151

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.
5355

5456
## Writing a plugin
5557

0 commit comments

Comments
 (0)