Skip to content

Commit

Permalink
Merge pull request #1610 from 99designs/go-1.17
Browse files Browse the repository at this point in the history
Update to go 1.17
  • Loading branch information
mtibben authored Sep 13, 2021
2 parents 1116ea6 + 9162c53 commit 890f5f6
Show file tree
Hide file tree
Showing 32 changed files with 194 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-init
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail

cd example/init

go get github.com/99designs/gqlgen
go get -d github.com/99designs/gqlgen

if { go run github.com/99designs/gqlgen init 2>&1 >&3 3>&- | grep '^' >&2; } 3>&1; then
echo "gqlgen init failed validation"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
integration:
runs-on: ubuntu-latest
timeout-minutes: 3
container: golang:1.13-alpine
container: golang:1.17-alpine
steps:
- uses: actions/checkout@v1
- run: apk add --no-cache --no-progress nodejs npm git bash
Expand All @@ -15,7 +15,7 @@ jobs:

federation:
runs-on: ubuntu-latest
container: golang:1.13-alpine
container: golang:1.17-alpine
steps:
- uses: actions/checkout@v1
- run: apk add --no-cache --no-progress nodejs npm git bash
Expand All @@ -25,7 +25,7 @@ jobs:

init:
runs-on: ubuntu-latest
container: golang:1.16-alpine
container: golang:1.17-alpine
steps:
- uses: actions/checkout@v1
- run: apk add --no-cache --no-progress alpine-sdk bash
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with: { go-version: 1.14 }
with: { go-version: 1.17 }
- run: go mod download
- run: .github/workflows/check-fmt
- run: .github/workflows/check-linting
Expand All @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with: { go-version: 1.14 }
with: { go-version: 1.17 }
- run: go mod download
- run: .github/workflows/check-coverage
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
strategy:
matrix:
go: [1.13, 1.14]
go: 1.17
os: [ubuntu-latest, windows-latest]

runs-on: ${{ matrix.os }}
Expand Down
22 changes: 11 additions & 11 deletions api/generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"fmt"
"syscall"

"github.com/99designs/gqlgen/codegen"
Expand All @@ -9,7 +10,6 @@ import (
"github.com/99designs/gqlgen/plugin/federation"
"github.com/99designs/gqlgen/plugin/modelgen"
"github.com/99designs/gqlgen/plugin/resolvergen"
"github.com/pkg/errors"
)

func Generate(cfg *config.Config, option ...Option) error {
Expand Down Expand Up @@ -40,7 +40,7 @@ func Generate(cfg *config.Config, option ...Option) error {
}

if err := cfg.LoadSchema(); err != nil {
return errors.Wrap(err, "failed to load schema")
return fmt.Errorf("failed to load schema: %w", err)
}

for _, p := range plugins {
Expand All @@ -53,50 +53,50 @@ func Generate(cfg *config.Config, option ...Option) error {

// LoadSchema again now we have everything
if err := cfg.LoadSchema(); err != nil {
return errors.Wrap(err, "failed to load schema")
return fmt.Errorf("failed to load schema: %w", err)
}

if err := cfg.Init(); err != nil {
return errors.Wrap(err, "generating core failed")
return fmt.Errorf("generating core failed: %w", err)
}

for _, p := range plugins {
if mut, ok := p.(plugin.ConfigMutator); ok {
err := mut.MutateConfig(cfg)
if err != nil {
return errors.Wrap(err, p.Name())
return fmt.Errorf("%s: %w", p.Name(), err)
}
}
}
// Merge again now that the generated models have been injected into the typemap
data, err := codegen.BuildData(cfg)
if err != nil {
return errors.Wrap(err, "merging type systems failed")
return fmt.Errorf("merging type systems failed: %w", err)
}

if err = codegen.GenerateCode(data); err != nil {
return errors.Wrap(err, "generating core failed")
return fmt.Errorf("generating core failed: %w", err)
}
if err = cfg.Packages.ModTidy(); err != nil {
return errors.Wrap(err, "tidy failed")
return fmt.Errorf("tidy failed: %w", err)
}

for _, p := range plugins {
if mut, ok := p.(plugin.CodeGenerator); ok {
err := mut.GenerateCode(data)
if err != nil {
return errors.Wrap(err, p.Name())
return fmt.Errorf("%s: %w", p.Name(), err)
}
}
}

if err = codegen.GenerateCode(data); err != nil {
return errors.Wrap(err, "generating core failed")
return fmt.Errorf("generating core failed: %w", err)
}

if !cfg.SkipValidation {
if err := validate(cfg); err != nil {
return errors.Wrap(err, "validation failed")
return fmt.Errorf("validation failed: %w", err)
}
}

Expand Down
8 changes: 4 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (p *Client) Post(query string, response interface{}, options ...Option) err
func (p *Client) RawPost(query string, options ...Option) (*Response, error) {
r, err := p.newRequest(query, options...)
if err != nil {
return nil, fmt.Errorf("build: %s", err.Error())
return nil, fmt.Errorf("build: %w", err)
}

w := httptest.NewRecorder()
Expand All @@ -97,7 +97,7 @@ func (p *Client) RawPost(query string, options ...Option) (*Response, error) {
respDataRaw := &Response{}
err = json.Unmarshal(w.Body.Bytes(), &respDataRaw)
if err != nil {
return nil, fmt.Errorf("decode: %s", err.Error())
return nil, fmt.Errorf("decode: %w", err)
}

return respDataRaw, nil
Expand All @@ -123,7 +123,7 @@ func (p *Client) newRequest(query string, options ...Option) (*http.Request, err
case "application/json":
requestBody, err := json.Marshal(bd)
if err != nil {
return nil, fmt.Errorf("encode: %s", err.Error())
return nil, fmt.Errorf("encode: %w", err)
}
bd.HTTP.Body = ioutil.NopCloser(bytes.NewBuffer(requestBody))
default:
Expand All @@ -141,7 +141,7 @@ func unpack(data interface{}, into interface{}) error {
ZeroFields: true,
})
if err != nil {
return fmt.Errorf("mapstructure: %s", err.Error())
return fmt.Errorf("mapstructure: %w", err)
}

return d.Decode(data)
Expand Down
18 changes: 9 additions & 9 deletions client/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,37 @@ func (p *Client) WebsocketOnce(query string, resp interface{}, options ...Option
func (p *Client) WebsocketWithPayload(query string, initPayload map[string]interface{}, options ...Option) *Subscription {
r, err := p.newRequest(query, options...)
if err != nil {
return errorSubscription(fmt.Errorf("request: %s", err.Error()))
return errorSubscription(fmt.Errorf("request: %w", err))
}

requestBody, err := ioutil.ReadAll(r.Body)
if err != nil {
return errorSubscription(fmt.Errorf("parse body: %s", err.Error()))
return errorSubscription(fmt.Errorf("parse body: %w", err))
}

srv := httptest.NewServer(p.h)
host := strings.Replace(srv.URL, "http://", "ws://", -1)
c, _, err := websocket.DefaultDialer.Dial(host+r.URL.Path, r.Header)

if err != nil {
return errorSubscription(fmt.Errorf("dial: %s", err.Error()))
return errorSubscription(fmt.Errorf("dial: %w", err))
}

initMessage := operationMessage{Type: connectionInitMsg}
if initPayload != nil {
initMessage.Payload, err = json.Marshal(initPayload)
if err != nil {
return errorSubscription(fmt.Errorf("parse payload: %s", err.Error()))
return errorSubscription(fmt.Errorf("parse payload: %w", err))
}
}

if err = c.WriteJSON(initMessage); err != nil {
return errorSubscription(fmt.Errorf("init: %s", err.Error()))
return errorSubscription(fmt.Errorf("init: %w", err))
}

var ack operationMessage
if err = c.ReadJSON(&ack); err != nil {
return errorSubscription(fmt.Errorf("ack: %s", err.Error()))
return errorSubscription(fmt.Errorf("ack: %w", err))
}

if ack.Type != connectionAckMsg {
Expand All @@ -92,15 +92,15 @@ func (p *Client) WebsocketWithPayload(query string, initPayload map[string]inter

var ka operationMessage
if err = c.ReadJSON(&ka); err != nil {
return errorSubscription(fmt.Errorf("ack: %s", err.Error()))
return errorSubscription(fmt.Errorf("ack: %w", err))
}

if ka.Type != connectionKaMsg {
return errorSubscription(fmt.Errorf("expected ack message, got %#v", ack))
}

if err = c.WriteJSON(operationMessage{Type: startMsg, ID: "1", Payload: requestBody}); err != nil {
return errorSubscription(fmt.Errorf("start: %s", err.Error()))
return errorSubscription(fmt.Errorf("start: %w", err))
}

return &Subscription{
Expand All @@ -125,7 +125,7 @@ func (p *Client) WebsocketWithPayload(query string, initPayload map[string]inter
var respDataRaw Response
err = json.Unmarshal(op.Payload, &respDataRaw)
if err != nil {
return fmt.Errorf("decode: %s", err.Error())
return fmt.Errorf("decode: %w", err)
}

// we want to unpack even if there is an error, so we can see partial responses
Expand Down
6 changes: 3 additions & 3 deletions cmd/gen.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cmd

import (
"os"
"errors"
"io/fs"

"github.com/99designs/gqlgen/api"
"github.com/99designs/gqlgen/codegen/config"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)

Expand All @@ -26,7 +26,7 @@ var genCmd = &cli.Command{
}
} else {
cfg, err = config.LoadConfigFromDefaultLocations()
if os.IsNotExist(errors.Cause(err)) {
if errors.Is(err, fs.ErrNotExist) {
cfg, err = config.LoadDefaultConfig()
}

Expand Down
Loading

0 comments on commit 890f5f6

Please sign in to comment.