package api import ( "omega-server/local/controller" "omega-server/local/graphql/handler" graphqlService "omega-server/local/graphql/service" "omega-server/local/service" "omega-server/local/utl/common" "omega-server/local/utl/configs" "omega-server/local/utl/logging" "github.com/gofiber/fiber/v2" "go.uber.org/dig" ) // Routes // Initializes web api controllers and its corresponding routes. // // Args: // *fiber.App: Fiber Application func Init(di *dig.Container, app *fiber.App) { // Protected routes groups := app.Group(configs.Prefix) routeGroups := &common.RouteGroups{ API: groups.Group("/api"), Auth: groups.Group("/auth"), Users: groups.Group("/membership"), } err := di.Provide(func() *common.RouteGroups { return routeGroups }) if err != nil { logging.Panic("unable to bind routes") } // Initialize GraphQL initGraphQL(di, groups) controller.InitializeControllers(di) } // initGraphQL initializes GraphQL endpoints func initGraphQL(di *dig.Container, groups fiber.Router) { err := di.Invoke(func(membershipService *service.MembershipService) error { // Create GraphQL service gqlService := graphqlService.NewGraphQLService(membershipService) _ = gqlService // Use the service (placeholder) // Create GraphQL handler graphqlHandler := handler.NewGraphQLHandler(membershipService) // Register GraphQL routes groups.Post("/graphql", graphqlHandler.Handle) // GraphQL playground/schema endpoint groups.Get("/graphql", func(c *fiber.Ctx) error { return c.SendString(graphqlHandler.GetSchema()) }) logging.Info("GraphQL endpoint initialized at /graphql") return nil }) if err != nil { logging.Panic("failed to initialize GraphQL: " + err.Error()) } }