@@ -29,9 +29,34 @@ const {
29
29
RelayFeatureFlags,
30
30
graphql,
31
31
} = require ( 'relay-runtime' ) ;
32
+ const {
33
+ addTodo,
34
+ } = require ( 'relay-runtime/store/__tests__/resolvers/ExampleTodoStore' ) ;
32
35
const LiveResolverStore = require ( 'relay-runtime/store/experimental-live-resolvers/LiveResolverStore' ) ;
33
36
const { createMockEnvironment} = require ( 'relay-test-utils' ) ;
34
37
38
+ /**
39
+ * CLIENT EDGE TO PLURAL LIVE STRONG CLIENT OBJECT
40
+ */
41
+
42
+ /**
43
+ * @RelayResolver Query.edge_to_plural_live_objects_some_exist: [TodoModel]
44
+ */
45
+ export function edge_to_plural_live_objects_some_exist ( ) : $ReadOnlyArray < {
46
+ id : DataID ,
47
+ } > {
48
+ return [ { id : 'todo-1' } , { id : 'THERE_IS_NO_TODO_WITH_THIS_ID' } ] ;
49
+ }
50
+
51
+ /**
52
+ * @RelayResolver Query.edge_to_plural_live_objects_none_exist: [TodoModel]
53
+ */
54
+ export function edge_to_plural_live_objects_none_exist ( ) : $ReadOnlyArray < {
55
+ id : DataID ,
56
+ } > {
57
+ return [ { id : 'NO_TODO_1' } , { id : 'NO_TODO_2' } ] ;
58
+ }
59
+
35
60
/**
36
61
* CLIENT EDGE TO LIVE STRONG CLIENT OBJECT
37
62
*/
@@ -158,6 +183,73 @@ describe.each([
158
183
beforeEach ( ( ) => {
159
184
environment = createEnvironment ( ) ;
160
185
} ) ;
186
+ test ( 'client edge to plural IDs, none have corresponding live object' , ( ) => {
187
+ function TodoNullComponent ( ) {
188
+ const data = useClientQuery (
189
+ graphql `
190
+ query RelayResolverNullableModelClientEdgeTest_PluralLiveModelNoneExist_Query {
191
+ edge_to_plural_live_objects_none_exist {
192
+ id
193
+ description
194
+ }
195
+ }
196
+ ` ,
197
+ { } ,
198
+ ) ;
199
+
200
+ invariant ( data != null , 'Query response should be nonnull' ) ;
201
+ expect ( data . edge_to_plural_live_objects_none_exist ) . toHaveLength ( 2 ) ;
202
+ return data . edge_to_plural_live_objects_none_exist
203
+ ?. map ( item =>
204
+ item
205
+ ? `${ item . id ?? 'unknown' } - ${ item . description ?? 'unknown' } `
206
+ : 'unknown' ,
207
+ )
208
+ . join ( ',' ) ;
209
+ }
210
+
211
+ const renderer = TestRenderer . create (
212
+ < EnvironmentWrapper environment = { environment } >
213
+ < TodoNullComponent />
214
+ </ EnvironmentWrapper > ,
215
+ ) ;
216
+ expect ( renderer . toJSON ( ) ) . toEqual ( 'unknown,unknown' ) ;
217
+ } ) ;
218
+
219
+ test ( 'client edge to plural IDs, some with no corresponding live object' , ( ) => {
220
+ function TodoNullComponent ( ) {
221
+ const data = useClientQuery (
222
+ graphql `
223
+ query RelayResolverNullableModelClientEdgeTest_PluralLiveModel_Query {
224
+ edge_to_plural_live_objects_some_exist {
225
+ id
226
+ description
227
+ }
228
+ }
229
+ ` ,
230
+ { } ,
231
+ ) ;
232
+
233
+ invariant ( data != null , 'Query response should be nonnull' ) ;
234
+ expect ( data . edge_to_plural_live_objects_some_exist ) . toHaveLength ( 2 ) ;
235
+ return data . edge_to_plural_live_objects_some_exist
236
+ ?. map ( item =>
237
+ item
238
+ ? `${ item . id ?? 'unknown' } - ${ item . description ?? 'unknown' } `
239
+ : 'unknown' ,
240
+ )
241
+ . join ( ',' ) ;
242
+ }
243
+
244
+ addTodo ( 'Test todo' ) ;
245
+ const renderer = TestRenderer . create (
246
+ < EnvironmentWrapper environment = { environment } >
247
+ < TodoNullComponent />
248
+ </ EnvironmentWrapper > ,
249
+ ) ;
250
+ expect ( renderer . toJSON ( ) ) . toEqual ( 'todo-1 - Test todo,unknown' ) ;
251
+ } ) ;
252
+
161
253
test ( 'client edge to ID with no corresponding live object' , ( ) => {
162
254
function TodoNullComponent ( ) {
163
255
const data = useClientQuery (
0 commit comments