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 }