GraphQL API and utilities for the rpdata project
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package main
import ( "context" "fmt" "log" "net/http" "runtime/debug"
"git.aiterp.net/rpdata/api/graph2" "git.aiterp.net/rpdata/api/internal/auth" "git.aiterp.net/rpdata/api/internal/loader" "git.aiterp.net/rpdata/api/internal/store" "github.com/99designs/gqlgen/handler" )
func main() { err := store.Init() if err != nil { log.Fatalln("Failed to init store:", err) }
http.Handle("/", handler.Playground("RPData API", "/graphql")) http.Handle("/graphql", queryHandler())
log.Fatal(http.ListenAndServe(":8081", nil)) }
func queryHandler() http.HandlerFunc { handler := handler.GraphQL( graph2.New(), handler.RecoverFunc(func(ctx context.Context, err interface{}) error { // send this panic somewhere
log.Println(err) log.Println(string(debug.Stack()))
return fmt.Errorf("shit") }), )
return func(w http.ResponseWriter, r *http.Request) { l := loader.New() r = r.WithContext(l.ToContext(r.Context()))
r = auth.RequestWithToken(r)
handler.ServeHTTP(w, r) } }
|