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,1469 +0,0 @@
1
- "use strict";
2
- var import_vitest = require("vitest");
3
- var import_test = require("../../../test");
4
- var import_lib = require("../../lib");
5
- var import_cache = require("../cache");
6
- const config = (0, import_test.testConfigFile)();
7
- (0, import_vitest.test)("root subscribe - field change", function() {
8
- const cache = new import_cache.Cache(config);
9
- const selection = {
10
- viewer: {
11
- type: "User",
12
- keyRaw: "viewer",
13
- fields: {
14
- id: {
15
- type: "ID",
16
- keyRaw: "id"
17
- },
18
- firstName: {
19
- type: "String",
20
- keyRaw: "firstName"
21
- },
22
- favoriteColors: {
23
- type: "String",
24
- keyRaw: "favoriteColors"
25
- }
26
- }
27
- }
28
- };
29
- cache.write({
30
- selection,
31
- data: {
32
- viewer: {
33
- id: "1",
34
- firstName: "bob",
35
- favoriteColors: ["red", "green", "blue"]
36
- }
37
- }
38
- });
39
- const set = import_vitest.vi.fn();
40
- cache.subscribe({
41
- rootType: "Query",
42
- selection,
43
- set
44
- });
45
- cache.write({
46
- selection,
47
- data: {
48
- viewer: {
49
- id: "1",
50
- firstName: "mary"
51
- }
52
- }
53
- });
54
- (0, import_vitest.expect)(set).toHaveBeenCalledWith({
55
- viewer: {
56
- firstName: "mary",
57
- favoriteColors: ["red", "green", "blue"],
58
- id: "1"
59
- }
60
- });
61
- });
62
- (0, import_vitest.test)("root subscribe - linked object changed", function() {
63
- const cache = new import_cache.Cache(config);
64
- const selection = {
65
- viewer: {
66
- type: "User",
67
- keyRaw: "viewer",
68
- fields: {
69
- id: {
70
- type: "ID",
71
- keyRaw: "id"
72
- },
73
- firstName: {
74
- type: "String",
75
- keyRaw: "firstName"
76
- },
77
- favoriteColors: {
78
- type: "String",
79
- keyRaw: 'favoriteColors(where: "foo")',
80
- nullable: true
81
- }
82
- }
83
- }
84
- };
85
- cache.write({
86
- selection,
87
- data: {
88
- viewer: {
89
- id: "1",
90
- firstName: "bob",
91
- favoriteColors: ["red", "green", "blue"]
92
- }
93
- }
94
- });
95
- const set = import_vitest.vi.fn();
96
- cache.subscribe({
97
- rootType: "Query",
98
- selection,
99
- set
100
- });
101
- cache.write({
102
- selection,
103
- data: {
104
- viewer: {
105
- id: "2",
106
- firstName: "mary"
107
- }
108
- }
109
- });
110
- (0, import_vitest.expect)(set).toHaveBeenCalledWith({
111
- viewer: {
112
- firstName: "mary",
113
- favoriteColors: null,
114
- id: "2"
115
- }
116
- });
117
- cache.write({
118
- selection: {
119
- firstName: {
120
- type: "String",
121
- keyRaw: "firstName"
122
- }
123
- },
124
- data: {
125
- firstName: "Michelle"
126
- },
127
- parent: "User:2"
128
- });
129
- (0, import_vitest.expect)(set).toHaveBeenCalledTimes(2);
130
- (0, import_vitest.expect)(set).toHaveBeenLastCalledWith({
131
- viewer: {
132
- firstName: "Michelle",
133
- id: "2",
134
- favoriteColors: null
135
- }
136
- });
137
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:1", "firstName")).toHaveLength(0);
138
- });
139
- (0, import_vitest.test)("subscribing to null object doesn't explode", function() {
140
- const cache = new import_cache.Cache(config);
141
- const selection = {
142
- viewer: {
143
- type: "User",
144
- keyRaw: "viewer",
145
- fields: {
146
- id: {
147
- type: "ID",
148
- keyRaw: "id"
149
- },
150
- firstName: {
151
- type: "String",
152
- keyRaw: "firstName"
153
- },
154
- favoriteColors: {
155
- nullable: true,
156
- type: "String",
157
- keyRaw: 'favoriteColors(where: "foo")'
158
- }
159
- }
160
- }
161
- };
162
- cache.write({
163
- selection,
164
- data: {
165
- viewer: null
166
- }
167
- });
168
- const set = import_vitest.vi.fn();
169
- cache.subscribe({
170
- rootType: "Query",
171
- selection,
172
- set
173
- });
174
- cache.write({
175
- selection,
176
- data: {
177
- viewer: {
178
- id: "2",
179
- firstName: "mary"
180
- }
181
- }
182
- });
183
- (0, import_vitest.expect)(set).toHaveBeenCalledWith({
184
- viewer: {
185
- firstName: "mary",
186
- favoriteColors: null,
187
- id: "2"
188
- }
189
- });
190
- });
191
- (0, import_vitest.test)("overwriting a reference with null clears its subscribers", function() {
192
- const cache = new import_cache.Cache(config);
193
- const selection = {
194
- viewer: {
195
- type: "User",
196
- keyRaw: "viewer",
197
- nullable: true,
198
- fields: {
199
- id: {
200
- type: "ID",
201
- keyRaw: "id"
202
- },
203
- firstName: {
204
- type: "String",
205
- keyRaw: "firstName"
206
- },
207
- favoriteColors: {
208
- type: "String",
209
- keyRaw: 'favoriteColors(where: "foo")'
210
- }
211
- }
212
- }
213
- };
214
- cache.write({
215
- selection,
216
- data: {
217
- viewer: {
218
- id: "2",
219
- firstName: "mary"
220
- }
221
- }
222
- });
223
- const set = import_vitest.vi.fn();
224
- cache.subscribe({
225
- rootType: "Query",
226
- selection,
227
- set
228
- });
229
- cache.write({
230
- selection,
231
- data: {
232
- viewer: null
233
- }
234
- });
235
- (0, import_vitest.expect)(set).toHaveBeenCalledWith({
236
- viewer: null
237
- });
238
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:2", "firstName")).toHaveLength(0);
239
- });
240
- (0, import_vitest.test)("overwriting a linked list with null clears its subscribers", function() {
241
- const cache = new import_cache.Cache(config);
242
- const selection = {
243
- viewer: {
244
- type: "User",
245
- keyRaw: "viewer",
246
- fields: {
247
- id: {
248
- type: "ID",
249
- keyRaw: "id"
250
- },
251
- friends: {
252
- type: "User",
253
- keyRaw: "friends",
254
- nullable: true,
255
- fields: {
256
- firstName: {
257
- type: "String",
258
- keyRaw: "firstName"
259
- },
260
- id: {
261
- type: "ID",
262
- keyRaw: "id"
263
- }
264
- }
265
- }
266
- }
267
- }
268
- };
269
- const set = import_vitest.vi.fn();
270
- cache.subscribe({
271
- rootType: "Query",
272
- selection,
273
- set
274
- });
275
- cache.write({
276
- selection,
277
- data: {
278
- viewer: {
279
- id: "1",
280
- friends: [
281
- { id: "2", firstName: "Jason" },
282
- { id: "3", firstName: "Nick" }
283
- ]
284
- }
285
- }
286
- });
287
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:1", "friends")).toHaveLength(1);
288
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:2", "firstName")).toHaveLength(1);
289
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:3", "firstName")).toHaveLength(1);
290
- cache.write({
291
- selection: {
292
- id: {
293
- type: "String",
294
- keyRaw: "id"
295
- },
296
- friends: selection.viewer.fields.friends
297
- },
298
- data: {
299
- id: "1",
300
- friends: null
301
- },
302
- parent: "User:1"
303
- });
304
- (0, import_vitest.expect)(set).toHaveBeenNthCalledWith(2, {
305
- viewer: {
306
- id: "1",
307
- friends: null
308
- }
309
- });
310
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:2", "firstName")).toHaveLength(0);
311
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:3", "firstName")).toHaveLength(0);
312
- });
313
- (0, import_vitest.test)("root subscribe - linked list lost entry", function() {
314
- const cache = new import_cache.Cache(config);
315
- const selection = {
316
- viewer: {
317
- type: "User",
318
- keyRaw: "viewer",
319
- fields: {
320
- id: {
321
- type: "ID",
322
- keyRaw: "id"
323
- },
324
- friends: {
325
- type: "User",
326
- keyRaw: "friends",
327
- fields: {
328
- id: {
329
- type: "ID",
330
- keyRaw: "id"
331
- },
332
- firstName: {
333
- type: "String",
334
- keyRaw: "firstName"
335
- }
336
- }
337
- }
338
- }
339
- }
340
- };
341
- cache.write({
342
- selection,
343
- data: {
344
- viewer: {
345
- id: "1",
346
- friends: [
347
- {
348
- id: "2",
349
- firstName: "jane"
350
- },
351
- {
352
- id: "3",
353
- firstName: "mary"
354
- }
355
- ]
356
- }
357
- }
358
- });
359
- const set = import_vitest.vi.fn();
360
- cache.subscribe({
361
- rootType: "Query",
362
- selection,
363
- set
364
- });
365
- cache.write({
366
- selection,
367
- data: {
368
- viewer: {
369
- id: "1",
370
- friends: [
371
- {
372
- id: "2"
373
- }
374
- ]
375
- }
376
- }
377
- });
378
- (0, import_vitest.expect)(set).toHaveBeenCalledWith({
379
- viewer: {
380
- id: "1",
381
- friends: [
382
- {
383
- firstName: "jane",
384
- id: "2"
385
- }
386
- ]
387
- }
388
- });
389
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:3", "firstName")).toHaveLength(0);
390
- });
391
- (0, import_vitest.test)("subscribing to list with null values doesn't explode", function() {
392
- const cache = new import_cache.Cache(config);
393
- const selection = {
394
- viewer: {
395
- type: "User",
396
- keyRaw: "viewer",
397
- fields: {
398
- id: {
399
- type: "ID",
400
- keyRaw: "id"
401
- },
402
- friends: {
403
- type: "User",
404
- keyRaw: "friends",
405
- fields: {
406
- id: {
407
- type: "ID",
408
- keyRaw: "id"
409
- },
410
- firstName: {
411
- type: "String",
412
- keyRaw: "firstName"
413
- }
414
- }
415
- }
416
- }
417
- }
418
- };
419
- cache.write({
420
- selection,
421
- data: {
422
- viewer: {
423
- id: "1",
424
- friends: [
425
- {
426
- id: "2",
427
- firstName: "jane"
428
- },
429
- null
430
- ]
431
- }
432
- }
433
- });
434
- const set = import_vitest.vi.fn();
435
- cache.subscribe({
436
- rootType: "Query",
437
- selection,
438
- set
439
- });
440
- cache.write({
441
- selection,
442
- data: {
443
- viewer: {
444
- id: "1",
445
- friends: [
446
- {
447
- id: "2"
448
- }
449
- ]
450
- }
451
- }
452
- });
453
- (0, import_vitest.expect)(set).toHaveBeenCalledWith({
454
- viewer: {
455
- id: "1",
456
- friends: [
457
- {
458
- firstName: "jane",
459
- id: "2"
460
- }
461
- ]
462
- }
463
- });
464
- });
465
- (0, import_vitest.test)("root subscribe - linked list reorder", function() {
466
- const cache = new import_cache.Cache(config);
467
- const selection = {
468
- viewer: {
469
- type: "User",
470
- keyRaw: "viewer",
471
- fields: {
472
- id: {
473
- type: "ID",
474
- keyRaw: "id"
475
- },
476
- friends: {
477
- type: "User",
478
- keyRaw: "friends",
479
- fields: {
480
- id: {
481
- type: "ID",
482
- keyRaw: "id"
483
- },
484
- firstName: {
485
- type: "String",
486
- keyRaw: "firstName"
487
- }
488
- }
489
- }
490
- }
491
- }
492
- };
493
- cache.write({
494
- selection,
495
- data: {
496
- viewer: {
497
- id: "1",
498
- friends: [
499
- {
500
- id: "2",
501
- firstName: "jane"
502
- },
503
- {
504
- id: "3",
505
- firstName: "mary"
506
- }
507
- ]
508
- }
509
- }
510
- });
511
- const set = import_vitest.vi.fn();
512
- cache.subscribe({
513
- rootType: "Query",
514
- set,
515
- selection
516
- });
517
- cache.write({
518
- selection,
519
- data: {
520
- viewer: {
521
- id: "1",
522
- friends: [
523
- {
524
- id: "3"
525
- },
526
- {
527
- id: "2"
528
- }
529
- ]
530
- }
531
- }
532
- });
533
- (0, import_vitest.expect)(set).toHaveBeenCalledWith({
534
- viewer: {
535
- id: "1",
536
- friends: [
537
- {
538
- id: "3",
539
- firstName: "mary"
540
- },
541
- {
542
- id: "2",
543
- firstName: "jane"
544
- }
545
- ]
546
- }
547
- });
548
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:2", "firstName")).toHaveLength(1);
549
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:3", "firstName")).toHaveLength(1);
550
- });
551
- (0, import_vitest.test)("unsubscribe", function() {
552
- const cache = new import_cache.Cache(config);
553
- const selection = {
554
- viewer: {
555
- type: "User",
556
- keyRaw: "viewer",
557
- fields: {
558
- id: {
559
- type: "ID",
560
- keyRaw: "id"
561
- },
562
- firstName: {
563
- type: "String",
564
- keyRaw: "firstName"
565
- },
566
- favoriteColors: {
567
- type: "String",
568
- keyRaw: 'favoriteColors(where: "foo")'
569
- }
570
- }
571
- }
572
- };
573
- cache.write({
574
- selection,
575
- data: {
576
- viewer: {
577
- id: "1",
578
- firstName: "bob",
579
- favoriteColors: ["red", "green", "blue"]
580
- }
581
- }
582
- });
583
- const spec = {
584
- rootType: "Query",
585
- selection,
586
- set: import_vitest.vi.fn()
587
- };
588
- cache.subscribe(spec);
589
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:1", "firstName")).toHaveLength(1);
590
- cache.unsubscribe(spec);
591
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:1", "firstName")).toHaveLength(0);
592
- });
593
- (0, import_vitest.test)("subscribe to new list nodes", function() {
594
- const cache = new import_cache.Cache(config);
595
- const selection = {
596
- viewer: {
597
- type: "User",
598
- keyRaw: "viewer",
599
- fields: {
600
- id: {
601
- type: "ID",
602
- keyRaw: "id"
603
- },
604
- friends: {
605
- type: "User",
606
- keyRaw: "friends",
607
- list: {
608
- name: "All_Users",
609
- connection: false,
610
- type: "User"
611
- },
612
- fields: {
613
- id: {
614
- type: "ID",
615
- keyRaw: "id"
616
- },
617
- firstName: {
618
- type: "String",
619
- keyRaw: "firstName"
620
- }
621
- }
622
- }
623
- }
624
- }
625
- };
626
- const set = import_vitest.vi.fn();
627
- cache.subscribe({
628
- rootType: "Query",
629
- set,
630
- selection
631
- });
632
- cache.write({
633
- selection,
634
- data: {
635
- viewer: {
636
- id: "1",
637
- friends: [
638
- {
639
- id: "2",
640
- firstName: "jane"
641
- }
642
- ]
643
- }
644
- }
645
- });
646
- cache.write({
647
- selection: {
648
- id: {
649
- type: "String",
650
- keyRaw: "id"
651
- },
652
- firstName: {
653
- type: "String",
654
- keyRaw: "firstName"
655
- }
656
- },
657
- data: {
658
- id: "2",
659
- firstName: "jane-prime"
660
- },
661
- parent: "User:2"
662
- });
663
- (0, import_vitest.expect)(set).toHaveBeenNthCalledWith(2, {
664
- viewer: {
665
- id: "1",
666
- friends: [
667
- {
668
- firstName: "jane-prime",
669
- id: "2"
670
- }
671
- ]
672
- }
673
- });
674
- cache.write({
675
- selection,
676
- data: {
677
- viewer: {
678
- id: "1",
679
- friends: [
680
- {
681
- id: "2",
682
- firstName: "jane-prime"
683
- },
684
- {
685
- id: "3",
686
- firstName: "mary"
687
- }
688
- ]
689
- }
690
- }
691
- });
692
- cache.write({
693
- selection: {
694
- id: {
695
- type: "String",
696
- keyRaw: "id"
697
- },
698
- firstName: {
699
- type: "String",
700
- keyRaw: "firstName"
701
- }
702
- },
703
- data: {
704
- id: "3",
705
- firstName: "mary-prime"
706
- },
707
- parent: "User:3"
708
- });
709
- (0, import_vitest.expect)(set).toHaveBeenNthCalledWith(4, {
710
- viewer: {
711
- id: "1",
712
- friends: [
713
- {
714
- firstName: "jane-prime",
715
- id: "2"
716
- },
717
- {
718
- firstName: "mary-prime",
719
- id: "3"
720
- }
721
- ]
722
- }
723
- });
724
- });
725
- (0, import_vitest.test)("variables in query and subscription", function() {
726
- const cache = new import_cache.Cache(config);
727
- const selection = {
728
- viewer: {
729
- type: "User",
730
- keyRaw: "viewer",
731
- fields: {
732
- id: {
733
- type: "ID",
734
- keyRaw: "id"
735
- },
736
- friends: {
737
- type: "User",
738
- keyRaw: "friends(filter: $filter)",
739
- list: {
740
- name: "All_Users",
741
- connection: false,
742
- type: "User"
743
- },
744
- fields: {
745
- id: {
746
- type: "ID",
747
- keyRaw: "id"
748
- },
749
- firstName: {
750
- type: "String",
751
- keyRaw: "firstName"
752
- }
753
- }
754
- }
755
- }
756
- }
757
- };
758
- cache.write({
759
- selection,
760
- data: {
761
- viewer: {
762
- id: "1",
763
- friends: [
764
- {
765
- id: "2",
766
- firstName: "jane"
767
- },
768
- {
769
- id: "3",
770
- firstName: "mary"
771
- }
772
- ]
773
- }
774
- },
775
- variables: {
776
- filter: "foo"
777
- }
778
- });
779
- const set = import_vitest.vi.fn();
780
- cache.subscribe(
781
- {
782
- rootType: "Query",
783
- selection,
784
- set,
785
- variables: () => ({ filter: "foo" })
786
- },
787
- {
788
- filter: "foo"
789
- }
790
- );
791
- (0, import_vitest.expect)(cache.list("All_Users").lists[0].key).toEqual('friends(filter: "foo")');
792
- cache.write({
793
- selection,
794
- data: {
795
- viewer: {
796
- id: "1",
797
- friends: [
798
- {
799
- id: "2"
800
- }
801
- ]
802
- }
803
- },
804
- variables: {
805
- filter: "foo"
806
- }
807
- });
808
- (0, import_vitest.expect)(set).toHaveBeenCalledWith({
809
- viewer: {
810
- id: "1",
811
- friends: [
812
- {
813
- firstName: "jane",
814
- id: "2"
815
- }
816
- ]
817
- }
818
- });
819
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:3", "firstName")).toHaveLength(0);
820
- });
821
- (0, import_vitest.test)("deleting a node removes nested subscriptions", function() {
822
- const cache = new import_cache.Cache(config);
823
- const selection = {
824
- viewer: {
825
- type: "User",
826
- keyRaw: "viewer",
827
- fields: {
828
- id: {
829
- type: "ID",
830
- keyRaw: "id"
831
- },
832
- friends: {
833
- type: "User",
834
- keyRaw: "friends",
835
- list: {
836
- name: "All_Users",
837
- connection: false,
838
- type: "User"
839
- },
840
- fields: {
841
- id: {
842
- type: "ID",
843
- keyRaw: "id"
844
- },
845
- firstName: {
846
- type: "String",
847
- keyRaw: "firstName"
848
- }
849
- }
850
- }
851
- }
852
- }
853
- };
854
- cache.write({
855
- selection,
856
- data: {
857
- viewer: {
858
- id: "1",
859
- friends: [
860
- {
861
- id: "2",
862
- firstName: "jane"
863
- }
864
- ]
865
- }
866
- }
867
- });
868
- const set = import_vitest.vi.fn();
869
- cache.subscribe({
870
- rootType: "Query",
871
- selection,
872
- set
873
- });
874
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:2", "firstName")).toHaveLength(1);
875
- cache.delete("User:1");
876
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:2", "firstName")).toHaveLength(0);
877
- });
878
- (0, import_vitest.test)("same record twice in a query survives one unsubscribe (reference counting)", function() {
879
- const cache = new import_cache.Cache(config);
880
- const selection = {
881
- viewer: {
882
- type: "User",
883
- keyRaw: "viewer",
884
- fields: {
885
- id: {
886
- type: "ID",
887
- keyRaw: "id"
888
- },
889
- firstName: {
890
- type: "String",
891
- keyRaw: "firstName"
892
- },
893
- friends: {
894
- type: "User",
895
- keyRaw: "friends",
896
- list: {
897
- name: "All_Users",
898
- connection: false,
899
- type: "User"
900
- },
901
- fields: {
902
- id: {
903
- type: "ID",
904
- keyRaw: "id"
905
- },
906
- firstName: {
907
- type: "String",
908
- keyRaw: "firstName"
909
- }
910
- }
911
- }
912
- }
913
- }
914
- };
915
- cache.write({
916
- selection,
917
- data: {
918
- viewer: {
919
- id: "1",
920
- firstName: "bob",
921
- friends: [
922
- {
923
- id: "1",
924
- firstName: "bob"
925
- }
926
- ]
927
- }
928
- },
929
- variables: {
930
- filter: "foo"
931
- }
932
- });
933
- const set = import_vitest.vi.fn();
934
- cache.subscribe(
935
- {
936
- rootType: "Query",
937
- selection,
938
- set
939
- },
940
- {
941
- filter: "foo"
942
- }
943
- );
944
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:1", "firstName")).toHaveLength(1);
945
- cache.list("All_Users").remove({ id: "1" });
946
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:1", "firstName")).toHaveLength(1);
947
- });
948
- (0, import_vitest.test)("embedded references", function() {
949
- const cache = new import_cache.Cache(config);
950
- const selection = {
951
- viewer: {
952
- type: "User",
953
- keyRaw: "viewer",
954
- fields: {
955
- id: {
956
- type: "ID",
957
- keyRaw: "id"
958
- },
959
- friends: {
960
- type: "User",
961
- keyRaw: "friends",
962
- fields: {
963
- edges: {
964
- type: "UserEdge",
965
- keyRaw: "edges",
966
- fields: {
967
- node: {
968
- type: "User",
969
- keyRaw: "node",
970
- fields: {
971
- id: {
972
- type: "ID",
973
- keyRaw: "id"
974
- },
975
- firstName: {
976
- type: "String",
977
- keyRaw: "firstName"
978
- }
979
- }
980
- }
981
- }
982
- }
983
- }
984
- }
985
- }
986
- }
987
- };
988
- cache.write({
989
- selection,
990
- data: {
991
- viewer: {
992
- id: "1",
993
- friends: {
994
- edges: [
995
- {
996
- node: {
997
- id: "2",
998
- firstName: "jane"
999
- }
1000
- },
1001
- {
1002
- node: {
1003
- id: "3",
1004
- firstName: "mary"
1005
- }
1006
- }
1007
- ]
1008
- }
1009
- }
1010
- }
1011
- });
1012
- const set = import_vitest.vi.fn();
1013
- cache.subscribe(
1014
- {
1015
- rootType: "Query",
1016
- selection,
1017
- set
1018
- },
1019
- {
1020
- filter: "foo"
1021
- }
1022
- );
1023
- cache.write({
1024
- selection: {
1025
- user: {
1026
- type: "User",
1027
- keyRaw: "user",
1028
- fields: {
1029
- id: {
1030
- type: "ID",
1031
- keyRaw: "id"
1032
- },
1033
- firstName: {
1034
- type: "String",
1035
- keyRaw: "firstName"
1036
- }
1037
- }
1038
- }
1039
- },
1040
- data: {
1041
- user: {
1042
- id: "2",
1043
- firstName: "not-jane"
1044
- }
1045
- }
1046
- });
1047
- (0, import_vitest.expect)(set).toHaveBeenCalledWith({
1048
- viewer: {
1049
- id: "1",
1050
- friends: {
1051
- edges: [
1052
- {
1053
- node: {
1054
- id: "2",
1055
- firstName: "not-jane"
1056
- }
1057
- },
1058
- {
1059
- node: {
1060
- id: "3",
1061
- firstName: "mary"
1062
- }
1063
- }
1064
- ]
1065
- }
1066
- }
1067
- });
1068
- });
1069
- (0, import_vitest.test)("self-referencing linked lists can be unsubscribed (avoid infinite recursion)", function() {
1070
- const cache = new import_cache.Cache(config);
1071
- const selection = {
1072
- viewer: {
1073
- type: "User",
1074
- keyRaw: "viewer",
1075
- fields: {
1076
- id: {
1077
- type: "ID",
1078
- keyRaw: "id"
1079
- },
1080
- firstName: {
1081
- type: "String",
1082
- keyRaw: "firstName"
1083
- },
1084
- friends: {
1085
- type: "User",
1086
- keyRaw: "friends",
1087
- fields: {
1088
- id: {
1089
- type: "ID",
1090
- keyRaw: "id"
1091
- },
1092
- firstName: {
1093
- type: "String",
1094
- keyRaw: "firstName"
1095
- },
1096
- friends: {
1097
- type: "User",
1098
- keyRaw: "friends",
1099
- fields: {
1100
- id: {
1101
- type: "ID",
1102
- keyRaw: "id"
1103
- },
1104
- firstName: {
1105
- type: "String",
1106
- keyRaw: "firstName"
1107
- }
1108
- }
1109
- }
1110
- }
1111
- }
1112
- }
1113
- }
1114
- };
1115
- cache.write({
1116
- selection,
1117
- data: {
1118
- viewer: {
1119
- id: "1",
1120
- firstName: "bob",
1121
- friends: [
1122
- {
1123
- id: "1",
1124
- firstName: "bob",
1125
- friends: [
1126
- {
1127
- id: "1",
1128
- firstName: "bob"
1129
- }
1130
- ]
1131
- }
1132
- ]
1133
- }
1134
- }
1135
- });
1136
- const spec = {
1137
- set: import_vitest.vi.fn(),
1138
- selection,
1139
- rootType: "Query"
1140
- };
1141
- cache.subscribe(spec);
1142
- cache.unsubscribe(spec);
1143
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:1", "firstName")).toHaveLength(0);
1144
- });
1145
- (0, import_vitest.test)("self-referencing links can be unsubscribed (avoid infinite recursion)", function() {
1146
- const cache = new import_cache.Cache(config);
1147
- const selection = {
1148
- viewer: {
1149
- type: "User",
1150
- keyRaw: "viewer",
1151
- fields: {
1152
- id: {
1153
- type: "ID",
1154
- keyRaw: "id"
1155
- },
1156
- firstName: {
1157
- type: "String",
1158
- keyRaw: "firstName"
1159
- },
1160
- friend: {
1161
- type: "User",
1162
- keyRaw: "friend",
1163
- fields: {
1164
- id: {
1165
- type: "ID",
1166
- keyRaw: "id"
1167
- },
1168
- firstName: {
1169
- type: "String",
1170
- keyRaw: "firstName"
1171
- },
1172
- friend: {
1173
- type: "User",
1174
- keyRaw: "friend",
1175
- fields: {
1176
- id: {
1177
- type: "ID",
1178
- keyRaw: "id"
1179
- },
1180
- firstName: {
1181
- type: "String",
1182
- keyRaw: "firstName"
1183
- },
1184
- friend: {
1185
- type: "User",
1186
- keyRaw: "friend",
1187
- fields: {
1188
- id: {
1189
- type: "ID",
1190
- keyRaw: "id"
1191
- },
1192
- firstName: {
1193
- type: "String",
1194
- keyRaw: "firstName"
1195
- }
1196
- }
1197
- }
1198
- }
1199
- }
1200
- }
1201
- }
1202
- }
1203
- }
1204
- };
1205
- cache.write({
1206
- selection,
1207
- data: {
1208
- viewer: {
1209
- id: "1",
1210
- firstName: "bob",
1211
- friend: {
1212
- id: "1",
1213
- firstName: "bob",
1214
- friend: {
1215
- id: "1",
1216
- firstName: "bob",
1217
- friend: {
1218
- id: "1",
1219
- firstName: "bob"
1220
- }
1221
- }
1222
- }
1223
- }
1224
- }
1225
- });
1226
- const spec = {
1227
- set: import_vitest.vi.fn(),
1228
- selection,
1229
- rootType: "Query"
1230
- };
1231
- cache.subscribe(spec);
1232
- cache.unsubscribe(spec);
1233
- (0, import_vitest.expect)(cache._internal_unstable.subscriptions.get("User:1", "firstName")).toHaveLength(0);
1234
- });
1235
- (0, import_vitest.test)("overwriting a value in an optimistic layer triggers subscribers", function() {
1236
- const cache = new import_cache.Cache(config);
1237
- const selection = {
1238
- viewer: {
1239
- type: "User",
1240
- keyRaw: "viewer",
1241
- fields: {
1242
- id: {
1243
- type: "ID",
1244
- keyRaw: "id"
1245
- },
1246
- firstName: {
1247
- type: "String",
1248
- keyRaw: "firstName"
1249
- },
1250
- favoriteColors: {
1251
- type: "String",
1252
- keyRaw: "favoriteColors"
1253
- }
1254
- }
1255
- }
1256
- };
1257
- cache.write({
1258
- selection,
1259
- data: {
1260
- viewer: {
1261
- id: "1",
1262
- firstName: "bob",
1263
- favoriteColors: ["red", "green", "blue"]
1264
- }
1265
- }
1266
- });
1267
- const set = import_vitest.vi.fn();
1268
- cache.subscribe({
1269
- rootType: "Query",
1270
- selection,
1271
- set
1272
- });
1273
- const layer = cache._internal_unstable.storage.createLayer(true);
1274
- cache.write({
1275
- selection,
1276
- data: {
1277
- viewer: {
1278
- id: "1",
1279
- firstName: "mary"
1280
- }
1281
- },
1282
- layer: layer.id
1283
- });
1284
- (0, import_vitest.expect)(set).toHaveBeenCalledWith({
1285
- viewer: {
1286
- firstName: "mary",
1287
- favoriteColors: ["red", "green", "blue"],
1288
- id: "1"
1289
- }
1290
- });
1291
- });
1292
- (0, import_vitest.test)("clearing a display layer updates subscribers", function() {
1293
- const cache = new import_cache.Cache(config);
1294
- const selection = {
1295
- viewer: {
1296
- type: "User",
1297
- keyRaw: "viewer",
1298
- fields: {
1299
- id: {
1300
- type: "ID",
1301
- keyRaw: "id"
1302
- },
1303
- firstName: {
1304
- type: "String",
1305
- keyRaw: "firstName"
1306
- },
1307
- favoriteColors: {
1308
- type: "String",
1309
- keyRaw: "favoriteColors"
1310
- }
1311
- }
1312
- }
1313
- };
1314
- cache.write({
1315
- selection,
1316
- data: {
1317
- viewer: {
1318
- id: "1",
1319
- firstName: "bob",
1320
- favoriteColors: ["red", "green", "blue"]
1321
- }
1322
- }
1323
- });
1324
- const set = import_vitest.vi.fn();
1325
- cache.subscribe({
1326
- rootType: "Query",
1327
- selection,
1328
- set
1329
- });
1330
- const layer = cache._internal_unstable.storage.createLayer(true);
1331
- cache.write({
1332
- selection,
1333
- data: {
1334
- viewer: {
1335
- id: "1",
1336
- firstName: "mary"
1337
- }
1338
- },
1339
- layer: layer.id
1340
- });
1341
- (0, import_vitest.expect)(set).toHaveBeenCalledWith({
1342
- viewer: {
1343
- firstName: "mary",
1344
- favoriteColors: ["red", "green", "blue"],
1345
- id: "1"
1346
- }
1347
- });
1348
- layer.clear();
1349
- cache.write({
1350
- selection,
1351
- data: {
1352
- viewer: {
1353
- firstName: "mary",
1354
- favoriteColors: ["red", "green", "blue"],
1355
- id: "1"
1356
- }
1357
- },
1358
- layer: layer.id
1359
- });
1360
- (0, import_vitest.expect)(set).toHaveBeenNthCalledWith(2, {
1361
- viewer: {
1362
- firstName: "mary",
1363
- favoriteColors: ["red", "green", "blue"],
1364
- id: "1"
1365
- }
1366
- });
1367
- });
1368
- (0, import_vitest.test)("ensure parent type is properly passed for nested lists", function() {
1369
- const cache = new import_cache.Cache(config);
1370
- const selection = {
1371
- cities: {
1372
- type: "City",
1373
- keyRaw: "cities",
1374
- list: {
1375
- name: "City_List",
1376
- connection: false,
1377
- type: "City"
1378
- },
1379
- update: import_lib.RefetchUpdateMode.append,
1380
- fields: {
1381
- id: {
1382
- type: "ID",
1383
- keyRaw: "id"
1384
- },
1385
- name: {
1386
- type: "String",
1387
- keyRaw: "name"
1388
- },
1389
- libraries: {
1390
- type: "Library",
1391
- keyRaw: "libraries",
1392
- update: import_lib.RefetchUpdateMode.append,
1393
- list: {
1394
- name: "Library_List",
1395
- connection: false,
1396
- type: "Library"
1397
- },
1398
- fields: {
1399
- id: {
1400
- type: "ID",
1401
- keyRaw: "id"
1402
- },
1403
- name: {
1404
- type: "String",
1405
- keyRaw: "name"
1406
- },
1407
- books: {
1408
- type: "Book",
1409
- keyRaw: "books",
1410
- list: {
1411
- name: "Book_List",
1412
- connection: false,
1413
- type: "Book"
1414
- },
1415
- fields: {
1416
- id: {
1417
- type: "ID",
1418
- keyRaw: "id"
1419
- },
1420
- title: {
1421
- type: "String",
1422
- keyRaw: "title"
1423
- }
1424
- }
1425
- }
1426
- }
1427
- }
1428
- }
1429
- }
1430
- };
1431
- const set = import_vitest.vi.fn();
1432
- cache.subscribe({
1433
- rootType: "Query",
1434
- selection,
1435
- set
1436
- });
1437
- cache.write({
1438
- selection,
1439
- data: {
1440
- cities: [
1441
- {
1442
- id: "1",
1443
- name: "Alexandria",
1444
- libraries: [
1445
- {
1446
- id: "1",
1447
- name: "The Library of Alexandria",
1448
- books: []
1449
- },
1450
- {
1451
- id: "2",
1452
- name: "Bibliotheca Alexandrina",
1453
- books: []
1454
- }
1455
- ]
1456
- },
1457
- {
1458
- id: "2",
1459
- name: "Aalborg",
1460
- libraries: []
1461
- }
1462
- ]
1463
- }
1464
- });
1465
- (0, import_vitest.expect)(() => cache.list("Library_List", "2")).not.toThrow();
1466
- (0, import_vitest.expect)(() => cache.list("Book_List", "2")).not.toThrow();
1467
- });
1468
- import_vitest.test.todo("can write to and resolve layers");
1469
- import_vitest.test.todo("resolving a layer with the same value as the most recent doesn't notify subscribers");