From 6a5257134f45a85d65dc840fec268aa6ef748075 Mon Sep 17 00:00:00 2001 From: John Starich Date: Fri, 17 Nov 2023 12:14:11 -0600 Subject: [PATCH] Fix introspect options not ready for use immediately (#34) * 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 --- .github/workflows/ci.yml | 7 +++++-- introspection.go | 22 +++++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bcb51cd..9af74d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 ./... @@ -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 diff --git a/introspection.go b/introspection.go index 0eae53a..a0238d6 100644 --- a/introspection.go +++ b/introspection.go @@ -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