mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 04:01:34 +00:00
35 lines
1.1 KiB
Go
35 lines
1.1 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 {
|
|
srv := handler.NewDefaultServer(graphql.NewExecutableSchema(graphql.Config{Resolvers: resolver}))
|
|
|
|
// 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 {
|
|
srv := handler.NewDefaultServer(graphql.NewExecutableSchema(graphql.Config{Resolvers: resolver}))
|
|
|
|
// 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
|
|
}
|