Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Feb 9, 2020
1 parent 30e2375 commit e4530da
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/99designs/gqlgen
go 1.12

require (
github.com/agnivade/levenshtein v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-chi/chi v3.3.2+incompatible
github.com/gogo/protobuf v1.0.0 // indirect
Expand All @@ -25,7 +26,7 @@ require (
github.com/stretchr/testify v1.3.0
github.com/urfave/cli v1.20.0
github.com/vektah/dataloaden v0.2.1-0.20190515034641-a19b9a6e7c9e
github.com/vektah/gqlparser v1.3.1
github.com/vektah/gqlparser v1.3.2-0.20200209091329-fcdc57498356
golang.org/x/tools v0.0.0-20200114235610-7ae403b6b589
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.2
Expand Down
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
github.com/agnivade/levenshtein v1.0.1 h1:3oJU7J3FGFmyhn8KHjmVaZCN5hxTr7GxgRue+sxIXdQ=
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
github.com/agnivade/levenshtein v1.0.3 h1:M5ZnqLOoZR8ygVq0FfkXsNOKzMCk0xRiow0R5+5VkQ0=
github.com/agnivade/levenshtein v1.0.3/go.mod h1:4SFRZbbXWLF4MU1T9Qg0pGgH3Pjs+t6ie5efyrwRJXs=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/trifles v0.0.0-20190318185328-a8d75aae118c/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/go-chi/chi v3.3.2+incompatible h1:uQNcQN3NsV1j4ANsPh42P4ew4t6rnRbJb8frvpp31qQ=
github.com/go-chi/chi v3.3.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/gogo/protobuf v1.0.0 h1:2jyBKDKU/8v3v2xVR2PtiWQviFUyiaGk2rpfyFT8rTM=
Expand Down Expand Up @@ -59,8 +63,16 @@ github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/vektah/dataloaden v0.2.1-0.20190515034641-a19b9a6e7c9e h1:+w0Zm/9gaWpEAyDlU1eKOuk5twTjAjuevXqcJJw8hrg=
github.com/vektah/dataloaden v0.2.1-0.20190515034641-a19b9a6e7c9e/go.mod h1:/HUdMve7rvxZma+2ZELQeNh88+003LL7Pf/CZ089j8U=
github.com/vektah/gqlparser v1.2.2-0.20200207070222-bc3e68891810 h1:rWT63vqVwBxR3HWs/Uv3BaNNOjIOOKgNQ+eWk+q+pKo=
github.com/vektah/gqlparser v1.2.2-0.20200207070222-bc3e68891810/go.mod h1:bkVf0FX+Stjg/MHnm8mEyubuaArhNEqfQhF+OTiAL74=
github.com/vektah/gqlparser v1.2.2-0.20200209090035-1cdd9c855be2 h1:QESfBEW4Fdj70rV3Sz5+MkyFLuv60irXbW1cazk8hmM=
github.com/vektah/gqlparser v1.2.2-0.20200209090035-1cdd9c855be2/go.mod h1:bkVf0FX+Stjg/MHnm8mEyubuaArhNEqfQhF+OTiAL74=
github.com/vektah/gqlparser v1.2.2-0.20200209090733-6a7b2cdda12f h1:A1vVD0WMvyaSdCMlz5liWdMV4IFCVXqK1T+MQnQeNxI=
github.com/vektah/gqlparser v1.2.2-0.20200209090733-6a7b2cdda12f/go.mod h1:bkVf0FX+Stjg/MHnm8mEyubuaArhNEqfQhF+OTiAL74=
github.com/vektah/gqlparser v1.3.1 h1:8b0IcD3qZKWJQHSzynbDlrtP3IxVydZ2DZepCGofqfU=
github.com/vektah/gqlparser v1.3.1/go.mod h1:bkVf0FX+Stjg/MHnm8mEyubuaArhNEqfQhF+OTiAL74=
github.com/vektah/gqlparser v1.3.2-0.20200209091329-fcdc57498356 h1:v9PLvniug2CnIsccJr+eULcGQL0zQ2pgLyxDM18YMCM=
github.com/vektah/gqlparser v1.3.2-0.20200209091329-fcdc57498356/go.mod h1:bkVf0FX+Stjg/MHnm8mEyubuaArhNEqfQhF+OTiAL74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
Expand Down
12 changes: 7 additions & 5 deletions graphql/context_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package graphql
import (
"context"
"time"

"github.com/vektah/gqlparser/ast"
)

type key string
Expand Down Expand Up @@ -39,13 +41,13 @@ type FieldStats struct {
Completed time.Time
}

func (r *FieldContext) Path() []interface{} {
var path []interface{}
func (r *FieldContext) Path() ast.Path {
var path ast.Path
for it := r; it != nil; it = it.Parent {
if it.Index != nil {
path = append(path, *it.Index)
path = append(path, ast.PathIndex(*it.Index))
} else if it.Field.Field != nil {
path = append(path, it.Field.Alias)
path = append(path, ast.PathName(it.Field.Alias))
}
}

Expand Down Expand Up @@ -75,7 +77,7 @@ func WithFieldContext(ctx context.Context, rc *FieldContext) context.Context {
return context.WithValue(ctx, resolverCtx, rc)
}

func equalPath(a []interface{}, b []interface{}) bool {
func equalPath(a ast.Path, b ast.Path) bool {
if len(a) != len(b) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion graphql/context_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestAddError(t *testing.T) {
AddError(ctx, errors.New("bar"))
AddError(ctx, &gqlerror.Error{
Message: "foo3",
Path: append(child.Path(), "works"),
Path: append(child.Path(), ast.PathName("works")),
})

specs := []struct {
Expand Down
3 changes: 2 additions & 1 deletion graphql/handler/apollotracing/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/99designs/gqlgen/graphql"
"github.com/vektah/gqlparser/ast"
)

type (
Expand All @@ -30,7 +31,7 @@ type (
}

ResolverExecution struct {
Path []interface{} `json:"path"`
Path ast.Path `json:"path"`
ParentType string `json:"parentType"`
FieldName string `json:"fieldName"`
ReturnType string `json:"returnType"`
Expand Down
4 changes: 2 additions & 2 deletions graphql/handler/apollotracing/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"time"

"github.com/99designs/gqlgen/graphql"

"github.com/99designs/gqlgen/graphql/handler/apollotracing"
"github.com/99designs/gqlgen/graphql/handler/extension"
"github.com/99designs/gqlgen/graphql/handler/lru"
"github.com/99designs/gqlgen/graphql/handler/testserver"
"github.com/99designs/gqlgen/graphql/handler/transport"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vektah/gqlparser/ast"
"github.com/vektah/gqlparser/gqlerror"
)

Expand Down Expand Up @@ -59,7 +59,7 @@ func TestApolloTracing(t *testing.T) {

require.EqualValues(t, 700, tracing.Execution.Resolvers[0].StartOffset)
require.EqualValues(t, 100, tracing.Execution.Resolvers[0].Duration)
require.EqualValues(t, []interface{}{"name"}, tracing.Execution.Resolvers[0].Path)
require.EqualValues(t, ast.Path{ast.PathName("name")}, tracing.Execution.Resolvers[0].Path)
require.EqualValues(t, "Query", tracing.Execution.Resolvers[0].ParentType)
require.EqualValues(t, "name", tracing.Execution.Resolvers[0].FieldName)
require.EqualValues(t, "String!", tracing.Execution.Resolvers[0].ReturnType)
Expand Down
13 changes: 1 addition & 12 deletions graphql/handler/debug/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,7 @@ func (a Tracer) InterceptResponse(ctx context.Context, next graphql.ResponseHand

fmt.Fprintln(a.out, " resp:", Green(stringify(resp)))
for _, err := range resp.Errors {
pathstr := ""
for i, bit := range err.Path {
if biti, ok := bit.(int); ok {
pathstr += fmt.Sprintf("[%d]", biti)
} else {
if i != 0 {
pathstr += "."
}
pathstr += fmt.Sprint(bit)
}
}
fmt.Fprintln(a.out, " error:", Bold(pathstr+":"), Red(err.Message))
fmt.Fprintln(a.out, " error:", Bold(err.Path.String()+":"), Red(err.Message))
}
fmt.Fprintln(a.out, "}")
fmt.Fprintln(a.out)
Expand Down

0 comments on commit e4530da

Please sign in to comment.