This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/internal/api/routes.go

37 lines
907 B
Go
Raw Normal View History

2021-01-16 22:00:17 +00:00
package api
import (
2021-02-02 20:34:10 +00:00
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
2021-02-03 03:55:35 +00:00
2021-02-02 20:34:10 +00:00
"reichard.io/imagini/graph"
"reichard.io/imagini/graph/generated"
2021-01-16 22:00:17 +00:00
)
func (api *API) registerRoutes() {
2021-02-04 10:16:13 +00:00
// Set up Directives
graphConfig := generated.Config{
Resolvers: &graph.Resolver{
2021-02-06 03:01:51 +00:00
DB: api.DB,
Auth: api.Auth,
Config: api.Config,
2021-02-04 10:16:13 +00:00
},
Directives: generated.DirectiveRoot{
Meta: api.metaDirective,
2021-02-04 20:31:07 +00:00
IsPrivate: api.isPrivateDirective,
2021-02-04 10:16:13 +00:00
HasMinRole: api.hasMinRoleDirective,
},
}
srv := handler.NewDefaultServer(generated.NewExecutableSchema(graphConfig))
// Handle GraphQL
2021-02-02 20:34:10 +00:00
api.Router.Handle("/playground", playground.Handler("GraphQL playground", "/query"))
api.Router.Handle("/query", api.queryMiddleware(srv))
2021-02-02 20:34:10 +00:00
2021-02-04 10:16:13 +00:00
// Handle Resource Route
api.Router.HandleFunc("/media/", multipleMiddleware(
api.mediaHandler,
api.authMiddleware,
))
2021-01-16 22:00:17 +00:00
}