@@ -999,4 +999,102 @@ def exec_multiplex(...)
999999 assert_nil Fiber [ :__graphql_runtime_info ]
10001000 end
10011001 end
1002+
1003+ describe "list items with dataloader and current_path usage" do
1004+ class ListBugExampleSchema < GraphQL ::Schema
1005+ class PathTest < GraphQL ::Schema ::Directive
1006+ locations ( GraphQL ::Schema ::Directive ::INLINE_FRAGMENT )
1007+
1008+ def self . resolve ( object , arguments , context )
1009+ context [ :test_paths ] ||= [ ]
1010+ context [ :test_paths ] << context [ :current_path ]
1011+ super
1012+ end
1013+ end
1014+
1015+ class DataloadedSource < GraphQL ::Dataloader ::Source
1016+ def fetch ( objects )
1017+ objects . map ( &:dataloaded )
1018+ end
1019+ end
1020+
1021+ class DataloadedType < GraphQL ::Schema ::Object
1022+ field :int , Integer
1023+ end
1024+
1025+ class SiblingType < GraphQL ::Schema ::Object
1026+ field :dataloaded , DataloadedType , null : false
1027+
1028+ def dataloaded
1029+ dataload ( DataloadedSource , object )
1030+ end
1031+ end
1032+
1033+
1034+ class ChildType < GraphQL ::Schema ::Object
1035+ field :int , Integer , null : false
1036+ end
1037+
1038+ class ParentType < GraphQL ::Schema ::Object
1039+ field :children , [ ChildType ] , null : false
1040+ end
1041+
1042+ class Query < GraphQL ::Schema ::Object
1043+ field :parent , ParentType do
1044+ argument :name , String
1045+ end
1046+
1047+ def parent ( name :)
1048+ object . parent
1049+ end
1050+
1051+ field :siblings , [ SiblingType ] , null : false
1052+ end
1053+
1054+ query ( Query )
1055+ use GraphQL ::Dataloader
1056+ directive PathTest
1057+ end
1058+
1059+ it "correctly provides current_type at selections-level" do
1060+ query_str = <<~GRAPHQL
1061+ query {
1062+ parent(name: "ABC") {
1063+ children {
1064+ ... @pathTest {
1065+ int
1066+ }
1067+ }
1068+ }
1069+ siblings {
1070+ dataloaded {
1071+ int
1072+ }
1073+ }
1074+ }
1075+ GRAPHQL
1076+
1077+ root_value = OpenStruct . new (
1078+ parent : OpenStruct . new (
1079+ children : [
1080+ OpenStruct . new ( int : 1 ) ,
1081+ ]
1082+ ) ,
1083+ siblings : [
1084+ OpenStruct . new ( dataloaded : OpenStruct . new ( int : 2 ) ) ,
1085+ ]
1086+ )
1087+
1088+ result = ListBugExampleSchema . execute ( query_str , root_value : root_value )
1089+ expected_result = {
1090+ "data" => {
1091+ "parent" => { "children" => [ { "int" => 1 } ] } ,
1092+ "siblings" => [ { "dataloaded" => { "int" => 2 } } ]
1093+ }
1094+ }
1095+
1096+ assert_graphql_equal expected_result , result
1097+ assert_equal [ [ "parent" , "children" , 0 ] ] , result . context [ :test_paths ]
1098+ end
1099+ end
10021100end
0 commit comments