Skip to content

Commit 6871cc4

Browse files
authored
Merge pull request #4503 from aericson/handle-warden-nil
Handle context.warden being nil
2 parents b359fc9 + 2edf9e7 commit 6871cc4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/graphql/schema/warden.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ class Schema
3838
# @api private
3939
class Warden
4040
def self.from_context(context)
41-
context.warden # this might be a hash which won't respond to this
42-
rescue
41+
context.warden || PassThruWarden
42+
rescue NoMethodError
43+
# this might be a hash which won't respond to #warden
4344
PassThruWarden
4445
end
4546

spec/graphql/schema/warden_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,4 +961,15 @@ def self.visible?(member, context)
961961
end
962962
end
963963
end
964+
965+
describe "PassThruWarden is used when no warden is used" do
966+
it "uses PassThruWarden when a hash is used for context" do
967+
assert_equal GraphQL::Schema::Warden::PassThruWarden, GraphQL::Schema::Warden.from_context({})
968+
end
969+
970+
it "uses PassThruWarden when a warden on the context nor query" do
971+
context = GraphQL::Query::Context.new(query: OpenStruct.new(schema: GraphQL::Schema.new), values: {}, object: nil)
972+
assert_equal GraphQL::Schema::Warden::PassThruWarden, GraphQL::Schema::Warden.from_context(context)
973+
end
974+
end
964975
end

0 commit comments

Comments
 (0)