package main import ( "net/http" "tercul/internal/adapters/graphql" "tercul/internal/app" "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(application *app.Application, 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) // Apply dataloader middleware dataloaderHandler := graphql.Middleware(application, authHandler) // Create a mux to handle GraphQL endpoint only (no playground here; served separately in production) mux := http.NewServeMux() mux.Handle("/query", dataloaderHandler) return mux }