github.com/kubeshop/testkube@v1.17.23/internal/app/api/v1/graphql.go (about) 1 package v1 2 3 import ( 4 "context" 5 "net" 6 "net/http" 7 8 "github.com/kubeshop/testkube/internal/graphql" 9 "github.com/kubeshop/testkube/pkg/log" 10 ) 11 12 // RunGraphQLServer runs GraphQL server on go net/http server 13 func (s *TestkubeAPI) RunGraphQLServer(ctx context.Context, port string) error { 14 srv := graphql.GetServer(s.Events.Bus, s.ExecutorsClient) 15 16 mux := http.NewServeMux() 17 mux.Handle("/graphql", srv) 18 httpSrv := &http.Server{Handler: mux} 19 20 log.DefaultLogger.Infow("running GraphQL server", "port", port) 21 22 l, err := net.Listen("tcp", ":"+port) 23 if err != nil { 24 return err 25 } 26 27 go func() { 28 <-ctx.Done() 29 s.Log.Infof("shutting down Testkube GraphQL API server") 30 _ = httpSrv.Shutdown(context.Background()) 31 }() 32 33 return httpSrv.Serve(l) 34 }