gographql/main.go

47 lines
862 B
Go
Raw Normal View History

2019-07-24 16:52:09 +02:00
package main
import (
"cadoles/graphql/mutations"
"cadoles/graphql/postgres"
"cadoles/graphql/queries"
"log"
"net/http"
"github.com/graphql-go/graphql"
"github.com/graphql-go/handler"
)
func main() {
schemaConfig := graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "RootQuery",
Fields: queries.GetRootFields(),
}),
Mutation: graphql.NewObject(graphql.ObjectConfig{
Name: "RootMutation",
Fields: mutations.GetRootFields(),
}),
}
schema, err := graphql.NewSchema(schemaConfig)
if err != nil {
log.Fatalf("Failed to create new schema, error: %v", err)
}
httpHandler := handler.New(&handler.Config{
Schema: &schema,
2019-07-24 17:29:11 +02:00
Pretty: true,
2019-07-24 16:52:09 +02:00
})
postgres.DBConnect()
defer postgres.DBClose()
http.Handle("/", httpHandler)
log.Print("ready: listening...\n")
http.ListenAndServe(":8383", nil)
}