tercul-backend/graph/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

37 lines
1.1 KiB
Go

package graph
import (
"net/http"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"tercul/auth"
)
// NewServer creates a new GraphQL server with the given resolver
func NewServer(resolver *Resolver) http.Handler {
srv := handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolver}))
// Create a mux to handle both GraphQL and playground
mux := http.NewServeMux()
mux.Handle("/query", srv)
mux.Handle("/", playground.Handler("GraphQL playground", "/query"))
return mux
}
// NewServerWithAuth creates a new GraphQL server with authentication middleware
func NewServerWithAuth(resolver *Resolver, jwtManager *auth.JWTManager) http.Handler {
srv := handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolver}))
// Apply authentication middleware to GraphQL endpoint
authHandler := auth.GraphQLAuthMiddleware(jwtManager)(srv)
// Create a mux to handle both GraphQL and playground
mux := http.NewServeMux()
mux.Handle("/query", authHandler)
mux.Handle("/", playground.Handler("GraphQL playground", "/query"))
return mux
}