Skip to content

Commit 8298e97

Browse files
authored
Merge pull request #5505 from rmosolgo/fix-engine-routes
Lazily define engine routes using routes do ... end
2 parents 98f0d9e + f903cb5 commit 8298e97

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/graphql.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ class << self
126126
autoload :Testing, "graphql/testing"
127127
autoload :Current, "graphql/current"
128128
if defined?(::Rails::Engine)
129-
autoload :Dashboard, 'graphql/dashboard'
129+
# This needs to be defined before Rails runs `add_routing_paths`,
130+
# otherwise GraphQL::Dashboard's routes won't have been gathered for loading
131+
# when that initializer runs.
132+
require 'graphql/dashboard'
130133
end
131134
end
132135

lib/graphql/dashboard.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module Graphql
3434
class Dashboard < Rails::Engine
3535
engine_name "graphql_dashboard"
3636
isolate_namespace(Graphql::Dashboard)
37-
routes.draw do
37+
routes do
3838
root "landings#show"
3939
resources :statics, only: :show, constraints: { id: /[0-9A-Za-z\-.]+/ }
4040

@@ -76,6 +76,8 @@ class Dashboard < Rails::Engine
7676
resources :subscriptions, only: [:show], constraints: { id: /[a-zA-Z0-9\-]+/ }
7777
post "/subscriptions/clear_all", to: "subscriptions#clear_all", as: :clear_all
7878
end
79+
80+
ApplicationController.include(Dashboard.routes.url_helpers)
7981
end
8082

8183
class ApplicationController < ActionController::Base

0 commit comments

Comments
 (0)