Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/graphql/schema/visibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class Schema
class Visibility
# @param schema [Class<GraphQL::Schema>]
# @param profiles [Hash<Symbol => Hash>] A hash of `name => context` pairs for preloading visibility profiles
# @param preload [Boolean] if `true`, load the default schema profile and all named profiles immediately (defaults to `true` for `Rails.env.production?`)
# @param preload [Boolean] if `true`, load the default schema profile and all named profiles immediately (defaults to `false` for `Rails.env.development?`)
# @param migration_errors [Boolean] if `true`, raise an error when `Visibility` and `Warden` return different results
def self.use(schema, dynamic: false, profiles: EmptyObjects::EMPTY_HASH, preload: (defined?(Rails.env) ? Rails.env.production? : nil), migration_errors: false)
def self.use(schema, dynamic: false, profiles: EmptyObjects::EMPTY_HASH, preload: (defined?(Rails.env) ? !Rails.env.development? : nil), migration_errors: false)
profiles&.each { |name, ctx|
ctx[:visibility_profile] = name
ctx.freeze
Expand Down
24 changes: 24 additions & 0 deletions spec/graphql/schema/visibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,28 @@ def self.resolve_type(...); Thing; end
res = InterfaceSuperclassSchema.execute("{ node { id ... on Thing { name } } }")
assert_equal "Hat", res["data"]["node"]["name"]
end

focus
it "defaults to preload: true for Rails.env.staging?" do
prev_rails = defined?(Rails) ? Rails : nil
mock_env = OpenStruct.new(:development? => false)
Object.const_set(:Rails, OpenStruct.new(env: mock_env))
schema = Class.new(GraphQL::Schema) do
use GraphQL::Schema::Visibility
end
refute Rails.env.development?
assert schema.visibility.preload?

mock_env[:development?] = true

schema = Class.new(GraphQL::Schema) do
use GraphQL::Schema::Visibility
end
assert Rails.env.development?
refute schema.visibility.preload?
ensure
if prev_rails
const_set(:Rails, prev_rails)
end
end
end
Loading