mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
- Core Go application with GraphQL API using gqlgen - Comprehensive data models for literary works, authors, translations - Repository pattern with caching layer - Authentication and authorization system - Linguistics analysis capabilities with multiple adapters - Vector search integration with Weaviate - Docker containerization support - Python data migration and analysis scripts - Clean architecture with proper separation of concerns - Production-ready configuration and middleware - Proper .gitignore excluding vendor/, database files, and build artifacts
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"tercul/graph"
|
|
|
|
"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/99designs/gqlgen/graphql/playground"
|
|
"github.com/vektah/gqlparser/v2/ast"
|
|
)
|
|
|
|
const defaultPort = "8080"
|
|
|
|
// SetupGraphQLServer configures and returns a GraphQL server with the provided resolver
|
|
func SetupGraphQLServer(resolver *graph.Resolver) *handler.Server {
|
|
srv := handler.New(graph.NewExecutableSchema(graph.Config{Resolvers: 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),
|
|
})
|
|
|
|
return srv
|
|
}
|
|
|
|
// SetupHTTPHandlers configures HTTP routes for the GraphQL playground and API
|
|
func SetupHTTPHandlers(srv *handler.Server, queryPath string) {
|
|
http.Handle("/", playground.Handler("GraphQL playground", queryPath))
|
|
http.Handle(queryPath, srv)
|
|
}
|