Module: Graphiti::Rails::RakeHelpers
- Extended by:
- TestHelpers
- Defined in:
- lib/graphiti/rails/rake_helpers.rb
Overview
Rake's namespace takes a block, and a block does not open a new definee,
so helpers defined inside one are defined on Object and turn up in every
request spec in the host app. They live here to stay off that namespace.
Class Method Summary collapse
-
.connection_pool_advisory ⇒ Object
The pool and RAILS_MAX_THREADS are read from this environment, and production may size both differently.
- .make_request(path, debug = false) ⇒ Object
-
.schema_path(path = nil) ⇒ Object
An engine runs the task from its own directory, not the host application's root.
-
.session ⇒ Object
::Rails throughout, because bare Rails resolves to Graphiti::Rails here.
- .setup_rails! ⇒ Object
Methods included from TestHelpers
handle_request_exceptions, handle_request_exceptions?
Class Method Details
.connection_pool_advisory ⇒ Object
The pool and RAILS_MAX_THREADS are read from this environment, and production may size both differently.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/graphiti/rails/rake_helpers.rb', line 30 def connection_pool_advisory return unless defined?(ActiveRecord::Base) pool = ActiveRecord::Base.connection_db_config.pool threads = ENV.fetch("RAILS_MAX_THREADS", 5).to_i sideload_threads = Graphiti.config.concurrency_max_threads needed = threads + sideload_threads + 1 return if pool.nil? || pool >= needed "WARNING database.yml pool is #{pool} in this environment. With concurrency on (the production default), " \ "each sideload holds its own connection, so pool should be at least " \ "web threads (#{threads}) + concurrency_max_threads (#{sideload_threads}) + 1 = #{needed}. " \ "If production sizes these differently, check the numbers there. " \ "See graphiti.dev/concepts/resources#concurrency-pool-sizing." end |
.make_request(path, debug = false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/graphiti/rails/rake_helpers.rb', line 46 def make_request(path, debug = false) if path.split("/").length == 2 path = "#{ApplicationResource.endpoint_namespace}#{path}" end path << if path.include?("?") "&cache=bust" else "?cache=bust" end path = "#{path}&debug=true" if debug handle_request_exceptions do headers = {Authorization: ENV["AUTHORIZATION_HEADER"]}.compact session.get(path.to_s, headers: headers) end JSON.parse(session.response.body) end |
.schema_path(path = nil) ⇒ Object
An engine runs the task from its own directory, not the host application's root.
19 20 21 |
# File 'lib/graphiti/rails/rake_helpers.rb', line 19 def schema_path(path = nil) path.nil? ? Graphiti.config.schema_path : File.(path, Dir.pwd) end |
.session ⇒ Object
::Rails throughout, because bare Rails resolves to Graphiti::Rails here.
14 15 16 |
# File 'lib/graphiti/rails/rake_helpers.rb', line 14 def session @session ||= ActionDispatch::Integration::Session.new(::Rails.application) end |
.setup_rails! ⇒ Object
23 24 25 26 27 |
# File 'lib/graphiti/rails/rake_helpers.rb', line 23 def setup_rails! ::Rails.application.eager_load! ::Rails.application.config.cache_classes = true ::Rails.application.config.action_controller.perform_caching = false end |