-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (36 loc) · 983 Bytes
/
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
// This package is a demonstration how to build and use a GraphQL server in Go
package main
import (
"log"
"net/http"
"github.com/graphql-go/graphql"
"github.com/graphql-go/handler"
"github.com/programmingpercy/gopheragency/gopher"
"github.com/programmingpercy/gopheragency/job"
"github.com/programmingpercy/gopheragency/schemas"
)
func main() {
gopherService := gopher.NewService(
gopher.NewMemoryRepository(),
job.NewMemoryRepository(),
)
schema, err := schemas.GenerateSchema(&gopherService)
if err != nil {
panic(err)
}
StartServer(schema)
}
// StartServer will trigger the server with a Playground
func StartServer(schema *graphql.Schema) {
// Create a new HTTP handler
h := handler.New(&handler.Config{
Schema: schema,
// Pretty print JSON response
Pretty: true,
// Host a GraphiQL Playground to use for testing Queries
GraphiQL: true,
Playground: true,
})
http.Handle("/graphql", h)
log.Fatal(http.ListenAndServe(":8080", nil))
}