From cdec6f143e2aa5155167b8f42466ff5b2b6a1a20 Mon Sep 17 00:00:00 2001 From: Rahul Powar Date: Mon, 26 Jun 2017 19:17:55 +0100 Subject: [PATCH 1/9] Added benchmark for aliases --- .gitignore | 2 ++ graphql_test.go | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/.gitignore b/.gitignore index 32b9e0f1..bf45edbf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /internal/tests/testdata/graphql-js + +.idea/ diff --git a/graphql_test.go b/graphql_test.go index 95d15b1d..112176c9 100644 --- a/graphql_test.go +++ b/graphql_test.go @@ -8,6 +8,8 @@ import ( "github.com/neelance/graphql-go" "github.com/neelance/graphql-go/example/starwars" "github.com/neelance/graphql-go/gqltesting" + "fmt" + "bytes" ) type helloWorldResolver1 struct{} @@ -1744,3 +1746,71 @@ func TestComposedFragments(t *testing.T) { }, }) } + +// go test -bench=FragmentQueries -benchmem +func BenchmarkFragmentQueries(b *testing.B) { + singleQuery := ` + composed_%d: hero(episode: EMPIRE) { + name + ...friendsNames + ...friendsIds + } + ` + + queryTemplate := ` + { + %s + } + + fragment friendsNames on Character { + name + friends { + name + } + } + + fragment friendsIds on Character { + name + friends { + id + } + } + ` + + testCases := []int { + 1, + 10, + 100, + 1000, + 10000, + } + + for _, c := range testCases { + // for each count, add a case for overlapping aliases vs non-overlapping aliases + for _, o := range []bool{ true, false } { + + var buffer bytes.Buffer + for i := 0; i < c; i++ { + idx := 0 + if o { + idx = i + } + buffer.WriteString(fmt.Sprintf(singleQuery, idx)) + } + + query := fmt.Sprintf(queryTemplate, buffer.String()) + a := "overlapping" + if o { + a = "non-overlapping" + } + b.Run(fmt.Sprintf("%d queries %s aliases", c, a), func(b *testing.B) { + for n := 0; n < b.N; n++ { + result := starwarsSchema.Exec(context.Background(), query, "", nil) + if len(result.Errors) != 0 { + b.Fatal(result.Errors[0]) + } + } + }) + } + } +} From 47c1b55fa8b8557921c6f17b55873e0a0cd914bc Mon Sep 17 00:00:00 2001 From: Rahul Powar Date: Tue, 27 Jun 2017 12:45:10 +0100 Subject: [PATCH 2/9] Added test for overlapping alias --- graphql_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/graphql_test.go b/graphql_test.go index 112176c9..07509c8a 100644 --- a/graphql_test.go +++ b/graphql_test.go @@ -1747,6 +1747,21 @@ func TestComposedFragments(t *testing.T) { }) } +func TestOverlappingAlias(t *testing.T) { + query := ` + { + hero(episode: EMPIRE) { + a: name + a: id + } + } + ` + result := starwarsSchema.Exec(context.Background(), query, "", nil) + if len(result.Errors) == 0 { + t.Fatal("Expected error from overlapping alias") + } +} + // go test -bench=FragmentQueries -benchmem func BenchmarkFragmentQueries(b *testing.B) { singleQuery := ` From 93175b09dc79163afdf9d53c3a4adbf954024b45 Mon Sep 17 00:00:00 2001 From: Rahul Powar Date: Tue, 27 Jun 2017 17:29:48 +0100 Subject: [PATCH 3/9] Added cache bypass for long lists --- internal/validation/validation.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/internal/validation/validation.go b/internal/validation/validation.go index a537d458..bfd1db3b 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -171,9 +171,10 @@ func validateSelectionSet(c *opContext, sels []query.Selection, t schema.NamedTy validateSelection(c, sel, t) } + useCache := len(sels) <= 100 for i, a := range sels { for _, b := range sels[i+1:] { - c.validateOverlap(a, b, nil, nil) + c.validateOverlap(a, b, nil, nil, useCache) } } } @@ -381,16 +382,18 @@ func detectFragmentCycleSel(c *context, sel query.Selection, fragVisited map[*qu } } -func (c *context) validateOverlap(a, b query.Selection, reasons *[]string, locs *[]errors.Location) { +func (c *context) validateOverlap(a, b query.Selection, reasons *[]string, locs *[]errors.Location, useCache bool) { if a == b { return } - if _, ok := c.overlapValidated[selectionPair{a, b}]; ok { - return + if useCache { + if _, ok := c.overlapValidated[selectionPair{a, b}]; ok { + return + } + c.overlapValidated[selectionPair{a, b}] = struct{}{} + c.overlapValidated[selectionPair{b, a}] = struct{}{} } - c.overlapValidated[selectionPair{a, b}] = struct{}{} - c.overlapValidated[selectionPair{b, a}] = struct{}{} switch a := a.(type) { case *query.Field: @@ -399,7 +402,7 @@ func (c *context) validateOverlap(a, b query.Selection, reasons *[]string, locs if b.Alias.Loc.Before(a.Alias.Loc) { a, b = b, a } - if reasons2, locs2 := c.validateFieldOverlap(a, b); len(reasons2) != 0 { + if reasons2, locs2 := c.validateFieldOverlap(a, b, useCache); len(reasons2) != 0 { locs2 = append(locs2, a.Alias.Loc, b.Alias.Loc) if reasons == nil { c.addErrMultiLoc(locs2, "OverlappingFieldsCanBeMerged", "Fields %q conflict because %s. Use different aliases on the fields to fetch both if this was intentional.", a.Alias.Name, strings.Join(reasons2, " and ")) @@ -413,13 +416,13 @@ func (c *context) validateOverlap(a, b query.Selection, reasons *[]string, locs case *query.InlineFragment: for _, sel := range b.Selections { - c.validateOverlap(a, sel, reasons, locs) + c.validateOverlap(a, sel, reasons, locs, useCache) } case *query.FragmentSpread: if frag := c.doc.Fragments.Get(b.Name.Name); frag != nil { for _, sel := range frag.Selections { - c.validateOverlap(a, sel, reasons, locs) + c.validateOverlap(a, sel, reasons, locs, useCache) } } @@ -429,13 +432,13 @@ func (c *context) validateOverlap(a, b query.Selection, reasons *[]string, locs case *query.InlineFragment: for _, sel := range a.Selections { - c.validateOverlap(sel, b, reasons, locs) + c.validateOverlap(sel, b, reasons, locs, useCache) } case *query.FragmentSpread: if frag := c.doc.Fragments.Get(a.Name.Name); frag != nil { for _, sel := range frag.Selections { - c.validateOverlap(sel, b, reasons, locs) + c.validateOverlap(sel, b, reasons, locs, useCache) } } @@ -444,7 +447,7 @@ func (c *context) validateOverlap(a, b query.Selection, reasons *[]string, locs } } -func (c *context) validateFieldOverlap(a, b *query.Field) ([]string, []errors.Location) { +func (c *context) validateFieldOverlap(a, b *query.Field, useCache bool) ([]string, []errors.Location) { if a.Alias.Name != b.Alias.Name { return nil, nil } @@ -473,7 +476,7 @@ func (c *context) validateFieldOverlap(a, b *query.Field) ([]string, []errors.Lo var locs []errors.Location for _, a2 := range a.Selections { for _, b2 := range b.Selections { - c.validateOverlap(a2, b2, &reasons, &locs) + c.validateOverlap(a2, b2, &reasons, &locs, useCache) } } return reasons, locs From f14a31623877d5d7564080e6bb600fd078074b4f Mon Sep 17 00:00:00 2001 From: Rahul Powar Date: Sat, 1 Jul 2017 23:06:34 +0100 Subject: [PATCH 4/9] Minor performance tweaks --- internal/validation/validation.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/validation/validation.go b/internal/validation/validation.go index bfd1db3b..c6aa9337 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -391,8 +391,11 @@ func (c *context) validateOverlap(a, b query.Selection, reasons *[]string, locs if _, ok := c.overlapValidated[selectionPair{a, b}]; ok { return } - c.overlapValidated[selectionPair{a, b}] = struct{}{} - c.overlapValidated[selectionPair{b, a}] = struct{}{} + key := selectionPair{b, a} + if _, ok := c.overlapValidated[key]; ok { + return + } + c.overlapValidated[key] = struct{}{} } switch a := a.(type) { @@ -452,16 +455,19 @@ func (c *context) validateFieldOverlap(a, b *query.Field, useCache bool) ([]stri return nil, nil } - if asf := c.fieldMap[a].sf; asf != nil { - if bsf := c.fieldMap[b].sf; bsf != nil { + afm := c.fieldMap[a] + bfm := c.fieldMap[b] + + if asf := afm.sf; asf != nil { + if bsf := bfm.sf; bsf != nil { if !typesCompatible(asf.Type, bsf.Type) { return []string{fmt.Sprintf("they return conflicting types %s and %s", asf.Type, bsf.Type)}, nil } } } - at := c.fieldMap[a].parent - bt := c.fieldMap[b].parent + at := afm.parent + bt := bfm.parent if at == nil || bt == nil || at == bt { if a.Name.Name != b.Name.Name { return []string{fmt.Sprintf("%s and %s are different fields", a.Name.Name, b.Name.Name)}, nil From 602f734d59889ab10aee18060dec34dadefab704 Mon Sep 17 00:00:00 2001 From: Rahul Powar Date: Sat, 1 Jul 2017 23:07:17 +0100 Subject: [PATCH 5/9] Modifed test cases to remove overlaps Overlapping fields is a bit of an artificial test case. --- graphql_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/graphql_test.go b/graphql_test.go index 07509c8a..49d30a3e 100644 --- a/graphql_test.go +++ b/graphql_test.go @@ -1778,14 +1778,12 @@ func BenchmarkFragmentQueries(b *testing.B) { } fragment friendsNames on Character { - name friends { name } } fragment friendsIds on Character { - name friends { id } @@ -1802,7 +1800,7 @@ func BenchmarkFragmentQueries(b *testing.B) { for _, c := range testCases { // for each count, add a case for overlapping aliases vs non-overlapping aliases - for _, o := range []bool{ true, false } { + for _, o := range []bool{ true } { var buffer bytes.Buffer for i := 0; i < c; i++ { From 31eb94bf64db6ec317a7bab5aaa3098a982e7ea0 Mon Sep 17 00:00:00 2001 From: Rahul Powar Date: Mon, 17 Jul 2017 19:42:36 +0100 Subject: [PATCH 6/9] Removed gitignore contamination. --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index bf45edbf..32b9e0f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ /internal/tests/testdata/graphql-js - -.idea/ From 720c77cf6b750fef642d5256b0b5efcdd74636ce Mon Sep 17 00:00:00 2001 From: csucu Date: Mon, 1 Nov 2021 11:33:57 +0000 Subject: [PATCH 7/9] mute scanner errors --- internal/common/lexer.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/common/lexer.go b/internal/common/lexer.go index 5807f7ae..c3b1fdf2 100644 --- a/internal/common/lexer.go +++ b/internal/common/lexer.go @@ -30,6 +30,10 @@ func NewLexer(s string, useStringDescriptions bool) *Lexer { } sc.Init(strings.NewReader(s)) + sc.Error = func(s *scanner.Scanner, msg string) { + // do nothing, as we get a large volume of bad requests and we dont want to log these + } + return &Lexer{sc: sc, useStringDescriptions: useStringDescriptions} } From 00e76d5c13179ed0291e45507a5b79afe91fcf91 Mon Sep 17 00:00:00 2001 From: csucu Date: Mon, 1 Nov 2021 17:28:50 +0000 Subject: [PATCH 8/9] added collector, fmt & go mod tidy --- go.mod | 6 +++++- go.sum | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ graphql.go | 14 ++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2c814b0b..2bde05f7 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,9 @@ module github.com/graph-gophers/graphql-go -require github.com/opentracing/opentracing-go v1.1.0 +require ( + github.com/opentracing/opentracing-go v1.1.0 + github.com/redsift/go-stats v1.0.5 + github.com/stretchr/testify v1.7.0 // indirect +) go 1.13 diff --git a/go.sum b/go.sum index 71fd021b..b7400b22 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,54 @@ +github.com/PagerDuty/godspeed v0.0.0-20180224001232-122876cde329 h1:3q+9OIju0tFi+TUZZuG80mRbXI3MT/L/1vlTb8CcofA= +github.com/PagerDuty/godspeed v0.0.0-20180224001232-122876cde329/go.mod h1:u6OV0JEB9gtT/nTmTNEt6SXkQJW+SBnGWlJoSr+0F+U= +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/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ= +github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/redsift/go-cfg v0.1.0/go.mod h1:aU2ck918wPW7lVeJv8u6OqNsVY4dDJCiGf8h+PVbUoY= +github.com/redsift/go-errs v0.1.4 h1:wjLI5lGf1W4SMVHkeF4gMMm3NI/nSnYbIxrTFc0p3ZQ= +github.com/redsift/go-errs v0.1.4/go.mod h1:adLW0LIX8lEaRMD0rFDcsdO6ccGlOirWyK7lXjhoqaU= +github.com/redsift/go-foodfans v1.0.4 h1:gzj7oiaZuS+xAIPDELD5NJj8PwuHPAxfuVlIvf1Xoo0= +github.com/redsift/go-foodfans v1.0.4/go.mod h1:0KcaRKBiH6upPJ16EDryKCJhTQDJznpLkZg2b/PNQEo= +github.com/redsift/go-stats v1.0.5 h1:VEZMuba4LNPnzmjBx5EwVYNqw1i0EZF1ipWhptAkS1A= +github.com/redsift/go-stats v1.0.5/go.mod h1:s5fr4yGrt52hn4Khd8/ON1xDIyLF2VZn3BcoyqBX4IY= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tinylib/msgp v1.1.5 h1:2gXmtWueD2HefZHQe1QOy9HVzmFrLOVvsXwXBQ0ayy0= +github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg= +github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +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/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/graphql.go b/graphql.go index 9ccc3592..859fdc99 100644 --- a/graphql.go +++ b/graphql.go @@ -17,6 +17,8 @@ import ( "github.com/graph-gophers/graphql-go/introspection" "github.com/graph-gophers/graphql-go/log" "github.com/graph-gophers/graphql-go/trace" + + "github.com/redsift/go-stats/stats" ) // ParseSchema parses a GraphQL schema and attaches the given root resolver. It returns an error if @@ -69,6 +71,7 @@ type Schema struct { tracer trace.Tracer validationTracer trace.ValidationTracer logger log.Logger + collector stats.Collector useStringDescriptions bool disableIntrospection bool } @@ -135,6 +138,13 @@ func DisableIntrospection() SchemaOpt { } } +// Collector used to send metrics +func Collector(collector stats.Collector) SchemaOpt { + return func(s *Schema) { + s.collector = collector + } +} + // Response represents a typical response of a GraphQL server. It may be encoded to JSON directly or // it may be further processed to a custom response type, for example to include custom error data. // Errors are intentionally serialized first based on the advice in https://github.com/facebook/graphql/commit/7b40390d48680b15cb93e02d46ac5eb249689876#diff-757cea6edf0288677a9eea4cfc801d87R107 @@ -167,6 +177,10 @@ func (s *Schema) Exec(ctx context.Context, queryString string, operationName str func (s *Schema) exec(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) *Response { doc, qErr := query.Parse(queryString) if qErr != nil { + if s.collector != nil { + s.collector.Count("graphql.parse_error", float64(1)) + } + return &Response{Errors: []*errors.QueryError{qErr}} } From e966f129b3363d09f88145420d6ebf94d4814e2d Mon Sep 17 00:00:00 2001 From: csucu Date: Wed, 10 Nov 2021 16:04:06 +0000 Subject: [PATCH 9/9] Revert "added collector, fmt & go mod tidy" This reverts commit 00e76d5c13179ed0291e45507a5b79afe91fcf91. --- go.mod | 6 +----- go.sum | 52 ---------------------------------------------------- graphql.go | 14 -------------- 3 files changed, 1 insertion(+), 71 deletions(-) diff --git a/go.mod b/go.mod index 2bde05f7..2c814b0b 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,5 @@ module github.com/graph-gophers/graphql-go -require ( - github.com/opentracing/opentracing-go v1.1.0 - github.com/redsift/go-stats v1.0.5 - github.com/stretchr/testify v1.7.0 // indirect -) +require github.com/opentracing/opentracing-go v1.1.0 go 1.13 diff --git a/go.sum b/go.sum index b7400b22..71fd021b 100644 --- a/go.sum +++ b/go.sum @@ -1,54 +1,2 @@ -github.com/PagerDuty/godspeed v0.0.0-20180224001232-122876cde329 h1:3q+9OIju0tFi+TUZZuG80mRbXI3MT/L/1vlTb8CcofA= -github.com/PagerDuty/godspeed v0.0.0-20180224001232-122876cde329/go.mod h1:u6OV0JEB9gtT/nTmTNEt6SXkQJW+SBnGWlJoSr+0F+U= -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/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ= -github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/redsift/go-cfg v0.1.0/go.mod h1:aU2ck918wPW7lVeJv8u6OqNsVY4dDJCiGf8h+PVbUoY= -github.com/redsift/go-errs v0.1.4 h1:wjLI5lGf1W4SMVHkeF4gMMm3NI/nSnYbIxrTFc0p3ZQ= -github.com/redsift/go-errs v0.1.4/go.mod h1:adLW0LIX8lEaRMD0rFDcsdO6ccGlOirWyK7lXjhoqaU= -github.com/redsift/go-foodfans v1.0.4 h1:gzj7oiaZuS+xAIPDELD5NJj8PwuHPAxfuVlIvf1Xoo0= -github.com/redsift/go-foodfans v1.0.4/go.mod h1:0KcaRKBiH6upPJ16EDryKCJhTQDJznpLkZg2b/PNQEo= -github.com/redsift/go-stats v1.0.5 h1:VEZMuba4LNPnzmjBx5EwVYNqw1i0EZF1ipWhptAkS1A= -github.com/redsift/go-stats v1.0.5/go.mod h1:s5fr4yGrt52hn4Khd8/ON1xDIyLF2VZn3BcoyqBX4IY= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tinylib/msgp v1.1.5 h1:2gXmtWueD2HefZHQe1QOy9HVzmFrLOVvsXwXBQ0ayy0= -github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg= -github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -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/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/graphql.go b/graphql.go index 859fdc99..9ccc3592 100644 --- a/graphql.go +++ b/graphql.go @@ -17,8 +17,6 @@ import ( "github.com/graph-gophers/graphql-go/introspection" "github.com/graph-gophers/graphql-go/log" "github.com/graph-gophers/graphql-go/trace" - - "github.com/redsift/go-stats/stats" ) // ParseSchema parses a GraphQL schema and attaches the given root resolver. It returns an error if @@ -71,7 +69,6 @@ type Schema struct { tracer trace.Tracer validationTracer trace.ValidationTracer logger log.Logger - collector stats.Collector useStringDescriptions bool disableIntrospection bool } @@ -138,13 +135,6 @@ func DisableIntrospection() SchemaOpt { } } -// Collector used to send metrics -func Collector(collector stats.Collector) SchemaOpt { - return func(s *Schema) { - s.collector = collector - } -} - // Response represents a typical response of a GraphQL server. It may be encoded to JSON directly or // it may be further processed to a custom response type, for example to include custom error data. // Errors are intentionally serialized first based on the advice in https://github.com/facebook/graphql/commit/7b40390d48680b15cb93e02d46ac5eb249689876#diff-757cea6edf0288677a9eea4cfc801d87R107 @@ -177,10 +167,6 @@ func (s *Schema) Exec(ctx context.Context, queryString string, operationName str func (s *Schema) exec(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) *Response { doc, qErr := query.Parse(queryString) if qErr != nil { - if s.collector != nil { - s.collector.Count("graphql.parse_error", float64(1)) - } - return &Response{Errors: []*errors.QueryError{qErr}} }