aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/main.go')
-rw-r--r--backend/main.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/backend/main.go b/backend/main.go
index 018a4b2..c7bd7ed 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -14,12 +14,19 @@ import (
"strings"
"time"
+ "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"
"github.com/hashicorp/go-multierror"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
_ "github.com/mattn/go-sqlite3"
"github.com/mmcdole/gofeed"
+ "github.com/vektah/gqlparser/v2/ast"
"golang.org/x/exp/slices"
+
+ "undef.ninja/x/feedaka/graphql"
)
var (
@@ -495,6 +502,24 @@ func main() {
e.GET("/static/*", echo.WrapHandler(http.FileServer(http.FS(staticFS))))
+ // Setup GraphQL server
+ srv := handler.New(graphql.NewExecutableSchema(graphql.Config{Resolvers: &graphql.Resolver{}}))
+
+ srv.AddTransport(transport.Options{})
+ srv.AddTransport(transport.GET{})
+ srv.AddTransport(transport.POST{})
+
+ srv.SetQueryCache(lru.New[*ast.QueryDocument](1000))
+
+ srv.Use(extension.Introspection{})
+ srv.Use(extension.AutomaticPersistedQuery{
+ Cache: lru.New[string](100),
+ })
+
+ // GraphQL endpoints
+ e.POST("/graphql", echo.WrapHandler(srv))
+ e.GET("/graphql", echo.WrapHandler(srv))
+
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
scheduled(ctx, 1*time.Hour, func() {