diff --git a/compiler/Makefile b/compiler/Makefile index 104454364..c9db36017 100644 --- a/compiler/Makefile +++ b/compiler/Makefile @@ -173,9 +173,9 @@ generate_code: cd ${GOPATH}/src/nexustempmodule && cd nexus-gql && go mod init && \ go mod edit -replace nexustempmodule=${GOPATH}/src/nexustempmodule && \ ${COMPILER_SRC_DIRECTORY}/scripts/pin_graphql_build_version.sh ${COMPILER_SRC_DIRECTORY} && \ - go mod tidy -e 2>/dev/null && \ - CGO_ENABLED=1 GOOS=linux \ - go build --trimpath -o graphql.so -buildmode=plugin server.go + go mod edit -go=1.18 && \ + go mod tidy && \ + CGO_ENABLED=1 GOARCH=amd64 GOOS=linux go build -ldflags="-w -s" server.go @echo "Updating module name" ./scripts/replace_mod_path.sh find . -name "*.bak" -type f -delete diff --git a/compiler/example/output/_rendered_templates/nexus-gql/server.go b/compiler/example/output/_rendered_templates/nexus-gql/server.go index 85cb58a13..25dd04c5f 100644 --- a/compiler/example/output/_rendered_templates/nexus-gql/server.go +++ b/compiler/example/output/_rendered_templates/nexus-gql/server.go @@ -1,17 +1,18 @@ package main import ( + "fmt" "net/http" + "os" "nexustempmodule/nexus-gql/graph" "nexustempmodule/nexus-gql/graph/generated" + "github.com/rs/cors" - "github.com/vmware-tanzu/graph-framework-for-microservices/gqlgen/graphql" "github.com/vmware-tanzu/graph-framework-for-microservices/gqlgen/graphql/handler" "github.com/vmware-tanzu/graph-framework-for-microservices/gqlgen/graphql/playground" ) - func StartHttpServer() { c := cors.New(cors.Options{ AllowedOrigins: []string{"*"}, @@ -25,3 +26,15 @@ func StartHttpServer() { http.Handle("/", HttpHandlerFunc) http.Handle("/query", c.Handler(Hander_server)) } + +func main() { + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + StartHttpServer() + srv := &http.Server{Addr: fmt.Sprintf(":%s", port)} + if err := srv.ListenAndServe(); err != nil { + fmt.Printf("Error in starting graphql server") + } +} diff --git a/compiler/example/output/generated/nexus-gql/server.go b/compiler/example/output/generated/nexus-gql/server.go index 8d32c046e..25dddd85b 100644 --- a/compiler/example/output/generated/nexus-gql/server.go +++ b/compiler/example/output/generated/nexus-gql/server.go @@ -1,7 +1,9 @@ package main import ( + "fmt" "net/http" + "os" "github.com/vmware-tanzu/graph-framework-for-microservices/compiler/example/output/generated/nexus-gql/graph" "github.com/vmware-tanzu/graph-framework-for-microservices/compiler/example/output/generated/nexus-gql/graph/generated" @@ -24,3 +26,15 @@ func StartHttpServer() { http.Handle("/", HttpHandlerFunc) http.Handle("/query", c.Handler(Hander_server)) } + +func main() { + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + StartHttpServer() + srv := &http.Server{Addr: fmt.Sprintf(":%s", port)} + if err := srv.ListenAndServe(); err != nil { + fmt.Printf("Error in starting graphql server") + } +} diff --git a/compiler/example/test-utils/output-group-name-with-hyphen-datamodel/crd_generated/nexus-gql/server.go b/compiler/example/test-utils/output-group-name-with-hyphen-datamodel/crd_generated/nexus-gql/server.go index af7102def..d920e7f52 100644 --- a/compiler/example/test-utils/output-group-name-with-hyphen-datamodel/crd_generated/nexus-gql/server.go +++ b/compiler/example/test-utils/output-group-name-with-hyphen-datamodel/crd_generated/nexus-gql/server.go @@ -1,17 +1,17 @@ package main import ( + "fmt" "net/http" + "os" "../../example/test-utils/output-group-name-with-hyphen-datamodel/crd_generated/nexus-gql/graph" "../../example/test-utils/output-group-name-with-hyphen-datamodel/crd_generated/nexus-gql/graph/generated" "github.com/rs/cors" - "github.com/vmware-tanzu/graph-framework-for-microservices/gqlgen/graphql" "github.com/vmware-tanzu/graph-framework-for-microservices/gqlgen/graphql/handler" "github.com/vmware-tanzu/graph-framework-for-microservices/gqlgen/graphql/playground" ) - func StartHttpServer() { c := cors.New(cors.Options{ AllowedOrigins: []string{"*"}, @@ -25,3 +25,15 @@ func StartHttpServer() { http.Handle("/", HttpHandlerFunc) http.Handle("/query", c.Handler(Hander_server)) } + +func main() { + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + StartHttpServer() + srv := &http.Server{Addr: fmt.Sprintf(":%s", port)} + if err := srv.ListenAndServe(); err != nil { + fmt.Printf("Error in starting graphql server") + } +} diff --git a/compiler/pkg/generator/template/graphql/server.go.tmpl b/compiler/pkg/generator/template/graphql/server.go.tmpl index 9ca8a4090..bcc165a0b 100644 --- a/compiler/pkg/generator/template/graphql/server.go.tmpl +++ b/compiler/pkg/generator/template/graphql/server.go.tmpl @@ -11,7 +11,6 @@ import ( "github.com/vmware-tanzu/graph-framework-for-microservices/gqlgen/graphql/playground" ) - func StartHttpServer() { c := cors.New(cors.Options{ AllowedOrigins: []string{"*"}, @@ -25,3 +24,15 @@ func StartHttpServer() { http.Handle("/", HttpHandlerFunc) http.Handle("/query", c.Handler(Hander_server)) } + +func main() { + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + StartHttpServer() + srv := &http.Server{Addr: fmt.Sprintf(":%s", port)} + if err := srv.ListenAndServe(); err != nil { + fmt.Printf("Error in starting graphql server") + } +} \ No newline at end of file