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 }