2021-11-11 18:57:02 +01:00
|
|
|
package graphql_endpoint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
graphql_handler "github.com/99designs/gqlgen/graphql/handler"
|
|
|
|
"github.com/99designs/gqlgen/graphql/handler/extension"
|
|
|
|
"github.com/99designs/gqlgen/graphql/handler/lru"
|
|
|
|
"github.com/99designs/gqlgen/graphql/handler/transport"
|
|
|
|
photoview_graphql "github.com/photoview/photoview/api/graphql"
|
|
|
|
"github.com/photoview/photoview/api/graphql/resolvers"
|
2022-02-07 18:15:47 +01:00
|
|
|
"github.com/photoview/photoview/api/server"
|
2021-11-11 18:57:02 +01:00
|
|
|
"github.com/photoview/photoview/api/utils"
|
2024-09-17 17:00:03 +02:00
|
|
|
"github.com/vektah/gqlparser/v2/ast"
|
2021-11-11 18:57:02 +01:00
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GraphqlEndpoint(db *gorm.DB) *graphql_handler.Server {
|
|
|
|
graphqlResolver := resolvers.NewRootResolver(db)
|
|
|
|
graphqlDirective := photoview_graphql.DirectiveRoot{}
|
|
|
|
graphqlDirective.IsAdmin = photoview_graphql.IsAdmin
|
|
|
|
graphqlDirective.IsAuthorized = photoview_graphql.IsAuthorized
|
|
|
|
|
|
|
|
graphqlConfig := photoview_graphql.Config{
|
|
|
|
Resolvers: &graphqlResolver,
|
|
|
|
Directives: graphqlDirective,
|
|
|
|
}
|
|
|
|
|
|
|
|
graphqlServer := graphql_handler.New(photoview_graphql.NewExecutableSchema(graphqlConfig))
|
|
|
|
graphqlServer.AddTransport(transport.Websocket{
|
|
|
|
KeepAlivePingInterval: 10 * time.Second,
|
2022-02-07 18:15:47 +01:00
|
|
|
Upgrader: server.WebsocketUpgrader(utils.DevelopmentMode()),
|
2021-11-11 18:57:02 +01:00
|
|
|
})
|
|
|
|
graphqlServer.AddTransport(transport.Options{})
|
|
|
|
graphqlServer.AddTransport(transport.GET{})
|
|
|
|
graphqlServer.AddTransport(transport.POST{})
|
|
|
|
graphqlServer.AddTransport(transport.MultipartForm{})
|
|
|
|
|
2024-09-17 17:00:03 +02:00
|
|
|
graphqlServer.SetQueryCache(lru.New[*ast.QueryDocument](1000))
|
2021-11-11 18:57:02 +01:00
|
|
|
|
|
|
|
graphqlServer.Use(extension.AutomaticPersistedQuery{
|
2024-09-17 17:00:03 +02:00
|
|
|
Cache: lru.New[string](100),
|
2021-11-11 18:57:02 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
if utils.DevelopmentMode() {
|
|
|
|
graphqlServer.Use(extension.Introspection{})
|
|
|
|
}
|
|
|
|
|
|
|
|
return graphqlServer
|
|
|
|
}
|