@khanacademy/wonder-blocks-data 11.0.3 → 11.0.5

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 (42) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/components/data.d.ts +1 -1
  3. package/dist/components/data.js.flow +1 -2
  4. package/dist/components/gql-router.js.flow +1 -2
  5. package/dist/components/intercept-context.js.flow +1 -2
  6. package/dist/components/intercept-requests.js.flow +1 -2
  7. package/dist/components/track-data.js.flow +1 -2
  8. package/dist/hooks/use-cached-effect.js.flow +1 -2
  9. package/dist/hooks/use-gql-router-context.js.flow +1 -2
  10. package/dist/hooks/use-gql.js.flow +1 -2
  11. package/dist/hooks/use-hydratable-effect.js.flow +1 -2
  12. package/dist/hooks/use-request-interception.js.flow +1 -2
  13. package/dist/hooks/use-server-effect.js.flow +1 -2
  14. package/dist/hooks/use-shared-cache.js.flow +1 -2
  15. package/dist/index.js.flow +1 -2
  16. package/dist/util/data-error.js.flow +1 -2
  17. package/dist/util/get-gql-data-from-response.js.flow +1 -2
  18. package/dist/util/get-gql-request-id.js.flow +1 -2
  19. package/dist/util/gql-error.js.flow +1 -2
  20. package/dist/util/gql-router-context.js.flow +1 -2
  21. package/dist/util/gql-types.js.flow +1 -2
  22. package/dist/util/graphql-document-node-parser.js.flow +1 -2
  23. package/dist/util/graphql-types.js.flow +28 -24
  24. package/dist/util/hydration-cache-api.js.flow +1 -2
  25. package/dist/util/merge-gql-context.js.flow +1 -2
  26. package/dist/util/purge-caches.js.flow +1 -2
  27. package/dist/util/request-api.js.flow +1 -2
  28. package/dist/util/request-fulfillment.js.flow +1 -2
  29. package/dist/util/request-tracking.js.flow +1 -2
  30. package/dist/util/result-from-cache-response.js.flow +1 -2
  31. package/dist/util/scoped-in-memory-cache.js.flow +1 -2
  32. package/dist/util/serializable-in-memory-cache.js.flow +1 -2
  33. package/dist/util/ssr-cache.js.flow +1 -2
  34. package/dist/util/status.js.flow +1 -2
  35. package/dist/util/to-gql-operation.js.flow +1 -2
  36. package/dist/util/types.js.flow +1 -2
  37. package/package.json +2 -2
  38. package/src/components/__tests__/data.test.tsx +0 -34
  39. package/src/components/data.ts +4 -4
  40. package/src/util/graphql-types.js.flow +30 -0
  41. package/src/util/graphql-types.ts +1 -0
  42. package/tsconfig.tsbuildinfo +1 -1
@@ -54,7 +54,6 @@ describe("Data", () => {
54
54
  // Act
55
55
  render(
56
56
  <Data handler={fakeHandler} requestId="ID">
57
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
58
57
  {fakeChildrenFn}
59
58
  </Data>,
60
59
  );
@@ -74,7 +73,6 @@ describe("Data", () => {
74
73
  // Act
75
74
  render(
76
75
  <Data handler={fakeHandler} requestId="ID">
77
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
78
76
  {fakeChildrenFn}
79
77
  </Data>,
80
78
  );
@@ -98,11 +96,9 @@ describe("Data", () => {
98
96
  render(
99
97
  <View>
100
98
  <Data handler={fakeHandler} requestId="ID">
101
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
102
99
  {fakeChildrenFn}
103
100
  </Data>
104
101
  <Data handler={fakeHandler} requestId="ID">
105
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
106
102
  {fakeChildrenFn}
107
103
  </Data>
108
104
  </View>,
@@ -124,7 +120,6 @@ describe("Data", () => {
124
120
  // Act
125
121
  render(
126
122
  <Data handler={fakeHandler} requestId="ID">
127
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
128
123
  {fakeChildrenFn}
129
124
  </Data>,
130
125
  );
@@ -159,7 +154,6 @@ describe("Data", () => {
159
154
  // Act
160
155
  render(
161
156
  <Data handler={fakeHandler} requestId="ID">
162
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
163
157
  {fakeChildrenFn}
164
158
  </Data>,
165
159
  );
@@ -191,7 +185,6 @@ describe("Data", () => {
191
185
  // Act
192
186
  render(
193
187
  <Data handler={fakeHandler} requestId="ID">
194
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
195
188
  {fakeChildrenFn}
196
189
  </Data>,
197
190
  );
@@ -222,7 +215,6 @@ describe("Data", () => {
222
215
  // Act
223
216
  render(
224
217
  <Data handler={fakeHandler} requestId="ID">
225
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
226
218
  {fakeChildrenFn}
227
219
  </Data>,
228
220
  );
@@ -252,7 +244,6 @@ describe("Data", () => {
252
244
  const fakeChildrenFn = jest.fn(() => null);
253
245
  const wrapper = render(
254
246
  <Data handler={fakeHandler} requestId="ID">
255
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
256
247
  {fakeChildrenFn}
257
248
  </Data>,
258
249
  );
@@ -265,7 +256,6 @@ describe("Data", () => {
265
256
  // Act
266
257
  wrapper.rerender(
267
258
  <Data handler={fakeHandler} requestId="NEW_ID">
268
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
269
259
  {fakeChildrenFn}
270
260
  </Data>,
271
261
  );
@@ -296,13 +286,11 @@ describe("Data", () => {
296
286
  const fakeChildrenFn = jest.fn(() => null);
297
287
  const wrapper = render(
298
288
  <Data handler={oldHandler} requestId="ID">
299
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
300
289
  {fakeChildrenFn}
301
290
  </Data>,
302
291
  );
303
292
  wrapper.rerender(
304
293
  <Data handler={oldHandler} requestId="NEW_ID">
305
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
306
294
  {fakeChildrenFn}
307
295
  </Data>,
308
296
  );
@@ -332,13 +320,11 @@ describe("Data", () => {
332
320
  const fakeChildrenFn = jest.fn(() => null);
333
321
  const wrapper = render(
334
322
  <Data handler={oldHandler} requestId="ID">
335
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
336
323
  {fakeChildrenFn}
337
324
  </Data>,
338
325
  );
339
326
  wrapper.rerender(
340
327
  <Data handler={oldHandler} requestId="NEW_ID">
341
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
342
328
  {fakeChildrenFn}
343
329
  </Data>,
344
330
  );
@@ -372,13 +358,11 @@ describe("Data", () => {
372
358
  const fakeChildrenFn = jest.fn(() => null);
373
359
  const wrapper = render(
374
360
  <Data handler={oldHandler} requestId="ID">
375
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
376
361
  {fakeChildrenFn}
377
362
  </Data>,
378
363
  );
379
364
  wrapper.rerender(
380
365
  <Data handler={oldHandler} requestId="NEW_ID">
381
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
382
366
  {fakeChildrenFn}
383
367
  </Data>,
384
368
  );
@@ -409,7 +393,6 @@ describe("Data", () => {
409
393
  render(
410
394
  <InterceptRequests interceptor={interceptHandler}>
411
395
  <Data handler={fakeHandler} requestId="ID">
412
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
413
396
  {fakeChildrenFn}
414
397
  </Data>
415
398
  </InterceptRequests>,
@@ -431,7 +414,6 @@ describe("Data", () => {
431
414
  render(
432
415
  <InterceptRequests interceptor={interceptHandler}>
433
416
  <Data handler={fakeHandler} requestId="ID">
434
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
435
417
  {fakeChildrenFn}
436
418
  </Data>
437
419
  </InterceptRequests>,
@@ -459,7 +441,6 @@ describe("Data", () => {
459
441
  requestId="ID1"
460
442
  retainResultOnChange={true}
461
443
  >
462
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
463
444
  {fakeChildrenFn}
464
445
  </Data>,
465
446
  );
@@ -472,7 +453,6 @@ describe("Data", () => {
472
453
  requestId="ID2"
473
454
  retainResultOnChange={true}
474
455
  >
475
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
476
456
  {fakeChildrenFn}
477
457
  </Data>,
478
458
  );
@@ -518,7 +498,6 @@ describe("Data", () => {
518
498
  // Act
519
499
  render(
520
500
  <Data handler={fakeHandler} requestId="ID">
521
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
522
501
  {fakeChildrenFn}
523
502
  </Data>,
524
503
  );
@@ -544,7 +523,6 @@ describe("Data", () => {
544
523
  WhenClientSide.ExecuteWhenNoSuccessResult
545
524
  }
546
525
  >
547
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
548
526
  {fakeChildrenFn}
549
527
  </Data>,
550
528
  );
@@ -565,7 +543,6 @@ describe("Data", () => {
565
543
  requestId="ID"
566
544
  clientBehavior={WhenClientSide.AlwaysExecute}
567
545
  >
568
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
569
546
  {fakeChildrenFn}
570
547
  </Data>,
571
548
  );
@@ -599,7 +576,6 @@ describe("Data", () => {
599
576
  // Act
600
577
  render(
601
578
  <Data handler={fakeHandler} requestId="ID">
602
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
603
579
  {fakeChildrenFn}
604
580
  </Data>,
605
581
  );
@@ -634,7 +610,6 @@ describe("Data", () => {
634
610
  // Act
635
611
  ReactDOMServer.renderToString(
636
612
  <Data handler={fakeHandler} requestId="ID">
637
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
638
613
  {fakeChildrenFn}
639
614
  </Data>,
640
615
  );
@@ -651,7 +626,6 @@ describe("Data", () => {
651
626
  // Act
652
627
  ReactDOMServer.renderToString(
653
628
  <Data handler={fakeHandler} requestId="ID">
654
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
655
629
  {fakeChildrenFn}
656
630
  </Data>,
657
631
  );
@@ -675,7 +649,6 @@ describe("Data", () => {
675
649
  ReactDOMServer.renderToString(
676
650
  <TrackData>
677
651
  <Data handler={fakeHandler} requestId="ID">
678
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
679
652
  {fakeChildrenFn}
680
653
  </Data>
681
654
  </TrackData>,
@@ -702,7 +675,6 @@ describe("Data", () => {
702
675
  ReactDOMServer.renderToString(
703
676
  <InterceptRequests interceptor={interceptedHandler}>
704
677
  <Data handler={fakeHandler} requestId="ID">
705
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
706
678
  {fakeChildrenFn}
707
679
  </Data>
708
680
  </InterceptRequests>,
@@ -730,7 +702,6 @@ describe("Data", () => {
730
702
  <TrackData>
731
703
  <InterceptRequests interceptor={interceptedHandler}>
732
704
  <Data handler={fakeHandler} requestId="ID">
733
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
734
705
  {fakeChildrenFn}
735
706
  </Data>
736
707
  </InterceptRequests>
@@ -766,7 +737,6 @@ describe("Data", () => {
766
737
  // Act
767
738
  ReactDOMServer.renderToString(
768
739
  <Data handler={fakeHandler} requestId="ID">
769
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
770
740
  {fakeChildrenFn}
771
741
  </Data>,
772
742
  );
@@ -783,7 +753,6 @@ describe("Data", () => {
783
753
  // Act
784
754
  ReactDOMServer.renderToString(
785
755
  <Data handler={fakeHandler} requestId="ID">
786
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
787
756
  {fakeChildrenFn}
788
757
  </Data>,
789
758
  );
@@ -806,7 +775,6 @@ describe("Data", () => {
806
775
  // Act
807
776
  ReactDOMServer.renderToString(
808
777
  <Data handler={fakeHandler} requestId="ID">
809
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
810
778
  {fakeChildrenFn}
811
779
  </Data>,
812
780
  );
@@ -831,7 +799,6 @@ describe("Data", () => {
831
799
  ReactDOMServer.renderToString(
832
800
  <TrackData>
833
801
  <Data handler={fakeHandler} requestId="ID">
834
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
835
802
  {fakeChildrenFn}
836
803
  </Data>
837
804
  </TrackData>,
@@ -857,7 +824,6 @@ describe("Data", () => {
857
824
  ReactDOMServer.renderToString(
858
825
  <InterceptRequests interceptor={interceptHandler}>
859
826
  <Data handler={fakeHandler} requestId="ID">
860
- {/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
861
827
  {fakeChildrenFn}
862
828
  </Data>
863
829
  </InterceptRequests>,
@@ -48,7 +48,7 @@ type Props<
48
48
  * loading state and data or error that gets retrieved from cache or loaded
49
49
  * via the request if no cached value is available.
50
50
  */
51
- children: (result: Result<TData>) => React.ReactElement;
51
+ children: (result: Result<TData>) => React.ReactNode;
52
52
  };
53
53
 
54
54
  /**
@@ -57,18 +57,18 @@ type Props<
57
57
  * support server-side rendering and efficient caching.
58
58
  */
59
59
  // TODO(FEI-5000): Update this support generic props correctly
60
- const Data: React.FC<Props<any>> = <TData extends ValidCacheData>({
60
+ const Data: React.FC<Props<any>> = (<TData extends ValidCacheData>({
61
61
  requestId,
62
62
  handler,
63
63
  children,
64
64
  retainResultOnChange = false,
65
65
  clientBehavior = WhenClientSide.ExecuteWhenNoSuccessResult,
66
- }: Props<TData>): React.ReactElement => {
66
+ }: Props<TData>): React.ReactNode => {
67
67
  const result = useHydratableEffect(requestId, handler, {
68
68
  retainResultOnChange,
69
69
  clientBehavior,
70
70
  });
71
71
  return children(result);
72
- };
72
+ }) as React.FC<Props<any>>;
73
73
 
74
74
  export default Data;
@@ -0,0 +1,30 @@
1
+ // @flow
2
+ // NOTE(somewhatabstract):
3
+ // These types are bare minimum to support document parsing. They're derived
4
+ // from graphql@14.5.8, the last version that provided flow types.
5
+ // Doing this avoids us having to take a dependency on that library just for
6
+ // these types.
7
+ export interface DefinitionNode {
8
+ +kind: string;
9
+ }
10
+
11
+ export type VariableDefinitionNode = {
12
+ +kind: "VariableDefinition",
13
+ ...
14
+ };
15
+
16
+ export interface OperationDefinitionNode extends DefinitionNode {
17
+ +kind: "OperationDefinition";
18
+ +operation: string;
19
+ +variableDefinitions: $ReadOnlyArray<VariableDefinitionNode>;
20
+ +name?: {|
21
+ +kind: mixed,
22
+ +value: string,
23
+ |};
24
+ }
25
+
26
+ export type DocumentNode = {
27
+ +kind: "Document",
28
+ +definitions: $ReadOnlyArray<DefinitionNode>,
29
+ ...
30
+ };
@@ -1,3 +1,4 @@
1
+ // WARNING: If you modify this file you must update graphql-types.js.flow.
1
2
  // NOTE(somewhatabstract):
2
3
  // These types are bare minimum to support document parsing. They're derived
3
4
  // from graphql@14.5.8, the last version that provided TypeScript types.