spec/graphql/query/context_spec.rb in graphql-1.8.9 vs spec/graphql/query/context_spec.rb in graphql-1.8.10
- old
+ new
@@ -215,9 +215,27 @@
assert_equal({b: 2}, context.namespace(:stuff))
end
end
end
+ describe "read values" do
+ let(:context) { GraphQL::Query::Context.new(query: OpenStruct.new(schema: schema), values: {a: {b: 1}}, object: nil) }
+
+ it "allows you to read values of contexts using []" do
+ assert_equal({b: 1}, context[:a])
+ end
+
+ it "allows you to read values of contexts using dig" do
+ if RUBY_VERSION >= '2.3.0'
+ assert_equal(1, context.dig(:a, :b))
+ else
+ assert_raises NoMethodError do
+ context.dig(:a, :b)
+ end
+ end
+ end
+ end
+
describe "accessing context after the fact" do
let(:query_string) { %|
{ pushContext }
|}