spec/graphql/query/context_spec.rb in graphql-0.15.3 vs spec/graphql/query/context_spec.rb in graphql-0.16.0
- old
+ new
@@ -7,11 +7,13 @@
resolve -> (target, args, ctx) { ctx[args[:key]] }
end
field :contextAstNodeName, types.String do
resolve -> (target, args, ctx) { ctx.ast_node.class.name }
end
-
+ field :contextIrepNodeName, types.String do
+ resolve -> (target, args, ctx) { ctx.irep_node.class.name }
+ end
field :queryName, types.String do
resolve -> (target, args, ctx) { ctx.query.class.name }
end
}}
let(:schema) { GraphQL::Schema.new(query: query_type, mutation: nil)}
@@ -37,10 +39,21 @@
expected = {"data" => {"contextAstNodeName" => "GraphQL::Language::Nodes::Field"}}
assert_equal(expected, result)
end
end
+ describe "access to the InternalRepresentation node" do
+ let(:query_string) { %|
+ query getCtx { contextIrepNodeName }
+ |}
+
+ it "provides access to the AST node" do
+ expected = {"data" => {"contextIrepNodeName" => "GraphQL::InternalRepresentation::Node"}}
+ assert_equal(expected, result)
+ end
+ end
+
describe "access to the query" do
let(:query_string) { %|
query getCtx { queryName }
|}
@@ -53,8 +66,18 @@
describe "empty values" do
let(:context) { GraphQL::Query::Context.new(query: OpenStruct.new(schema: schema), values: nil) }
it "returns nil for any key" do
assert_equal(nil, context[:some_key])
+ end
+ end
+
+ describe "assigning values" do
+ let(:context) { GraphQL::Query::Context.new(query: OpenStruct.new(schema: schema), values: nil) }
+
+ it "allows you to assign new contexts" do
+ assert_equal(nil, context[:some_key])
+ context[:some_key] = "wow!"
+ assert_equal("wow!", context[:some_key])
end
end
end