Skip to content

Commit 6a30ba3

Browse files
author
Robert Mosolgo
authored
Merge pull request #1955 from ojab/master
Add GraphQL::Query::Context#to_hash to allow splatting
2 parents 5954bdd + b6a8d48 commit 6a30ba3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/graphql/query/context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def initialize(query:, values: , object:)
160160
# @api private
161161
attr_writer :value
162162

163-
def_delegators :@provided_values, :[], :[]=, :to_h, :key?, :fetch, :dig
163+
def_delegators :@provided_values, :[], :[]=, :to_h, :to_hash, :key?, :fetch, :dig
164164
def_delegators :@query, :trace
165165

166166
# @!method [](key)

spec/graphql/query/context_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@
235235
end
236236
end
237237

238+
describe "splatting" do
239+
let(:context) { GraphQL::Query::Context.new(query: OpenStruct.new(schema: schema), values: {a: {b: 1}}, object: nil) }
240+
241+
let(:splat) { ->(**context) { context } }
242+
243+
it "runs successfully" do
244+
assert_equal({a: { b: 1 }}, splat.call(context))
245+
end
246+
end
247+
238248
describe "accessing context after the fact" do
239249
let(:query_string) { %|
240250
{ pushContext }

0 commit comments

Comments
 (0)