Skip to content

Commit

Permalink
Merge pull request #4503 from aericson/handle-warden-nil
Browse files Browse the repository at this point in the history
Handle context.warden being nil
  • Loading branch information
rmosolgo authored Jun 5, 2023
2 parents b359fc9 + 2edf9e7 commit 6871cc4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/graphql/schema/warden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class Schema
# @api private
class Warden
def self.from_context(context)
context.warden # this might be a hash which won't respond to this
rescue
context.warden || PassThruWarden
rescue NoMethodError
# this might be a hash which won't respond to #warden
PassThruWarden
end

Expand Down
11 changes: 11 additions & 0 deletions spec/graphql/schema/warden_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -961,4 +961,15 @@ def self.visible?(member, context)
end
end
end

describe "PassThruWarden is used when no warden is used" do
it "uses PassThruWarden when a hash is used for context" do
assert_equal GraphQL::Schema::Warden::PassThruWarden, GraphQL::Schema::Warden.from_context({})
end

it "uses PassThruWarden when a warden on the context nor query" do
context = GraphQL::Query::Context.new(query: OpenStruct.new(schema: GraphQL::Schema.new), values: {}, object: nil)
assert_equal GraphQL::Schema::Warden::PassThruWarden, GraphQL::Schema::Warden.from_context(context)
end
end
end

0 comments on commit 6871cc4

Please sign in to comment.