Skip to content

Commit

Permalink
Fix introspect options not ready for use immediately (#34)
Browse files Browse the repository at this point in the history
* Fix introspect options not ready for use immediately
Uncovered by Go 1.21s behavior change for context.TODO() != context.Background().
Change log for Go 1.21: https://go.dev/doc/go1.21#contextpkgcontext

* Run tests on Go 1.21
  • Loading branch information
JohnStarich authored Nov 17, 2023
1 parent 05d9531 commit 6a52571
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.18.x
go-version: 1.21.x
- name: Lint
run: go vet ./...

Expand All @@ -28,7 +28,10 @@ jobs:
- 1.15.x
- 1.16.x
- 1.17.x
- ^1.18 # Latest version of Go
- 1.18.x
- 1.19.x
- 1.20.x
- ^1.21 # Latest version of Go
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
Expand Down
22 changes: 9 additions & 13 deletions introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,23 @@ func mergeIntrospectOptions(opts ...*IntrospectOptions) *IntrospectOptions {
// IntrospectWithMiddlewares returns an instance of graphql.IntrospectOptions with given middlewares
// to be pass to an instance of a graphql.Queryer by the IntrospectOptions.Apply function
func IntrospectWithMiddlewares(wares ...NetworkMiddleware) *IntrospectOptions {
return &IntrospectOptions{
mergeFunc: func(opts *IntrospectOptions) {
opts.wares = append(opts.wares, wares...)
},
wares: wares,
}
return introspectOptsFunc(func(opts *IntrospectOptions) {
opts.wares = append(opts.wares, wares...)
})
}

// IntrospectWithHTTPClient returns an instance of graphql.IntrospectOptions with given client
// to be pass to an instance of a graphql.Queryer by the IntrospectOptions.Apply function
func IntrospectWithHTTPClient(client *http.Client) *IntrospectOptions {
return &IntrospectOptions{
mergeFunc: func(opts *IntrospectOptions) {
opts.client = client
},
client: client,
}
return introspectOptsFunc(func(opts *IntrospectOptions) {
opts.client = client
})
}

func introspectOptsFunc(fn func(opts *IntrospectOptions)) *IntrospectOptions {
return &IntrospectOptions{mergeFunc: fn}
opts := &IntrospectOptions{mergeFunc: fn}
opts.mergeFunc(opts)
return opts
}

// IntrospectWithHTTPClient returns an instance of graphql.IntrospectOptions with given context
Expand Down

0 comments on commit 6a52571

Please sign in to comment.