searchhut/cmd/sh-api/main.go
2022-07-09 13:25:27 +02:00

29 lines
685 B
Go

package main
import (
"log"
"net/http"
"os"
"git.sr.ht/~sircmpwn/searchhut/graph"
"git.sr.ht/~sircmpwn/searchhut/graph/generated"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
)
const defaultPort = "8080"
func main() {
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
http.Handle("/", playground.Handler("GraphQL playground", "/query"))
http.Handle("/query", srv)
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}