laconicd/gql/server.go
Sai Kumar e90b21bc8e migrate: add dxns module
1. add bond,auction, nameserivce module
2. update to v0.12.2 ethermint version
3. fix the test cases
4. add gql server
2022-04-05 12:39:27 +05:30

45 lines
1.1 KiB
Go

package gql
import (
"fmt"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/cosmos/cosmos-sdk/client"
"github.com/ethereum/go-ethereum/log"
"github.com/spf13/viper"
"net/http"
)
// Server configures and starts the GQL server.
func Server(ctx client.Context) {
if !viper.GetBool("gql-server") {
return
}
logFile := viper.GetString("log-file")
port := viper.GetString("gql-port")
srv := handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: &Resolver{
ctx: ctx,
logFile: logFile,
}}))
http.Handle("/", playground.Handler("GraphQL playground", "/api"))
if viper.GetBool("gql-playground") {
apiBase := viper.GetString("gql-playground-api-base")
http.Handle("/webui", playground.Handler("GraphQL playground", apiBase+"/api"))
http.Handle("/console", playground.Handler("GraphQL playground", apiBase+"/graphql"))
}
http.Handle("/api", srv)
http.Handle("/graphql", srv)
log.Info("Connect to GraphQL playground", "url", fmt.Sprintf("http://localhost:%s", port))
err := http.ListenAndServe(":"+port, nil)
if err != nil {
panic(err)
}
}