-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
57 lines (40 loc) · 1.27 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"net/http"
"github.com/graphql-go/handler"
"github.com/purwokertodev/go-mongo-graphql/config"
"github.com/purwokertodev/go-mongo-graphql/internal/modules/profile/repository"
"github.com/purwokertodev/go-mongo-graphql/internal/modules/profile/graphql/mutations"
"github.com/purwokertodev/go-mongo-graphql/internal/modules/profile/graphql/queries"
"github.com/purwokertodev/go-mongo-graphql/internal/modules/profile/graphql/schema"
)
func main() {
fmt.Println("Go Mongo Db")
db, err := config.GetMongoDB()
if err != nil {
fmt.Println(err)
}
profileRepository := repository.NewProfileRepositoryMongo(db, "profile")
query := queries.New(profileRepository)
mutation := mutations.New(profileRepository)
profileSchema := schema.New(query, mutation)
sc, err := profileSchema.GetSchema()
if err != nil {
fmt.Println(err)
}
//Using http HandleFunc
// http.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) {
// result := profileSchema.ExecuteQuery(r.URL.Query().Get("query"), sc)
// json.NewEncoder(w).Encode(result)
// })
//Using GraphQL Handler
h := handler.New(&handler.Config{
Schema: &sc,
Pretty: true,
GraphiQL: true,
})
// serve HTTP
http.Handle("/graphql", h)
http.ListenAndServe(":8080", nil)
}