aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/main.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-07-11 00:12:49 +0900
committernsfisis <nsfisis@gmail.com>2025-07-11 00:12:49 +0900
commit5fd105fd8ff480afaaf9c8ccd45eb26b61018550 (patch)
treefa6d278e5eb8a3a33f9a50088a18aa7ee8dde6d6 /backend/main.go
parentce42724c7b055f8f4d1080410e1cf358cbe99189 (diff)
downloadfeedaka-5fd105fd8ff480afaaf9c8ccd45eb26b61018550.tar.gz
feedaka-5fd105fd8ff480afaaf9c8ccd45eb26b61018550.tar.zst
feedaka-5fd105fd8ff480afaaf9c8ccd45eb26b61018550.zip
feat(backend): add GraphQL boilerplate code
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() {