11
11
12
12
'use strict' ;
13
13
14
+ import type { ClientEdgesTestUpperName$key } from './__generated__/ClientEdgesTestUpperName.graphql' ;
15
+
14
16
const React = require ( 'react' ) ;
15
17
const {
16
18
RelayEnvironmentProvider,
@@ -24,6 +26,7 @@ const {
24
26
RecordSource,
25
27
RelayFeatureFlags,
26
28
graphql,
29
+ readFragment,
27
30
} = require ( 'relay-runtime' ) ;
28
31
const RelayObservable = require ( 'relay-runtime/network/RelayObservable' ) ;
29
32
const RelayModernStore = require ( 'relay-runtime/store/RelayModernStore' ) ;
@@ -44,6 +47,23 @@ export function same_user_client_edge(): {id: string} {
44
47
return { id : '1' } ;
45
48
}
46
49
50
+ /**
51
+ * @RelayResolver User.upper_name: String
52
+ * @rootFragment ClientEdgesTestUpperName
53
+ */
54
+
55
+ export function upper_name ( key : ClientEdgesTestUpperName$key ) : ?string {
56
+ const user = readFragment (
57
+ graphql `
58
+ fragment ClientEdgesTestUpperName on User {
59
+ name
60
+ }
61
+ ` ,
62
+ key ,
63
+ ) ;
64
+ return user ?. name ?. toUpperCase ( ) ;
65
+ }
66
+
47
67
describe . each ( [ [ true ] , [ false ] ] ) (
48
68
'RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY = %s' ,
49
69
( activityEnabled : boolean ) => {
@@ -402,5 +422,81 @@ describe.each([[true], [false]])(
402
422
// });
403
423
// expect(renderer?.toJSON()).toBe('Alice');
404
424
} ) ;
425
+
426
+ it ( 'should fetch data missing client edge to server data in resolver @rootFragment' , ( ) => {
427
+ function TestComponent ( ) {
428
+ return (
429
+ < RelayEnvironmentProvider environment = { environment } >
430
+ < React . Suspense fallback = "Loading" >
431
+ < InnerComponent />
432
+ </ React . Suspense >
433
+ </ RelayEnvironmentProvider >
434
+ ) ;
435
+ }
436
+
437
+ const variables = { } ;
438
+ function InnerComponent ( ) {
439
+ const data = useLazyLoadQuery (
440
+ graphql `
441
+ query ClientEdgesTest6Query {
442
+ me {
443
+ same_user_client_edge @waterfall {
444
+ # No fields here means that we render without detecting any
445
+ # missing data here and don't attempt to fetch the @waterfall
446
+ # query.
447
+ #
448
+ # The same bug can be triggered by adding a field that is already
449
+ # in the store for an unrelated reason.
450
+ upper_name
451
+ # Adding "name" here will cause the query to be fetched.
452
+ }
453
+ }
454
+ }
455
+ ` ,
456
+ variables ,
457
+ ) ;
458
+
459
+ return data . me ?. same_user_client_edge ?. upper_name ;
460
+ }
461
+
462
+ // This will be updated when we add the new assertions as part of a fix for
463
+ // this bug.
464
+ // eslint-disable-next-line no-unused-vars
465
+ let renderer ;
466
+ TestRenderer . act ( ( ) => {
467
+ renderer = TestRenderer . create ( < TestComponent /> ) ;
468
+ } ) ;
469
+
470
+ // Oops, we didn't fetch the query!
471
+ expect ( fetchFn . mock . calls . length ) . toEqual ( 0 ) ;
472
+
473
+ // Following are the assertions that SHOULD pass.
474
+
475
+ // expect(fetchFn.mock.calls.length).toEqual(1);
476
+ // // We should send the client-edge query
477
+ // // $FlowFixMe[invalid-tuple-index] Error found while enabling LTI on this file
478
+ // expect(fetchFn.mock.calls[0][0].name).toBe(
479
+ // 'ClientEdgeQuery_ClientEdgesTest6Query_me__same_user_client_edge',
480
+ // );
481
+ // // Check variables
482
+ // // $FlowFixMe[invalid-tuple-index] Error found while enabling LTI on this file
483
+ // expect(fetchFn.mock.calls[0][1]).toEqual({id: '1'});
484
+ // expect(renderer?.toJSON()).toBe('Loading');
485
+
486
+ // TestRenderer.act(() => {
487
+ // // This should resolve client-edge query
488
+ // networkSink.next({
489
+ // data: {
490
+ // node: {
491
+ // id: '1',
492
+ // __typename: 'User',
493
+ // name: 'Alice',
494
+ // },
495
+ // },
496
+ // });
497
+ // jest.runAllImmediates();
498
+ // });
499
+ // expect(renderer?.toJSON()).toBe('ALICE');
500
+ } ) ;
405
501
} ,
406
502
) ;
0 commit comments