diff --git a/.gitignore b/.gitignore index a9712beb0bc..c0ff0ef28b9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ /codegen/gen .idea/ +*.test +*.out diff --git a/example/starwars/benchmarks_test.go b/example/starwars/benchmarks_test.go new file mode 100644 index 00000000000..8386b7963f0 --- /dev/null +++ b/example/starwars/benchmarks_test.go @@ -0,0 +1,30 @@ +package starwars + +import ( + "net/http/httptest" + "strings" + "testing" + + "github.com/99designs/gqlgen/handler" +) + +func BenchmarkSimpleQueryNoArgs(b *testing.B) { + server := handler.GraphQL(NewExecutableSchema(NewResolver())) + + q := `{"query":"{ search(text:\"Luke\") { ... on Human { starships { name } } } }"}` + + var body strings.Reader + r := httptest.NewRequest("POST", "/graphql", &body) + + b.ResetTimer() + rec := httptest.NewRecorder() + for i := 0; i < b.N; i++ { + body.Reset(q) + rec.Body.Reset() + server.ServeHTTP(rec, r) + if rec.Body.String() != `{"data":{"search":[{"starships":[{"name":"X-Wing"},{"name":"Imperial shuttle"}]}]}}` { + b.Fatalf("Unexpected response") + } + + } +}