mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 00:31:35 +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
37 lines
1.1 KiB
Go
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
|
|
}
|