Add instrumentation to library example (#212)

This commit is contained in:
Alejandro Serrano 2020-07-28 10:29:33 +02:00 committed by GitHub
parent 2b5c147535
commit afbe5d8ef1
2 changed files with 8 additions and 1 deletions

View File

@ -25,6 +25,7 @@ executable library
, monad-logger >=0.3 && <0.4
, mtl
, mu-persistent >=0.3
, mu-prometheus >=0.4
, mu-graphql >=0.4
, mu-rpc >=0.4
, mu-schema >=0.3

View File

@ -20,6 +20,7 @@ import Database.Persist.Sqlite
import Mu.Adapter.Persistent (runDb)
import Mu.GraphQL.Quasi
import Mu.GraphQL.Server
import Mu.Instrumentation.Prometheus
import Mu.Schema
import Mu.Server
import Network.Wai.Handler.Warp (run)
@ -30,19 +31,24 @@ import Schema
main :: IO ()
main = do
putStrLn "starting GraphQL server on port 8000"
-- Setup CORS
let hm = addHeaders [
("Access-Control-Allow-Origin", "*")
, ("Access-Control-Allow-Headers", "Content-Type")
]
-- Set up Prometheus
p <- initPrometheus "library"
-- Run the whole thing
runStderrLoggingT $
withSqliteConn @(LoggingT IO) ":memory:" $ \conn -> do
runDb conn $ runMigration migrateAll
liftIO $ run 8000 $ hm $
graphQLApp (libraryServer conn)
graphQLApp (prometheus p $ libraryServer conn)
(Proxy @('Just "Query"))
(Proxy @('Just "Mutation"))
(Proxy @('Just "Subscription"))
type ObjectMapping = '[
"Book" ':-> Entity Book
, "Author" ':-> Entity Author