gographql/main.go

46 行
846 B
Go

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,
})
postgres.DBConnect()
defer postgres.DBClose()
http.Handle("/", httpHandler)
log.Print("ready: listening...\n")
http.ListenAndServe(":8383", nil)
}