mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
This change introduces a service layer to encapsulate the business logic for each domain aggregate. This will make the code more modular, testable, and easier to maintain. The following services have been created: - author - bookmark - category - collection - comment - like - tag - translation - user The main Application struct has been updated to use these new services. The integration test suite has also been updated to use the new Application struct and services. This is a work in progress. The next step is to fix the compilation errors and then refactor the resolvers to use the new services.
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"tercul/internal/adapters/graphql"
|
|
"tercul/internal/platform/auth"
|
|
|
|
"github.com/99designs/gqlgen/graphql/handler"
|
|
)
|
|
|
|
// NewServer creates a new GraphQL server with the given resolver
|
|
func NewServer(resolver *graphql.Resolver) http.Handler {
|
|
c := graphql.Config{Resolvers: resolver}
|
|
c.Directives.Binding = graphql.Binding
|
|
srv := handler.NewDefaultServer(graphql.NewExecutableSchema(c))
|
|
|
|
// Create a mux to handle GraphQL endpoint only (no playground here; served separately in production)
|
|
mux := http.NewServeMux()
|
|
mux.Handle("/query", srv)
|
|
|
|
return mux
|
|
}
|
|
|
|
// NewServerWithAuth creates a new GraphQL server with authentication middleware
|
|
func NewServerWithAuth(resolver *graphql.Resolver, jwtManager *auth.JWTManager) http.Handler {
|
|
c := graphql.Config{Resolvers: resolver}
|
|
c.Directives.Binding = graphql.Binding
|
|
srv := handler.NewDefaultServer(graphql.NewExecutableSchema(c))
|
|
|
|
// Apply authentication middleware to GraphQL endpoint
|
|
authHandler := auth.GraphQLAuthMiddleware(jwtManager)(srv)
|
|
|
|
// Create a mux to handle GraphQL endpoint only (no playground here; served separately in production)
|
|
mux := http.NewServeMux()
|
|
mux.Handle("/query", authHandler)
|
|
|
|
return mux
|
|
}
|