tercul-backend/server.go
Damir Mukimov 4957117cb6 Initial commit: Tercul Go project with comprehensive architecture
- 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
2025-08-13 07:42:32 +02:00

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)
}