houdini 0.17.9 → 0.17.11

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