@@ -86,6 +86,56 @@ public function testResolvingEntityReference()
8686$ this ->assertEquals ($ expectedRef ,$ actualRef );
8787 }
8888
89+ public function testResolvingEntityReferenceWithoutAllKeys ()
90+ {
91+ $ expectedRef = [
92+ 'id ' =>1 ,
93+ 'email ' =>'luke@skywalker.com ' ,
94+ 'firstName ' =>'Luke ' ,
95+ 'lastName ' =>'Skywalker ' ,
96+ '__typename ' =>'User '
97+ ];
98+
99+ $ userType =new EntityObjectType ([
100+ 'name ' =>'User ' ,
101+ 'keyFields ' => ['id ' ,'email ' ],
102+ 'fields ' => [
103+ 'id ' => ['type ' => Type::int ()],
104+ 'email ' => ['type ' => Type::string ()],
105+ 'firstName ' => ['type ' => Type::string ()],
106+ 'lastName ' => ['type ' => Type::string ()]
107+ ],
108+ '__resolveReference ' =>function ()use ($ expectedRef ) {
109+ return $ expectedRef ;
110+ }
111+ ]);
112+
113+ $ actualRef =$ userType ->resolveReference (['email ' =>'luke@skywalker.com ' ,'__typename ' =>'User ' ]);
114+
115+ $ this ->assertEquals ($ expectedRef ,$ actualRef );
116+ }
117+
118+ public function testResolvingEntityReferenceWithoutAnyKeys ()
119+ {
120+ $ userType =new EntityObjectType ([
121+ 'name ' =>'User ' ,
122+ 'keyFields ' => ['id ' ,'email ' ],
123+ 'fields ' => [
124+ 'id ' => ['type ' => Type::int ()],
125+ 'email ' => ['type ' => Type::string ()],
126+ 'firstName ' => ['type ' => Type::string ()],
127+ 'lastName ' => ['type ' => Type::string ()]
128+ ],
129+ '__resolveReference ' =>function () {
130+ return null ;
131+ }
132+ ]);
133+
134+ $ this ->expectException (InvariantViolation::class);
135+
136+ $ userType ->resolveReference (['__typename ' =>'User ' ]);
137+ }
138+
89139public function testCreatingEntityRefType ()
90140 {
91141$ userTypeKeyFields = ['id ' ,'email ' ];