Skip to content

Instantly share code, notes, and snippets.

@tosik
Created March 17, 2020 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tosik/7167c437d234825564f1b2c387095a04 to your computer and use it in GitHub Desktop.
Save tosik/7167c437d234825564f1b2c387095a04 to your computer and use it in GitHub Desktop.
package main
import (
"net/http"
"github.com/99designs/gqlgen/example/todo"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/go-chi/chi"
"github.com/rs/cors"
)
func main() {
router := chi.NewRouter()
router.Use(cors.New(cors.Options{
AllowedOrigins: []string{ "http://localhost:3000" },
AllowCredentials: true,
Debug: true,
}).Handler)
srv := handler.NewDefaultServer(todo.NewExecutableSchema(todo.New()))
router.Handle("/", playground.Handler("Todo", "/query"))
router.Handle("/query", srv)
err := http.ListenAndServe(":8081", router)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment