Skip to content

Commit

Permalink
go 1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Jul 26, 2020
1 parent ce964c1 commit 9793856
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 92 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/check-linting
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -euo pipefail

curl -sL --fail https://github.com/golangci/golangci-lint/releases/download/v1.23.2/golangci-lint-1.23.2-linux-amd64.tar.gz | tar zxv --strip-components=1 --dir=/go/bin
mkdir /tmp/golangci
curl -sL --fail https://github.com/golangci/golangci-lint/releases/download/v1.29.0/golangci-lint-1.29.0-linux-amd64.tar.gz | tar zxv --strip-components=1 --dir=/tmp/golangci

golangci-lint run
/tmp/golangci/golangci-lint run
63 changes: 0 additions & 63 deletions .github/workflows/ci.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Integration
on: [push, pull_request]

jobs:
integration:
runs-on: ubuntu-latest
timeout-minutes: 3
container: alpine:3.10
steps:
- uses: actions/checkout@v1
- run: apk add --no-cache --no-progress nodejs npm go musl-dev git bash
- run: go mod download
- run: cd integration ; npm install
- run: .github/workflows/check-integration

federation:
runs-on: ubuntu-latest
container: alpine:3.10
steps:
- uses: actions/checkout@v1
- run: apk add --no-cache --no-progress nodejs npm go musl-dev git bash
- run: go mod download
- run: cd example/federation ; npm install
- run: .github/workflows/check-federation
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint
on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with: { go-version: 1.14 }
- run: go mod download
- run: .github/workflows/check-fmt
- run: .github/workflows/check-linting
- run: .github/workflows/check-generate

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with: { go-version: 1.14 }
- run: go mod download
- run: .github/workflows/check-coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Test
on: [push, pull_request]

jobs:
test:
strategy:
matrix:
go: [1.12, 1.14]
os: [ubuntu-latest, windows-latest]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- run: go mod download
- run: go test -race ./...
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ linters:
- gocritic
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
Expand Down
2 changes: 1 addition & 1 deletion codegen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func (f *Field) ShortResolverDeclaration() string {
}

func (f *Field) ComplexitySignature() string {
res := fmt.Sprintf("func(childComplexity int")
res := "func(childComplexity int"
for _, arg := range f.Args {
res += fmt.Sprintf(", %s %s", arg.VarName, templates.CurrentImports.LookupType(arg.TypeReference.GO))
}
Expand Down
14 changes: 8 additions & 6 deletions codegen/testserver/directive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/stretchr/testify/require"
)

type ckey string

func TestDirectives(t *testing.T) {
resolvers := &Stub{}
ok := "Ok"
Expand Down Expand Up @@ -48,7 +50,7 @@ func TestDirectives(t *testing.T) {
}

resolvers.QueryResolver.DirectiveField = func(ctx context.Context) (*string, error) {
if s, ok := ctx.Value("request_id").(*string); ok {
if s, ok := ctx.Value(ckey("request_id")).(*string); ok {
return s, nil
}

Expand Down Expand Up @@ -149,7 +151,7 @@ func TestDirectives(t *testing.T) {
return next(ctx)
},
Logged: func(ctx context.Context, obj interface{}, next graphql.Resolver, id string) (interface{}, error) {
return next(context.WithValue(ctx, "request_id", &id))
return next(context.WithValue(ctx, ckey("request_id"), &id))
},
ToNull: func(ctx context.Context, obj interface{}, next graphql.Resolver) (interface{}, error) {
return nil, nil
Expand All @@ -172,13 +174,13 @@ func TestDirectives(t *testing.T) {
}))

srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
path, _ := ctx.Value("path").([]int)
return next(context.WithValue(ctx, "path", append(path, 1)))
path, _ := ctx.Value(ckey("path")).([]int)
return next(context.WithValue(ctx, ckey("path"), append(path, 1)))
})

srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
path, _ := ctx.Value("path").([]int)
return next(context.WithValue(ctx, "path", append(path, 2)))
path, _ := ctx.Value(ckey("path")).([]int)
return next(context.WithValue(ctx, ckey("path"), append(path, 2)))
})

c := client.New(srv)
Expand Down
10 changes: 5 additions & 5 deletions codegen/testserver/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ func TestMiddleware(t *testing.T) {
NewExecutableSchema(Config{Resolvers: resolvers}),
)
srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
path, _ := ctx.Value("path").([]int)
return next(context.WithValue(ctx, "path", append(path, 1)))
path, _ := ctx.Value(ckey("path")).([]int)
return next(context.WithValue(ctx, ckey("path"), append(path, 1)))
})

srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
path, _ := ctx.Value("path").([]int)
return next(context.WithValue(ctx, "path", append(path, 2)))
path, _ := ctx.Value(ckey("path")).([]int)
return next(context.WithValue(ctx, ckey("path"), append(path, 2)))
})

srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
Expand All @@ -58,7 +58,7 @@ func TestMiddleware(t *testing.T) {

called := false
resolvers.UserResolver.Friends = func(ctx context.Context, obj *User) ([]*User, error) {
assert.Equal(t, []int{1, 2, 1, 2}, ctx.Value("path"))
assert.Equal(t, []int{1, 2, 1, 2}, ctx.Value(ckey("path")))
called = true
return []*User{}, nil
}
Expand Down
8 changes: 4 additions & 4 deletions codegen/testserver/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ func TestSubscriptions(t *testing.T) {
NewExecutableSchema(Config{Resolvers: resolvers}),
)
srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
path, _ := ctx.Value("path").([]int)
return next(context.WithValue(ctx, "path", append(path, 1)))
path, _ := ctx.Value(ckey("path")).([]int)
return next(context.WithValue(ctx, ckey("path"), append(path, 1)))
})

srv.AroundFields(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) {
path, _ := ctx.Value("path").([]int)
return next(context.WithValue(ctx, "path", append(path, 2)))
path, _ := ctx.Value(ckey("path")).([]int)
return next(context.WithValue(ctx, ckey("path"), append(path, 2)))
})

c := client.New(srv)
Expand Down
6 changes: 4 additions & 2 deletions example/chat/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/99designs/gqlgen/graphql"
)

type ckey string

type resolver struct {
Rooms map[string]*Chatroom
mu sync.Mutex // nolint: structcheck
Expand All @@ -35,14 +37,14 @@ func New() Config {
},
Directives: DirectiveRoot{
User: func(ctx context.Context, obj interface{}, next graphql.Resolver, username string) (res interface{}, err error) {
return next(context.WithValue(ctx, "username", username))
return next(context.WithValue(ctx, ckey("username"), username))
},
},
}
}

func getUsername(ctx context.Context) string {
if username, ok := ctx.Value("username").(string); ok {
if username, ok := ctx.Value(ckey("username")).(string); ok {
return username
}
return ""
Expand Down
6 changes: 4 additions & 2 deletions example/todo/todo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
var you = &User{ID: 1, Name: "You"}
var them = &User{ID: 2, Name: "Them"}

type ckey string

func getUserId(ctx context.Context) int {
if id, ok := ctx.Value("userId").(int); ok {
if id, ok := ctx.Value(ckey("userId")).(int); ok {
return id
}
return you.ID
Expand Down Expand Up @@ -53,7 +55,7 @@ func New() Config {
return next(ctx)
}
c.Directives.User = func(ctx context.Context, obj interface{}, next graphql.Resolver, id int) (interface{}, error) {
return next(context.WithValue(ctx, "userId", id))
return next(context.WithValue(ctx, ckey("userId"), id))
}
return c
}
Expand Down
8 changes: 5 additions & 3 deletions graphql/handler/transport/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/vektah/gqlparser/v2/ast"
)

type ckey string

func TestWebsocket(t *testing.T) {
handler := testserver.New()
handler.AddTransport(transport.Websocket{})
Expand Down Expand Up @@ -194,7 +196,7 @@ func TestWebsocketInitFunc(t *testing.T) {
h := testserver.New()
h.AddTransport(transport.Websocket{
InitFunc: func(ctx context.Context, initPayload transport.InitPayload) (context.Context, error) {
return context.WithValue(ctx, "newkey", "newvalue"), nil
return context.WithValue(ctx, ckey("newkey"), "newvalue"), nil
},
})
srv := httptest.NewServer(h)
Expand Down Expand Up @@ -232,7 +234,7 @@ func TestWebsocketInitFunc(t *testing.T) {
t.Run("can return context for request from WebsocketInitFunc", func(t *testing.T) {
es := &graphql.ExecutableSchemaMock{
ExecFunc: func(ctx context.Context) graphql.ResponseHandler {
assert.Equal(t, "newvalue", ctx.Value("newkey"))
assert.Equal(t, "newvalue", ctx.Value(ckey("newkey")))
return graphql.OneShot(&graphql.Response{Data: []byte(`{"empty":"ok"}`)})
},
SchemaFunc: func() *ast.Schema {
Expand All @@ -248,7 +250,7 @@ func TestWebsocketInitFunc(t *testing.T) {

h.AddTransport(transport.Websocket{
InitFunc: func(ctx context.Context, initPayload transport.InitPayload) (context.Context, error) {
return context.WithValue(ctx, "newkey", "newvalue"), nil
return context.WithValue(ctx, ckey("newkey"), "newvalue"), nil
},
})

Expand Down
3 changes: 2 additions & 1 deletion internal/code/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func goModuleRoot(dir string) (string, bool) {
// ImportPathForDir takes a path and returns a golang import path for the package
func ImportPathForDir(dir string) (res string) {
dir, err := filepath.Abs(dir)

if err != nil {
panic(err)
}
Expand All @@ -99,4 +100,4 @@ func ImportPathForDir(dir string) (res string) {
return ""
}

var modregex = regexp.MustCompile("module (.*)\n")
var modregex = regexp.MustCompile(`module ([^\s]*)`)
1 change: 1 addition & 0 deletions internal/code/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

func TestImportPathForDir(t *testing.T) {
wd, err := os.Getwd()

require.NoError(t, err)

assert.Equal(t, "github.com/99designs/gqlgen/internal/code", ImportPathForDir(wd))
Expand Down
3 changes: 2 additions & 1 deletion internal/imports/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package imports

import (
"io/ioutil"
"strings"
"testing"

"github.com/99designs/gqlgen/internal/code"
Expand All @@ -13,7 +14,7 @@ func TestPrune(t *testing.T) {

b, err := Prune("testdata/unused.go", mustReadFile("testdata/unused.go"), &code.Packages{})
require.NoError(t, err)
require.Equal(t, string(mustReadFile("testdata/unused.expected.go")), string(b))
require.Equal(t, strings.Replace(string(mustReadFile("testdata/unused.expected.go")), "\r\n", "\n", -1), string(b))
}

func mustReadFile(filename string) []byte {
Expand Down
7 changes: 7 additions & 0 deletions internal/rewrite/rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ func New(importPath string) (*Rewriter, error) {
if len(pkgs) == 0 {
return nil, fmt.Errorf("package not found for importPath: %s", importPath)
}
if len(pkgs[0].Errors) != 0 {
for _, e := range pkgs[0].Errors {
if e.Kind == packages.ListError {
return nil, e
}
}
}

return &Rewriter{
pkg: pkgs[0],
Expand Down
Loading

0 comments on commit 9793856

Please sign in to comment.