spec/graphql/relay/relation_connection_spec.rb in graphql-1.8.0.pre1 vs spec/graphql/relay/relation_connection_spec.rb in graphql-1.8.0.pre2

- old
+ new

@@ -72,10 +72,39 @@ StarWars::Base.where(faction_id: 2).count, result["data"]["empire"]["bases"]["totalCount"] ) end + it "makes one sql query for items and another for count" do + query_str = <<-GRAPHQL + { + empire { + bases(first: 2) { + totalCount + edges { + cursor + node { + name + } + } + } + } + } + GRAPHQL + io = StringIO.new + begin + prev_logger = ActiveRecord::Base.logger + ActiveRecord::Base.logger = Logger.new(io) + result = star_wars_query(query_str, "first" => 2) + ensure + ActiveRecord::Base.logger = prev_logger + end + assert_equal 2, io.string.scan("\n").count, "Two log entries" + assert_equal 3, result["data"]["empire"]["bases"]["totalCount"] + assert_equal 2, result["data"]["empire"]["bases"]["edges"].size + end + it "provides bidirectional_pagination" do result = star_wars_query(query_string, "first" => 1) last_cursor = get_last_cursor(result) result = star_wars_query(query_string, "first" => 1, "after" => last_cursor) @@ -561,9 +590,38 @@ assert_equal(["Headquarters"], get_names(result)) before = get_last_cursor(result) result = star_wars_query(query_string, "last" => 1, "nameIncludes" => "ea", "before" => before) assert_equal(["Death Star"], get_names(result)) + end + + it "makes one sql query for items and another for count" do + query_str = <<-GRAPHQL + { + empire { + basesAsSequelDataset(first: 2) { + totalCount + edges { + cursor + node { + name + } + } + } + } + } + GRAPHQL + result = nil + io = StringIO.new + begin + StarWars::DB.loggers << Logger.new(io) + result = star_wars_query(query_str, "first" => 2) + ensure + StarWars::DB.loggers.pop + end + assert_equal 2, io.string.scan("SELECT").count + assert_equal 3, result["data"]["empire"]["basesAsSequelDataset"]["totalCount"] + assert_equal 2, result["data"]["empire"]["basesAsSequelDataset"]["edges"].size end end end describe "#cursor_from_node" do