Skip to content

Commit

Permalink
Add graphql server as executable instead of plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
janakiramanmesh7 committed Mar 23, 2023
1 parent fa1af5c commit 0c9cf01
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
6 changes: 3 additions & 3 deletions compiler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions compiler/example/output/_rendered_templates/nexus-gql/server.go
Original file line number Diff line number Diff line change
@@ -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{"*"},
Expand All @@ -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")
}
}
14 changes: 14 additions & 0 deletions compiler/example/output/generated/nexus-gql/server.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -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{"*"},
Expand All @@ -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")
}
}
13 changes: 12 additions & 1 deletion compiler/pkg/generator/template/graphql/server.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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{"*"},
Expand All @@ -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")
}
}

0 comments on commit 0c9cf01

Please sign in to comment.