Last active
November 20, 2022 14:25
-
-
Save justdomepaul/ee494aa93d924245759c4fac5458a6e9 to your computer and use it in GitHub Desktop.
inital graphql demo server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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