diff --git a/go.mod b/go.mod index 7726e1ddfe5..f09a35e2a66 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 06f3b01ccf0..a1e3862cfd5 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/graphql/context_field.go b/graphql/context_field.go index 802b60e4c5e..416646627f5 100644 --- a/graphql/context_field.go +++ b/graphql/context_field.go @@ -3,6 +3,8 @@ package graphql import ( "context" "time" + + "github.com/vektah/gqlparser/ast" ) type key string @@ -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)) } } @@ -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 } diff --git a/graphql/context_response_test.go b/graphql/context_response_test.go index 59d80f4403a..c009d45ab5d 100644 --- a/graphql/context_response_test.go +++ b/graphql/context_response_test.go @@ -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 { diff --git a/graphql/handler/apollotracing/tracer.go b/graphql/handler/apollotracing/tracer.go index b4b0cb312f9..c1478a518db 100644 --- a/graphql/handler/apollotracing/tracer.go +++ b/graphql/handler/apollotracing/tracer.go @@ -6,6 +6,7 @@ import ( "time" "github.com/99designs/gqlgen/graphql" + "github.com/vektah/gqlparser/ast" ) type ( @@ -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"` diff --git a/graphql/handler/apollotracing/tracer_test.go b/graphql/handler/apollotracing/tracer_test.go index d78d61c47c7..fa52c387c24 100644 --- a/graphql/handler/apollotracing/tracer_test.go +++ b/graphql/handler/apollotracing/tracer_test.go @@ -9,7 +9,6 @@ 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" @@ -17,6 +16,7 @@ import ( "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" ) @@ -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) diff --git a/graphql/handler/debug/tracer.go b/graphql/handler/debug/tracer.go index 6115f5ad44a..3a4c8436b4b 100644 --- a/graphql/handler/debug/tracer.go +++ b/graphql/handler/debug/tracer.go @@ -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)