mirror of
https://github.com/Unkn0wnCat/calapi.git
synced 2025-04-29 18:16:19 +02:00
28 lines
630 B
Go
28 lines
630 B
Go
package server
|
|
|
|
import (
|
|
"github.com/99designs/gqlgen/graphql/handler"
|
|
"github.com/99designs/gqlgen/graphql/playground"
|
|
"github.com/Unkn0wnCat/calapi/graph"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
const defaultPort = "8080"
|
|
|
|
func Serve() {
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = defaultPort
|
|
}
|
|
|
|
srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.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))
|
|
|
|
}
|