Skip to content

Instantly share code, notes, and snippets.

@justdomepaul
Last active November 20, 2022 14:25
Show Gist options
  • Save justdomepaul/ee494aa93d924245759c4fac5458a6e9 to your computer and use it in GitHub Desktop.
Save justdomepaul/ee494aa93d924245759c4fac5458a6e9 to your computer and use it in GitHub Desktop.
inital graphql demo server
package main
import (
"log"
"net/http"
"os"
"$PROJECT/internal/graph/generated"
"$PROJECT/internal/graph/resolvers"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
)
const defaultPort = "38089"
func main() {
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &resolvers.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))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment