-
Notifications
You must be signed in to change notification settings - Fork 4
/
graphql.go
37 lines (30 loc) · 903 Bytes
/
graphql.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
package graphql
import (
_ "embed"
"net/http"
"github.com/graph-gophers/graphql-go/relay"
"github.com/sassoftware/event-provenance-registry/pkg/api/graphql/schema"
"github.com/sassoftware/event-provenance-registry/pkg/message"
"github.com/sassoftware/event-provenance-registry/pkg/storage"
)
type Server struct {
DBConnector *storage.Database
msgProducer message.TopicProducer
}
func New(conn *storage.Database, msgProducer message.TopicProducer) *Server {
return &Server{
DBConnector: conn,
msgProducer: msgProducer,
}
}
//go:embed resources/graphql.html
var graphqlHTML []byte
func (s *Server) ServerGraphQLDoc() http.HandlerFunc {
return func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write(graphqlHTML)
}
}
func (s *Server) GraphQLHandler() http.HandlerFunc {
handler := &relay.Handler{Schema: schema.New(s.DBConnector, s.msgProducer)}
return handler.ServeHTTP
}