houdini 0.17.13 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/build/cmd-cjs/index.js +438 -201
  2. package/build/cmd-esm/index.js +438 -201
  3. package/build/codegen/utils/flattenSelections.d.ts +3 -1
  4. package/build/codegen-cjs/index.js +405 -180
  5. package/build/codegen-esm/index.js +405 -180
  6. package/build/lib/config.d.ts +8 -3
  7. package/build/lib-cjs/index.js +141 -81
  8. package/build/lib-esm/index.js +141 -81
  9. package/build/runtime/cache/subscription.d.ts +3 -3
  10. package/build/runtime/lib/config.d.ts +2 -1
  11. package/build/runtime/lib/scalars.d.ts +2 -2
  12. package/build/runtime/lib/selection.d.ts +2 -0
  13. package/build/runtime/lib/types.d.ts +26 -16
  14. package/build/runtime-cjs/cache/cache.js +38 -23
  15. package/build/runtime-cjs/cache/lists.js +40 -26
  16. package/build/runtime-cjs/cache/subscription.d.ts +3 -3
  17. package/build/runtime-cjs/cache/subscription.js +23 -21
  18. package/build/runtime-cjs/lib/config.d.ts +2 -1
  19. package/build/runtime-cjs/lib/scalars.d.ts +2 -2
  20. package/build/runtime-cjs/lib/scalars.js +9 -6
  21. package/build/runtime-cjs/lib/selection.d.ts +2 -0
  22. package/build/runtime-cjs/lib/selection.js +39 -0
  23. package/build/runtime-cjs/lib/types.d.ts +26 -16
  24. package/build/runtime-esm/cache/cache.js +38 -23
  25. package/build/runtime-esm/cache/lists.js +40 -26
  26. package/build/runtime-esm/cache/subscription.d.ts +3 -3
  27. package/build/runtime-esm/cache/subscription.js +23 -21
  28. package/build/runtime-esm/lib/config.d.ts +2 -1
  29. package/build/runtime-esm/lib/scalars.d.ts +2 -2
  30. package/build/runtime-esm/lib/scalars.js +9 -6
  31. package/build/runtime-esm/lib/selection.d.ts +2 -0
  32. package/build/runtime-esm/lib/selection.js +15 -0
  33. package/build/runtime-esm/lib/types.d.ts +26 -16
  34. package/build/test/index.d.ts +1 -2
  35. package/build/test-cjs/index.js +485 -195
  36. package/build/test-esm/index.js +485 -195
  37. package/build/vite-cjs/index.js +438 -193
  38. package/build/vite-esm/index.js +438 -193
  39. package/package.json +2 -2
  40. package/build/runtime-cjs/cache/tests/availability.test.js +0 -357
  41. package/build/runtime-cjs/cache/tests/gc.test.js +0 -271
  42. package/build/runtime-cjs/cache/tests/keys.test.js +0 -34
  43. package/build/runtime-cjs/cache/tests/list.test.js +0 -3390
  44. package/build/runtime-cjs/cache/tests/readwrite.test.js +0 -1076
  45. package/build/runtime-cjs/cache/tests/scalars.test.js +0 -181
  46. package/build/runtime-cjs/cache/tests/storage.test.js +0 -280
  47. package/build/runtime-cjs/cache/tests/subscriptions.test.js +0 -1469
  48. package/build/runtime-cjs/lib/scalars.test.js +0 -736
  49. package/build/runtime-esm/cache/tests/availability.test.js +0 -356
  50. package/build/runtime-esm/cache/tests/gc.test.js +0 -270
  51. package/build/runtime-esm/cache/tests/keys.test.js +0 -33
  52. package/build/runtime-esm/cache/tests/list.test.js +0 -3389
  53. package/build/runtime-esm/cache/tests/readwrite.test.js +0 -1075
  54. package/build/runtime-esm/cache/tests/scalars.test.js +0 -180
  55. package/build/runtime-esm/cache/tests/storage.test.js +0 -279
  56. package/build/runtime-esm/cache/tests/subscriptions.test.js +0 -1468
  57. package/build/runtime-esm/lib/scalars.test.js +0 -735
@@ -1,1075 +0,0 @@
1
- import { test, expect } from "vitest";
2
- import { testConfigFile } from "../../../test";
3
- import { Cache } from "../cache";
4
- const config = testConfigFile();
5
- test("write selection to root", function() {
6
- const cache = new Cache(config);
7
- const data = {
8
- viewer: {
9
- id: "1",
10
- firstName: "bob"
11
- }
12
- };
13
- const selection = {
14
- viewer: {
15
- type: "User",
16
- keyRaw: "viewer",
17
- fields: {
18
- id: {
19
- type: "ID",
20
- keyRaw: "id"
21
- },
22
- firstName: {
23
- type: "String",
24
- keyRaw: "firstName"
25
- }
26
- }
27
- }
28
- };
29
- cache.write({
30
- selection,
31
- data
32
- });
33
- expect(
34
- cache.read({
35
- selection
36
- }).data
37
- ).toEqual({
38
- viewer: {
39
- id: "1",
40
- firstName: "bob"
41
- }
42
- });
43
- });
44
- test("linked records with updates", function() {
45
- const cache = new Cache(config);
46
- const deeplyNestedSelection = {
47
- viewer: {
48
- type: "User",
49
- keyRaw: "viewer",
50
- fields: {
51
- id: {
52
- type: "ID",
53
- keyRaw: "id"
54
- },
55
- firstName: {
56
- type: "String",
57
- keyRaw: "firstName"
58
- },
59
- parent: {
60
- type: "User",
61
- keyRaw: "parent",
62
- fields: {
63
- id: {
64
- type: "ID",
65
- keyRaw: "id"
66
- },
67
- firstName: {
68
- type: "String",
69
- keyRaw: "firstName"
70
- }
71
- }
72
- }
73
- }
74
- }
75
- };
76
- const userFields = {
77
- id: {
78
- type: "ID",
79
- keyRaw: "id"
80
- },
81
- firstName: {
82
- type: "String",
83
- keyRaw: "firstName"
84
- },
85
- parent: {
86
- type: "User",
87
- keyRaw: "parent",
88
- nullable: true,
89
- fields: {
90
- id: {
91
- type: "ID",
92
- keyRaw: "id"
93
- }
94
- }
95
- }
96
- };
97
- cache.write({
98
- selection: deeplyNestedSelection,
99
- data: {
100
- viewer: {
101
- id: "1",
102
- firstName: "bob",
103
- parent: {
104
- id: "2",
105
- firstName: "jane"
106
- }
107
- }
108
- }
109
- });
110
- expect(cache.read({ selection: userFields, parent: "User:1" }).data).toEqual({
111
- id: "1",
112
- firstName: "bob",
113
- parent: {
114
- id: "2"
115
- }
116
- });
117
- expect(cache.read({ selection: userFields, parent: "User:2" }).data).toEqual({
118
- id: "2",
119
- firstName: "jane",
120
- parent: null
121
- });
122
- cache.write({
123
- selection: deeplyNestedSelection,
124
- data: {
125
- viewer: {
126
- id: "2",
127
- firstName: "jane-prime",
128
- parent: {
129
- id: "3",
130
- firstName: "mary"
131
- }
132
- }
133
- }
134
- });
135
- expect(cache.read({ selection: userFields, parent: "User:2" }).data).toEqual({
136
- id: "2",
137
- firstName: "jane-prime",
138
- parent: {
139
- id: "3"
140
- }
141
- });
142
- expect(cache.read({ selection: userFields, parent: "User:3" }).data).toEqual({
143
- id: "3",
144
- firstName: "mary",
145
- parent: null
146
- });
147
- });
148
- test("linked lists", function() {
149
- const cache = new Cache(config);
150
- const selection = {
151
- viewer: {
152
- type: "User",
153
- keyRaw: "viewer",
154
- fields: {
155
- id: {
156
- type: "ID",
157
- keyRaw: "id"
158
- },
159
- firstName: {
160
- type: "String",
161
- keyRaw: "firstName"
162
- },
163
- friends: {
164
- type: "User",
165
- keyRaw: "friends",
166
- fields: {
167
- id: {
168
- type: "ID",
169
- keyRaw: "id"
170
- },
171
- firstName: {
172
- type: "String",
173
- keyRaw: "firstName"
174
- }
175
- }
176
- }
177
- }
178
- }
179
- };
180
- cache.write({
181
- selection,
182
- data: {
183
- viewer: {
184
- id: "1",
185
- firstName: "bob",
186
- friends: [
187
- {
188
- id: "2",
189
- firstName: "jane"
190
- },
191
- {
192
- id: "3",
193
- firstName: "mary"
194
- }
195
- ]
196
- }
197
- }
198
- });
199
- expect(cache.read({ selection: selection.viewer.fields, parent: "User:1" }).data).toEqual({
200
- id: "1",
201
- firstName: "bob",
202
- friends: [
203
- {
204
- id: "2",
205
- firstName: "jane"
206
- },
207
- {
208
- id: "3",
209
- firstName: "mary"
210
- }
211
- ]
212
- });
213
- });
214
- test("list as value with args", function() {
215
- const cache = new Cache(config);
216
- cache.write({
217
- selection: {
218
- viewer: {
219
- type: "User",
220
- keyRaw: "viewer",
221
- fields: {
222
- id: {
223
- type: "ID",
224
- keyRaw: "id"
225
- },
226
- firstName: {
227
- type: "String",
228
- keyRaw: "firstName"
229
- },
230
- favoriteColors: {
231
- type: "String",
232
- keyRaw: 'favoriteColors(where: "foo")'
233
- }
234
- }
235
- }
236
- },
237
- data: {
238
- viewer: {
239
- id: "1",
240
- firstName: "bob",
241
- favoriteColors: ["red", "green", "blue"]
242
- }
243
- }
244
- });
245
- expect(
246
- cache.read({
247
- selection: {
248
- favoriteColors: {
249
- type: "String",
250
- keyRaw: 'favoriteColors(where: "foo")'
251
- }
252
- },
253
- parent: "User:1"
254
- }).data
255
- ).toEqual({
256
- favoriteColors: ["red", "green", "blue"]
257
- });
258
- });
259
- test("writing abstract objects", function() {
260
- const cache = new Cache(config);
261
- const data = {
262
- viewer: {
263
- __typename: "User",
264
- id: "1",
265
- firstName: "bob"
266
- }
267
- };
268
- cache.write({
269
- selection: {
270
- viewer: {
271
- type: "Node",
272
- abstract: true,
273
- keyRaw: "viewer",
274
- fields: {
275
- __typename: {
276
- type: "String",
277
- keyRaw: "__typename"
278
- },
279
- id: {
280
- type: "ID",
281
- keyRaw: "id"
282
- },
283
- firstName: {
284
- type: "String",
285
- keyRaw: "firstName"
286
- }
287
- }
288
- }
289
- },
290
- data
291
- });
292
- expect(
293
- cache.read({
294
- parent: "User:1",
295
- selection: {
296
- __typename: {
297
- type: "String",
298
- keyRaw: "__typename"
299
- },
300
- id: {
301
- type: "ID",
302
- keyRaw: "id"
303
- },
304
- firstName: {
305
- type: "String",
306
- keyRaw: "firstName"
307
- }
308
- }
309
- }).data
310
- ).toEqual({
311
- __typename: "User",
312
- id: "1",
313
- firstName: "bob"
314
- });
315
- });
316
- test("writing abstract lists", function() {
317
- const cache = new Cache(config);
318
- const data = {
319
- nodes: [
320
- {
321
- __typename: "User",
322
- id: "1",
323
- firstName: "bob"
324
- },
325
- {
326
- __typename: "User",
327
- id: "2",
328
- firstName: "bob"
329
- }
330
- ]
331
- };
332
- cache.write({
333
- selection: {
334
- nodes: {
335
- type: "Node",
336
- abstract: true,
337
- keyRaw: "nodes",
338
- fields: {
339
- __typename: {
340
- type: "String",
341
- keyRaw: "__typename"
342
- },
343
- id: {
344
- type: "ID",
345
- keyRaw: "id"
346
- },
347
- firstName: {
348
- type: "String",
349
- keyRaw: "firstName"
350
- }
351
- }
352
- }
353
- },
354
- data
355
- });
356
- expect(
357
- cache.read({
358
- parent: "User:1",
359
- selection: {
360
- __typename: {
361
- type: "String",
362
- keyRaw: "__typename"
363
- },
364
- id: {
365
- type: "ID",
366
- keyRaw: "id"
367
- },
368
- firstName: {
369
- type: "String",
370
- keyRaw: "firstName"
371
- }
372
- }
373
- }).data
374
- ).toEqual({
375
- __typename: "User",
376
- id: "1",
377
- firstName: "bob"
378
- });
379
- });
380
- test("can pull enum from cached values", function() {
381
- const cache = new Cache(config);
382
- const selection = {
383
- node: {
384
- type: "Node",
385
- keyRaw: "node",
386
- fields: {
387
- enumValue: {
388
- type: "MyEnum",
389
- keyRaw: "enumValue"
390
- },
391
- id: {
392
- type: "ID",
393
- keyRaw: "id"
394
- }
395
- }
396
- }
397
- };
398
- const data = {
399
- node: {
400
- id: "1",
401
- enumValue: "Hello"
402
- }
403
- };
404
- cache.write({ selection, data });
405
- expect(cache.read({ selection }).data).toEqual({
406
- node: {
407
- id: "1",
408
- enumValue: "Hello"
409
- }
410
- });
411
- });
412
- test("can store and retrieve lists with null values", function() {
413
- const cache = new Cache(config);
414
- const selection = {
415
- viewer: {
416
- type: "User",
417
- keyRaw: "viewer",
418
- fields: {
419
- id: {
420
- type: "ID",
421
- keyRaw: "id"
422
- },
423
- firstName: {
424
- type: "String",
425
- keyRaw: "firstName"
426
- },
427
- friends: {
428
- type: "User",
429
- keyRaw: "friends",
430
- fields: {
431
- id: {
432
- type: "ID",
433
- keyRaw: "id"
434
- },
435
- firstName: {
436
- type: "String",
437
- keyRaw: "firstName"
438
- }
439
- }
440
- }
441
- }
442
- }
443
- };
444
- cache.write({
445
- selection,
446
- data: {
447
- viewer: {
448
- id: "1",
449
- firstName: "bob",
450
- friends: [
451
- {
452
- id: "2",
453
- firstName: "jane"
454
- },
455
- null
456
- ]
457
- }
458
- }
459
- });
460
- expect(cache.read({ selection }).data).toEqual({
461
- viewer: {
462
- id: "1",
463
- firstName: "bob",
464
- friends: [
465
- {
466
- id: "2",
467
- firstName: "jane"
468
- },
469
- null
470
- ]
471
- }
472
- });
473
- });
474
- test("can store and retrieve lists of lists of records", function() {
475
- const cache = new Cache(config);
476
- const selection = {
477
- viewer: {
478
- type: "User",
479
- keyRaw: "viewer",
480
- fields: {
481
- id: {
482
- type: "ID",
483
- keyRaw: "id"
484
- },
485
- firstName: {
486
- type: "String",
487
- keyRaw: "firstName"
488
- },
489
- friends: {
490
- type: "User",
491
- keyRaw: "friends",
492
- fields: {
493
- id: {
494
- type: "ID",
495
- keyRaw: "id"
496
- },
497
- firstName: {
498
- type: "String",
499
- keyRaw: "firstName"
500
- }
501
- }
502
- }
503
- }
504
- }
505
- };
506
- cache.write({
507
- selection,
508
- data: {
509
- viewer: {
510
- id: "1",
511
- firstName: "bob",
512
- friends: [
513
- [
514
- {
515
- id: "2",
516
- firstName: "jane"
517
- },
518
- null
519
- ],
520
- [
521
- {
522
- id: "3",
523
- firstName: "jane"
524
- },
525
- {
526
- id: "4",
527
- firstName: "jane"
528
- }
529
- ]
530
- ]
531
- }
532
- }
533
- });
534
- expect(cache.read({ selection }).data).toEqual({
535
- viewer: {
536
- id: "1",
537
- firstName: "bob",
538
- friends: [
539
- [
540
- {
541
- id: "2",
542
- firstName: "jane"
543
- },
544
- null
545
- ],
546
- [
547
- {
548
- id: "3",
549
- firstName: "jane"
550
- },
551
- {
552
- id: "4",
553
- firstName: "jane"
554
- }
555
- ]
556
- ]
557
- }
558
- });
559
- });
560
- test("can store and retrieve links with null values", function() {
561
- const cache = new Cache(config);
562
- const selection = {
563
- viewer: {
564
- type: "User",
565
- keyRaw: "viewer",
566
- nullable: true,
567
- fields: {
568
- id: {
569
- type: "ID",
570
- keyRaw: "id"
571
- },
572
- firstName: {
573
- type: "String",
574
- keyRaw: "firstName"
575
- },
576
- friends: {
577
- type: "User",
578
- keyRaw: "friends",
579
- fields: {
580
- id: {
581
- type: "ID",
582
- keyRaw: "id"
583
- },
584
- firstName: {
585
- type: "String",
586
- keyRaw: "firstName"
587
- }
588
- }
589
- }
590
- }
591
- }
592
- };
593
- cache.write({
594
- selection,
595
- data: {
596
- viewer: null
597
- }
598
- });
599
- expect(cache.read({ selection }).data).toEqual({
600
- viewer: null
601
- });
602
- });
603
- test("can write list of just null", function() {
604
- const cache = new Cache(config);
605
- const selection = {
606
- viewer: {
607
- type: "User",
608
- keyRaw: "viewer",
609
- fields: {
610
- id: {
611
- type: "ID",
612
- keyRaw: "id"
613
- },
614
- firstName: {
615
- type: "String",
616
- keyRaw: "firstName"
617
- },
618
- friends: {
619
- type: "User",
620
- keyRaw: "friends",
621
- fields: {
622
- id: {
623
- type: "ID",
624
- keyRaw: "id"
625
- },
626
- firstName: {
627
- type: "String",
628
- keyRaw: "firstName"
629
- }
630
- }
631
- }
632
- }
633
- }
634
- };
635
- cache.write({
636
- selection,
637
- data: {
638
- viewer: {
639
- id: "1",
640
- firstName: "bob",
641
- friends: [null]
642
- }
643
- }
644
- });
645
- expect(cache.read({ selection }).data).toEqual({
646
- viewer: {
647
- id: "1",
648
- firstName: "bob",
649
- friends: [null]
650
- }
651
- });
652
- });
653
- test("null-value cascade from field value", function() {
654
- const cache = new Cache(config);
655
- cache.write({
656
- selection: {
657
- viewer: {
658
- type: "User",
659
- keyRaw: "viewer",
660
- fields: {
661
- id: {
662
- keyRaw: "id",
663
- type: "String"
664
- }
665
- }
666
- }
667
- },
668
- data: {
669
- viewer: {
670
- id: "1"
671
- }
672
- }
673
- });
674
- expect(
675
- cache.read({
676
- selection: {
677
- viewer: {
678
- type: "User",
679
- keyRaw: "viewer",
680
- nullable: true,
681
- fields: {
682
- id: {
683
- keyRaw: "id",
684
- type: "String"
685
- }
686
- }
687
- }
688
- }
689
- }).data
690
- ).toEqual({
691
- viewer: {
692
- id: "1"
693
- }
694
- });
695
- expect(
696
- cache.read({
697
- selection: {
698
- viewer: {
699
- type: "User",
700
- keyRaw: "viewer",
701
- nullable: true,
702
- fields: {
703
- firstName: {
704
- keyRaw: "firstName",
705
- type: "String"
706
- },
707
- id: {
708
- keyRaw: "id",
709
- type: "String"
710
- }
711
- }
712
- }
713
- }
714
- }).data
715
- ).toEqual({
716
- viewer: null
717
- });
718
- });
719
- test("null-value field", function() {
720
- const cache = new Cache(config);
721
- cache.write({
722
- selection: {
723
- viewer: {
724
- type: "User",
725
- keyRaw: "viewer",
726
- fields: {
727
- id: {
728
- keyRaw: "id",
729
- type: "String"
730
- },
731
- firstName: {
732
- keyRaw: "firstName",
733
- type: "String"
734
- }
735
- }
736
- }
737
- },
738
- data: {
739
- viewer: {
740
- id: "1",
741
- firstName: null
742
- }
743
- }
744
- });
745
- expect(
746
- cache.read({
747
- selection: {
748
- viewer: {
749
- type: "User",
750
- keyRaw: "viewer",
751
- nullable: true,
752
- fields: {
753
- id: {
754
- keyRaw: "id",
755
- type: "String"
756
- }
757
- }
758
- }
759
- }
760
- }).data
761
- ).toEqual({
762
- viewer: {
763
- id: "1"
764
- }
765
- });
766
- expect(
767
- cache.read({
768
- selection: {
769
- viewer: {
770
- type: "User",
771
- keyRaw: "viewer",
772
- nullable: true,
773
- fields: {
774
- firstName: {
775
- keyRaw: "firstName",
776
- type: "String",
777
- nullable: true
778
- }
779
- }
780
- }
781
- }
782
- }).data
783
- ).toEqual({
784
- viewer: {
785
- firstName: null
786
- }
787
- });
788
- });
789
- test("null-value cascade from object value", function() {
790
- const cache = new Cache(config);
791
- cache.write({
792
- selection: {
793
- viewer: {
794
- type: "User",
795
- keyRaw: "viewer",
796
- fields: {
797
- id: {
798
- keyRaw: "id",
799
- type: "String"
800
- }
801
- }
802
- }
803
- },
804
- data: {
805
- viewer: {
806
- id: "1"
807
- }
808
- }
809
- });
810
- expect(
811
- cache.read({
812
- selection: {
813
- viewer: {
814
- type: "User",
815
- keyRaw: "viewer",
816
- nullable: true,
817
- fields: {
818
- id: {
819
- keyRaw: "id",
820
- type: "String"
821
- },
822
- parent: {
823
- keyRaw: "parent",
824
- type: "User"
825
- }
826
- }
827
- }
828
- }
829
- })
830
- ).toEqual({
831
- partial: true,
832
- data: {
833
- viewer: null
834
- }
835
- });
836
- expect(
837
- cache.read({
838
- selection: {
839
- viewer: {
840
- type: "User",
841
- keyRaw: "viewer",
842
- nullable: true,
843
- fields: {
844
- id: {
845
- keyRaw: "id",
846
- type: "String"
847
- },
848
- parent: {
849
- keyRaw: "parent",
850
- type: "User",
851
- nullable: true
852
- }
853
- }
854
- }
855
- }
856
- })
857
- ).toEqual({
858
- partial: true,
859
- data: {
860
- viewer: {
861
- id: "1",
862
- parent: null
863
- }
864
- }
865
- });
866
- });
867
- test("null-value cascade to root", function() {
868
- const cache = new Cache(config);
869
- cache.write({
870
- selection: {
871
- viewer: {
872
- type: "User",
873
- keyRaw: "viewer",
874
- fields: {
875
- id: {
876
- keyRaw: "id",
877
- type: "String"
878
- }
879
- }
880
- }
881
- },
882
- data: {
883
- viewer: {
884
- id: "1"
885
- }
886
- }
887
- });
888
- expect(
889
- cache.read({
890
- selection: {
891
- viewer: {
892
- type: "User",
893
- keyRaw: "viewer",
894
- fields: {
895
- id: {
896
- keyRaw: "id",
897
- type: "String"
898
- },
899
- parent: {
900
- keyRaw: "parent",
901
- type: "User"
902
- }
903
- }
904
- }
905
- }
906
- })
907
- ).toEqual({
908
- data: null,
909
- partial: true
910
- });
911
- expect(
912
- cache.read({
913
- selection: {
914
- viewer: {
915
- type: "User",
916
- keyRaw: "viewer",
917
- nullable: true,
918
- fields: {
919
- parent: {
920
- keyRaw: "parent",
921
- type: "User"
922
- },
923
- id: {
924
- keyRaw: "id",
925
- type: "String"
926
- }
927
- }
928
- }
929
- }
930
- }).data
931
- ).toEqual({
932
- viewer: null
933
- });
934
- });
935
- test("must have a single value in order to use partial data", function() {
936
- const cache = new Cache(config);
937
- cache.write({
938
- selection: {
939
- viewer: {
940
- type: "User",
941
- keyRaw: "viewer",
942
- nullable: true,
943
- fields: {
944
- id: {
945
- keyRaw: "id",
946
- type: "String"
947
- }
948
- }
949
- }
950
- },
951
- data: {
952
- viewer: {
953
- id: "1"
954
- }
955
- }
956
- });
957
- expect(
958
- cache.read({
959
- selection: {
960
- viewer: {
961
- type: "User",
962
- keyRaw: "viewer",
963
- nullable: true,
964
- fields: {
965
- parent: {
966
- keyRaw: "parent",
967
- type: "User"
968
- }
969
- }
970
- }
971
- }
972
- })
973
- ).toEqual({
974
- partial: false,
975
- data: null
976
- });
977
- expect(
978
- cache.read({
979
- selection: {
980
- viewer: {
981
- type: "User",
982
- keyRaw: "viewer",
983
- nullable: true,
984
- fields: {
985
- id: {
986
- keyRaw: "id",
987
- type: "String"
988
- },
989
- parent: {
990
- keyRaw: "parent",
991
- type: "User"
992
- }
993
- }
994
- }
995
- }
996
- })
997
- ).toEqual({
998
- partial: true,
999
- data: {
1000
- viewer: null
1001
- }
1002
- });
1003
- });
1004
- test("reading an empty list counts as data", function() {
1005
- const cache = new Cache(config);
1006
- cache.write({
1007
- selection: {
1008
- viewer: {
1009
- type: "User",
1010
- keyRaw: "viewer",
1011
- nullable: true,
1012
- fields: {
1013
- id: {
1014
- keyRaw: "id",
1015
- type: "String"
1016
- },
1017
- friends: {
1018
- type: "User",
1019
- keyRaw: "friends",
1020
- fields: {
1021
- id: {
1022
- type: "ID",
1023
- keyRaw: "id"
1024
- },
1025
- firstName: {
1026
- type: "String",
1027
- keyRaw: "firstName"
1028
- }
1029
- }
1030
- }
1031
- }
1032
- }
1033
- },
1034
- data: {
1035
- viewer: {
1036
- id: "1",
1037
- friends: []
1038
- }
1039
- }
1040
- });
1041
- expect(
1042
- cache.read({
1043
- selection: {
1044
- viewer: {
1045
- type: "User",
1046
- keyRaw: "viewer",
1047
- nullable: true,
1048
- fields: {
1049
- friends: {
1050
- type: "User",
1051
- keyRaw: "friends",
1052
- fields: {
1053
- id: {
1054
- type: "ID",
1055
- keyRaw: "id"
1056
- },
1057
- firstName: {
1058
- type: "String",
1059
- keyRaw: "firstName"
1060
- }
1061
- }
1062
- }
1063
- }
1064
- }
1065
- }
1066
- })
1067
- ).toEqual({
1068
- partial: false,
1069
- data: {
1070
- viewer: {
1071
- friends: []
1072
- }
1073
- }
1074
- });
1075
- });