react-relay 16.2.0 → 18.0.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 (93) hide show
  1. package/ReactRelayContainerUtils.js.flow +2 -2
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -1
  4. package/ReactRelayFragmentContainer.js.flow +10 -8
  5. package/ReactRelayLocalQueryRenderer.js.flow +4 -1
  6. package/ReactRelayPaginationContainer.js.flow +4 -2
  7. package/ReactRelayQueryRenderer.js.flow +2 -2
  8. package/ReactRelayQueryRendererContext.js.flow +1 -1
  9. package/ReactRelayRefetchContainer.js.flow +2 -2
  10. package/ReactRelayTypes.js.flow +45 -18
  11. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -2
  12. package/buildReactRelayContainer.js.flow +10 -8
  13. package/getRootVariablesForFragments.js.flow +1 -0
  14. package/hooks.js +1 -1
  15. package/index.js +1 -1
  16. package/legacy.js +1 -1
  17. package/lib/ReactRelayFragmentContainer.js +2 -2
  18. package/lib/buildReactRelayContainer.js +3 -3
  19. package/lib/relay-hooks/legacy/FragmentResource.js +14 -16
  20. package/lib/relay-hooks/loadEntryPoint.js +8 -5
  21. package/lib/relay-hooks/loadQuery.js +2 -14
  22. package/lib/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js → readFragmentInternal.js} +7 -5
  23. package/lib/relay-hooks/useEntryPointLoader.js +5 -8
  24. package/lib/relay-hooks/useFragment.js +7 -20
  25. package/lib/relay-hooks/useFragmentInternal.js +13 -0
  26. package/lib/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js → useFragmentInternal_CURRENT.js} +12 -18
  27. package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +520 -0
  28. package/lib/relay-hooks/useLazyLoadQuery.js +2 -5
  29. package/lib/relay-hooks/useLazyLoadQueryNode.js +2 -13
  30. package/lib/relay-hooks/usePaginationFragment.js +17 -13
  31. package/lib/relay-hooks/usePreloadedQuery.js +6 -9
  32. package/lib/relay-hooks/useQueryLoader.js +1 -3
  33. package/lib/relay-hooks/useRefetchableFragment.js +3 -12
  34. package/lib/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js → useRefetchableFragmentInternal.js} +7 -7
  35. package/multi-actor/ActorChange.js.flow +1 -1
  36. package/multi-actor/useRelayActorEnvironment.js.flow +1 -1
  37. package/package.json +3 -3
  38. package/react-relay-hooks.js +2 -2
  39. package/react-relay-hooks.min.js +2 -2
  40. package/react-relay-legacy.js +2 -2
  41. package/react-relay-legacy.min.js +2 -2
  42. package/react-relay.js +2 -2
  43. package/react-relay.min.js +2 -2
  44. package/relay-hooks/EntryPointTypes.flow.js.flow +49 -25
  45. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +22 -5
  46. package/relay-hooks/MatchContainer.js.flow +1 -1
  47. package/relay-hooks/ProfilerContext.js.flow +1 -1
  48. package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +43 -0
  49. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +21 -0
  50. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +19 -0
  51. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +22 -0
  52. package/relay-hooks/legacy/FragmentResource.js.flow +13 -16
  53. package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +2 -2
  54. package/relay-hooks/legacy/useFragmentNode.js.flow +1 -1
  55. package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +2 -2
  56. package/relay-hooks/loadEntryPoint.js.flow +10 -4
  57. package/relay-hooks/loadQuery.js.flow +10 -33
  58. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -1
  59. package/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js.flow → readFragmentInternal.js.flow} +6 -4
  60. package/relay-hooks/useClientQuery.js.flow +1 -1
  61. package/relay-hooks/useEntryPointLoader.js.flow +4 -5
  62. package/relay-hooks/useFetchTrackingRef.js.flow +1 -1
  63. package/relay-hooks/useFragment.js.flow +8 -25
  64. package/relay-hooks/useFragmentInternal.js.flow +45 -0
  65. package/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js.flow → useFragmentInternal_CURRENT.js.flow} +14 -5
  66. package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +764 -0
  67. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  68. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  69. package/relay-hooks/useIsParentQueryActive.js.flow +5 -2
  70. package/relay-hooks/useLazyLoadQuery.js.flow +3 -7
  71. package/relay-hooks/useLazyLoadQueryNode.js.flow +3 -19
  72. package/relay-hooks/useLoadMoreFunction.js.flow +1 -1
  73. package/relay-hooks/useMemoOperationDescriptor.js.flow +1 -1
  74. package/relay-hooks/useMemoVariables.js.flow +1 -1
  75. package/relay-hooks/useMutation.js.flow +1 -1
  76. package/relay-hooks/usePaginationFragment.js.flow +62 -50
  77. package/relay-hooks/usePreloadedQuery.js.flow +2 -6
  78. package/relay-hooks/useQueryLoader.js.flow +3 -7
  79. package/relay-hooks/useRefetchableFragment.js.flow +7 -37
  80. package/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow → useRefetchableFragmentInternal.js.flow} +11 -11
  81. package/relay-hooks/useRelayEnvironment.js.flow +1 -1
  82. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -1
  83. package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
  84. package/relay-hooks/useSubscription.js.flow +1 -1
  85. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +1 -1
  86. package/lib/relay-hooks/HooksImplementation.js +0 -15
  87. package/lib/relay-hooks/experimental/useFragment_EXPERIMENTAL.js +0 -26
  88. package/lib/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js +0 -127
  89. package/lib/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js +0 -23
  90. package/relay-hooks/HooksImplementation.js.flow +0 -45
  91. package/relay-hooks/experimental/useFragment_EXPERIMENTAL.js.flow +0 -72
  92. package/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js.flow +0 -161
  93. package/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js.flow +0 -49
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ * @oncall relay
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ import type {
15
+ EnvironmentProviderOptions,
16
+ ExtractQueryTypes,
17
+ PreloadedQuery,
18
+ } from '../../EntryPointTypes.flow';
19
+
20
+ type Query = {
21
+ +variables: {foo: string, bar: number},
22
+ +response: mixed,
23
+ +rawResponse?: {...},
24
+ };
25
+
26
+ const _good: ExtractQueryTypes<
27
+ EnvironmentProviderOptions,
28
+ {root: PreloadedQuery<Query>},
29
+ >['root']['variables'] = {
30
+ foo: 'bar',
31
+ bar: 3,
32
+ };
33
+
34
+ const _bad: ExtractQueryTypes<
35
+ EnvironmentProviderOptions,
36
+ {root: PreloadedQuery<Query>},
37
+ // $FlowExpectedError[prop-missing]
38
+ >['root']['variables'] = {
39
+ memebers_are_checked: true,
40
+ // $FlowExpectedError[incompatible-type]
41
+ foo: 1,
42
+ bar: 3,
43
+ };
@@ -47,23 +47,32 @@ type ExpectedReturnType<
47
47
  // Nullability of returned data type is correct
48
48
  // $FlowFixMe[prop-missing]
49
49
  // $FlowFixMe[incompatible-cast]
50
+ // $FlowFixMe[incompatible-exact]
51
+ // $FlowFixMe[react-rule-hook]
50
52
  (useBlockingPaginationFragment(
51
53
  refetchableFragmentInput,
52
54
  keyNonNullable,
53
55
  ): ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>);
54
56
 
57
+ // $FlowFixMe[react-rule-hook]
55
58
  (useBlockingPaginationFragment(
56
59
  refetchableFragmentInput,
57
60
  keyNullable,
58
61
  ): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
59
62
 
60
63
  // $FlowExpectedError: can't cast nullable to non-nullable
64
+ // $FlowFixMe[react-rule-hook]
65
+ // $FlowFixMe[incompatible-cast]
61
66
  (useBlockingPaginationFragment(
62
67
  refetchableFragmentInput,
63
68
  keyNullable,
64
69
  ): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
65
70
 
66
71
  // $FlowExpectedError: actual type of returned data is correct
72
+ // $FlowFixMe[react-rule-hook]
73
+ // $FlowFixMe[incompatible-exact]
74
+ // $FlowFixMe[prop-missing]
75
+ // $FlowFixMe[incompatible-cast]
67
76
  (useBlockingPaginationFragment(
68
77
  refetchableFragmentInput,
69
78
  // $FlowExpectedError[incompatible-call]
@@ -71,6 +80,7 @@ type ExpectedReturnType<
71
80
  ): ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>);
72
81
 
73
82
  // $FlowExpectedError[incompatible-call] `Example_user$fragmentType` is incompatible with `FragmentType`
83
+ // $FlowFixMe[react-rule-hook]
74
84
  (useBlockingPaginationFragment(
75
85
  refetchableFragmentInput,
76
86
  // $FlowExpectedError[incompatible-call]
@@ -78,18 +88,28 @@ type ExpectedReturnType<
78
88
  ): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
79
89
 
80
90
  // $FlowExpectedError: Key should not be a user provided object
91
+ // $FlowFixMe[react-rule-hook]
92
+ // $FlowFixMe[prop-missing]
93
+ // $FlowFixMe[cannot-resolve-name]
81
94
  useBlockingPaginationFragment(fragmentInput, {abc: 123});
82
95
 
83
96
  // $FlowExpectedError: Key should not be an empty object
97
+ // $FlowFixMe[react-rule-hook]
98
+ // $FlowFixMe[prop-missing]
99
+ // $FlowFixMe[cannot-resolve-name]
84
100
  useBlockingPaginationFragment(fragmentInput, {});
85
101
 
86
102
  // $FlowExpectedError: Key should be the `<name>$key` type from generated flow
103
+ // $FlowFixMe[react-rule-hook]
104
+ // $FlowFixMe[prop-missing]
105
+ // $FlowFixMe[cannot-resolve-name]
87
106
  useBlockingPaginationFragment(fragmentInput, fragmentData);
88
107
 
89
108
  // Refetch function options:
90
109
  declare var variables: QueryVariables;
91
110
  declare var environment: IEnvironment;
92
111
 
112
+ // $FlowFixMe[react-rule-hook]
93
113
  const {refetch} = useBlockingPaginationFragment(
94
114
  refetchableFragmentInput,
95
115
  keyNonNullable,
@@ -108,6 +128,7 @@ refetch(variables, {
108
128
  declare var extraVariables: {nickname: string};
109
129
  declare var invalidVariables: {foo: string};
110
130
 
131
+ // $FlowFixMe[react-rule-hook]
111
132
  const {loadNext} = useBlockingPaginationFragment(
112
133
  refetchableFragmentInput,
113
134
  keyNonNullable,
@@ -49,29 +49,40 @@ type ExpectedReturnType<
49
49
  // Nullability of returned data type is correct
50
50
  // $FlowFixMe[prop-missing]
51
51
  // $FlowFixMe[incompatible-cast]
52
+ // $FlowFixMe[incompatible-exact]
53
+ // $FlowFixMe[react-rule-hook]
52
54
  (usePaginationFragment(
53
55
  refetchableFragmentInput,
54
56
  keyNonNullable,
55
57
  ): ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>);
56
58
 
59
+ // $FlowFixMe[react-rule-hook]
57
60
  (usePaginationFragment(
58
61
  refetchableFragmentInput,
59
62
  keyNullable,
60
63
  ): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
61
64
 
62
65
  // $FlowExpectedError: can't cast nullable to non-nullable
66
+ // $FlowFixMe[react-rule-hook]
67
+ // $FlowFixMe[incompatible-cast]
63
68
  (usePaginationFragment(
64
69
  refetchableFragmentInput,
65
70
  keyNullable,
66
71
  ): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
67
72
 
68
73
  // $FlowExpectedError: actual type of returned data is correct
74
+ // $FlowFixMe[react-rule-hook]
75
+ // $FlowFixMe[incompatible-exact]
76
+ // $FlowFixMe[prop-missing]
77
+ // $FlowFixMe[incompatible-cast]
69
78
  (usePaginationFragment(
70
79
  refetchableFragmentInput,
71
80
  // $FlowFixMe[incompatible-call]
72
81
  keyAnotherNonNullable,
73
82
  ): ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>);
74
83
  // $FlowExpectedError
84
+ // $FlowFixMe[react-rule-hook]
85
+ // $FlowFixMe[incompatible-cast]
75
86
  (usePaginationFragment(
76
87
  refetchableFragmentInput,
77
88
  // $FlowFixMe[incompatible-call]
@@ -79,18 +90,25 @@ type ExpectedReturnType<
79
90
  ): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
80
91
 
81
92
  // $FlowExpectedError: Key should not be a user provided object
93
+ // $FlowFixMe[react-rule-hook]
94
+ // $FlowFixMe[prop-missing]
82
95
  usePaginationFragment(refetchableFragmentInput, {abc: 123});
83
96
 
84
97
  // $FlowExpectedError: Key should not be an empty object
98
+ // $FlowFixMe[react-rule-hook]
99
+ // $FlowFixMe[prop-missing]
85
100
  usePaginationFragment(refetchableFragmentInput, {});
86
101
 
87
102
  // $FlowExpectedError: Key should be the `<name>$key` type from generated flow
103
+ // $FlowFixMe[react-rule-hook]
104
+ // $FlowFixMe[prop-missing]
88
105
  usePaginationFragment(refetchableFragmentInput, fragmentData);
89
106
 
90
107
  // Refetch function options:
91
108
  declare var variables: QueryVariables;
92
109
  declare var environment: IEnvironment;
93
110
 
111
+ // $FlowFixMe[react-rule-hook]
94
112
  const {refetch} = usePaginationFragment(
95
113
  refetchableFragmentInput,
96
114
  keyNonNullable,
@@ -109,6 +127,7 @@ refetch(variables, {
109
127
  declare var extraVariables: {nickname: string};
110
128
  declare var invalidVariables: {foo: string};
111
129
 
130
+ // $FlowFixMe[react-rule-hook]
112
131
  const {loadNext} = usePaginationFragment(
113
132
  refetchableFragmentInput,
114
133
  keyNonNullable,
@@ -33,53 +33,75 @@ import {
33
33
  // Nullability of returned data type is correct
34
34
  // $FlowFixMe[prop-missing]
35
35
  // $FlowFixMe[incompatible-cast]
36
+ // $FlowFixMe[incompatible-exact]
37
+ // $FlowFixMe[react-rule-hook]
36
38
  (useRefetchableFragment(refetchableFragmentInput, keyNonNullable): [
37
39
  NonNullableData,
38
40
  FetchFn<QueryVariablesSubset>,
39
41
  ]);
40
42
 
43
+ // $FlowFixMe[react-rule-hook]
41
44
  (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
42
45
  NullableData,
43
46
  FetchFn<QueryVariables>,
44
47
  ]);
45
48
 
46
49
  // $FlowExpectedError: can't cast nullable to non-nullable
50
+ // $FlowFixMe[react-rule-hook]
51
+ // $FlowFixMe[incompatible-cast]
47
52
  (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
48
53
  NonNullableData,
49
54
  FetchFn<QueryVariables>,
50
55
  ]);
51
56
 
52
57
  // $FlowExpectedError: refetch requires exact type if key is nullable
58
+ // $FlowFixMe[react-rule-hook]
59
+ // $FlowFixMe[incompatible-exact]
60
+ // $FlowFixMe[prop-missing]
53
61
  (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
54
62
  NullableData,
55
63
  FetchFn<QueryVariablesSubset>,
56
64
  ]);
57
65
 
58
66
  // $FlowExpectedError: actual type of returned data is correct
67
+ // $FlowFixMe[react-rule-hook]
68
+ // $FlowFixMe[incompatible-call]
69
+ // $FlowFixMe[incompatible-exact]
70
+ // $FlowFixMe[prop-missing]
71
+ // $FlowFixMe[incompatible-cast]
59
72
  (useRefetchableFragment(refetchableFragmentInput, keyAnotherNonNullable): [
60
73
  NonNullableData,
61
74
  FetchFn<QueryVariablesSubset>,
62
75
  ]);
63
76
 
64
77
  // $FlowExpectedError - incompatible key types
78
+ // $FlowFixMe[react-rule-hook]
79
+ // $FlowFixMe[incompatible-call]
65
80
  (useRefetchableFragment(refetchableFragmentInput, keyAnotherNullable): [
66
81
  NullableData,
67
82
  FetchFn<QueryVariables>,
68
83
  ]);
69
84
 
70
85
  // $FlowExpectedError: Key should not be a user provided object
86
+ // $FlowFixMe[react-rule-hook]
87
+ // $FlowFixMe[prop-missing]
71
88
  useRefetchableFragment(refetchableFragmentInput, {abc: 123});
72
89
 
73
90
  // $FlowExpectedError: Key should not be an empty object
91
+ // $FlowFixMe[react-rule-hook]
92
+ // $FlowFixMe[prop-missing]
74
93
  useRefetchableFragment(refetchableFragmentInput, {});
75
94
 
76
95
  // $FlowExpectedError: Key should be the `<name>$key` type from generated flow
96
+ // $FlowFixMe[react-rule-hook]
97
+ // $FlowFixMe[prop-missing]
77
98
  useRefetchableFragment(refetchableFragmentInput, fragmentData);
78
99
 
79
100
  // Refetch function options:
80
101
  declare var variables: QueryVariables;
81
102
  declare var environment: IEnvironment;
82
103
 
104
+ // $FlowFixMe[react-rule-hook]
83
105
  const [, refetch] = useRefetchableFragment(
84
106
  refetchableFragmentInput,
85
107
  keyNonNullable,
@@ -206,11 +206,9 @@ class FragmentResourceImpl {
206
206
  constructor(environment: IEnvironment) {
207
207
  this._environment = environment;
208
208
  this._cache = LRUCache.create(CACHE_CAPACITY);
209
- if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
210
- this._clientEdgeQueryResultsCache = new ClientEdgeQueryResultsCache(
211
- environment,
212
- );
213
- }
209
+ this._clientEdgeQueryResultsCache = new ClientEdgeQueryResultsCache(
210
+ environment,
211
+ );
214
212
  }
215
213
 
216
214
  /**
@@ -397,7 +395,6 @@ class FragmentResourceImpl {
397
395
  // First, initiate a query for any client edges that were missing data:
398
396
  let clientEdgeRequests: ?Array<RequestDescriptor> = null;
399
397
  if (
400
- RelayFeatureFlags.ENABLE_CLIENT_EDGES &&
401
398
  fragmentNode.metadata?.hasClientEdges === true &&
402
399
  hasMissingClientEdges(snapshot)
403
400
  ) {
@@ -432,7 +429,7 @@ class FragmentResourceImpl {
432
429
  );
433
430
  }
434
431
  let clientEdgePromises: Array<Promise<void>> = [];
435
- if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && clientEdgeRequests) {
432
+ if (clientEdgeRequests) {
436
433
  clientEdgePromises = clientEdgeRequests
437
434
  .map(request => getPromiseForActiveRequest(this._environment, request))
438
435
  .filter(Boolean);
@@ -567,6 +564,7 @@ class FragmentResourceImpl {
567
564
  s.missingRequiredFields,
568
565
  s.relayResolverErrors,
569
566
  s.errorResponseFields,
567
+ s.selector.node.metadata?.throwOnFieldError ?? false,
570
568
  );
571
569
  });
572
570
  } else {
@@ -575,6 +573,7 @@ class FragmentResourceImpl {
575
573
  snapshot.missingRequiredFields,
576
574
  snapshot.relayResolverErrors,
577
575
  snapshot.errorResponseFields,
576
+ snapshot.selector.node.metadata?.throwOnFieldError ?? false,
578
577
  );
579
578
  }
580
579
  }
@@ -672,15 +671,13 @@ class FragmentResourceImpl {
672
671
  );
673
672
  }
674
673
 
675
- if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
676
- const clientEdgeQueryResults =
677
- this._clientEdgeQueryResultsCache?.get(cacheKey) ?? undefined;
678
- if (clientEdgeQueryResults?.length) {
679
- const queryResource = getQueryResourceForEnvironment(this._environment);
680
- clientEdgeQueryResults.forEach(queryResult => {
681
- disposables.push(queryResource.retain(queryResult));
682
- });
683
- }
674
+ const clientEdgeQueryResults =
675
+ this._clientEdgeQueryResultsCache?.get(cacheKey) ?? undefined;
676
+ if (clientEdgeQueryResults?.length) {
677
+ const queryResource = getQueryResourceForEnvironment(this._environment);
678
+ clientEdgeQueryResults.forEach(queryResult => {
679
+ disposables.push(queryResource.retain(queryResult));
680
+ });
684
681
  }
685
682
 
686
683
  return {
@@ -65,7 +65,7 @@ type ReturnType<TVariables, TData, TKey> = {
65
65
  refetch: RefetchFn<TVariables, TKey>,
66
66
  };
67
67
 
68
- function useBlockingPaginationFragment<
68
+ hook useBlockingPaginationFragment<
69
69
  TFragmentType: FragmentType,
70
70
  TVariables: Variables,
71
71
  TData,
@@ -166,7 +166,7 @@ function useBlockingPaginationFragment<
166
166
  };
167
167
  }
168
168
 
169
- function useLoadMore<TVariables: Variables>(args: {
169
+ hook useLoadMore<TVariables: Variables>(args: {
170
170
  disableStoreUpdates: () => void,
171
171
  enableStoreUpdates: () => void,
172
172
  ...$Exact<
@@ -26,7 +26,7 @@ type ReturnType<TFragmentData: mixed> = {
26
26
  enableStoreUpdates: () => void,
27
27
  };
28
28
 
29
- function useFragmentNode<TFragmentData: mixed>(
29
+ hook useFragmentNode<TFragmentData: mixed>(
30
30
  fragmentNode: ReaderFragment,
31
31
  fragmentRef: mixed,
32
32
  componentDisplayName: string,
@@ -162,7 +162,7 @@ function reducer(state: RefetchState, action: Action): RefetchState {
162
162
  }
163
163
  }
164
164
 
165
- function useRefetchableFragmentNode<
165
+ hook useRefetchableFragmentNode<
166
166
  TQuery: OperationType,
167
167
  TKey: ?{+$data?: mixed, ...},
168
168
  >(
@@ -367,7 +367,7 @@ function useRefetchableFragmentNode<
367
367
  };
368
368
  }
369
369
 
370
- function useRefetchFunction<TQuery: OperationType>(
370
+ hook useRefetchFunction<TQuery: OperationType>(
371
371
  componentDisplayName: string,
372
372
  dispatch: (
373
373
  | {
@@ -17,13 +17,15 @@ import type {
17
17
  EnvironmentProviderOptions,
18
18
  IEnvironmentProvider,
19
19
  PreloadedEntryPoint,
20
+ PreloadedQuery,
20
21
  } from './EntryPointTypes.flow';
21
22
 
22
23
  const {loadQuery} = require('./loadQuery');
23
24
 
24
25
  function loadEntryPoint<
25
26
  TEntryPointParams: {...},
26
- TPreloadedQueries: {...},
27
+ // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
28
+ TPreloadedQueries: {+[string]: PreloadedQuery<any>},
27
29
  TPreloadedEntryPoints: {...},
28
30
  TRuntimeProps: {...},
29
31
  TExtraProps,
@@ -53,8 +55,12 @@ function loadEntryPoint<
53
55
  if (queries != null) {
54
56
  const queriesPropNames = Object.keys(queries);
55
57
  queriesPropNames.forEach(queryPropName => {
58
+ const query = queries[queryPropName];
59
+ if (query == null) {
60
+ return;
61
+ }
56
62
  const {environmentProviderOptions, options, parameters, variables} =
57
- queries[queryPropName];
63
+ query;
58
64
 
59
65
  const environment = environmentProvider.getEnvironment(
60
66
  environmentProviderOptions,
@@ -86,11 +92,11 @@ function loadEntryPoint<
86
92
  entryPointDescription;
87
93
  preloadedEntryPoints[entryPointPropName] = loadEntryPoint<
88
94
  _,
89
- {...},
95
+ {},
90
96
  {...},
91
97
  {...},
92
98
  mixed,
93
- EntryPointComponent<{...}, {...}, {...}, mixed>,
99
+ EntryPointComponent<{}, {...}, {...}, mixed>,
94
100
  _,
95
101
  >(environmentProvider, nestedEntryPoint, nestedParams);
96
102
  });
@@ -30,7 +30,6 @@ import type {
30
30
  } from 'relay-runtime';
31
31
 
32
32
  const invariant = require('invariant');
33
- const React = require('react');
34
33
  const {
35
34
  __internal: {fetchQueryDeduped},
36
35
  Observable,
@@ -41,29 +40,19 @@ const {
41
40
  getRequest,
42
41
  getRequestIdentifier,
43
42
  } = require('relay-runtime');
44
- const warning = require('warning');
45
43
 
46
- let RenderDispatcher = null;
47
44
  let fetchKey = 100001;
48
45
 
49
- function useTrackLoadQueryInRender() {
50
- if (RenderDispatcher === null) {
51
- // Flow does not know of React internals (rightly so), but we need to
52
- // ensure here that this function isn't called inside render.
53
- RenderDispatcher =
54
- // $FlowFixMe[prop-missing]
55
- React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
56
- ?.ReactCurrentDispatcher?.current;
57
- }
58
- }
59
-
60
- type QueryType<T> = T extends Query<infer V, infer D, infer RR>
61
- ? {
62
- variables: V,
63
- response: D,
64
- rawResponse?: $NonMaybeType<RR>,
65
- } // $FlowFixMe[deprecated-type]
66
- : $Call<<T>(PreloadableConcreteRequest<T>) => T, T>;
46
+ type QueryType<T> =
47
+ T extends Query<infer V, infer D, infer RR>
48
+ ? {
49
+ variables: V,
50
+ response: D,
51
+ rawResponse?: $NonMaybeType<RR>,
52
+ }
53
+ : [+t: T] extends [+t: PreloadableConcreteRequest<infer V>]
54
+ ? V
55
+ : empty;
67
56
 
68
57
  declare function loadQuery<
69
58
  T,
@@ -86,17 +75,6 @@ function loadQuery<
86
75
  options?: ?LoadQueryOptions,
87
76
  environmentProviderOptions?: ?TEnvironmentProviderOptions,
88
77
  ): PreloadedQueryInner<TQuery, TEnvironmentProviderOptions> {
89
- // This code ensures that we don't call loadQuery during render.
90
- const CurrentDispatcher =
91
- // $FlowFixMe[prop-missing]
92
- React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
93
- ?.ReactCurrentDispatcher?.current;
94
- warning(
95
- RenderDispatcher == null || CurrentDispatcher !== RenderDispatcher,
96
- 'Relay: `%s` should not be called inside a React render function.',
97
- options?.__nameForWarning ?? 'loadQuery',
98
- );
99
-
100
78
  // Every time you call loadQuery, we will generate a new fetchKey.
101
79
  // This will ensure that every query reference that is created and
102
80
  // passed to usePreloadedQuery is independently evaluated,
@@ -406,5 +384,4 @@ function loadQuery<
406
384
 
407
385
  module.exports = {
408
386
  loadQuery,
409
- useTrackLoadQueryInRender,
410
387
  };
@@ -16,13 +16,15 @@ import type {
16
16
  EntryPointComponent,
17
17
  EnvironmentProviderOptions,
18
18
  IEnvironmentProvider,
19
+ PreloadedQuery,
19
20
  } from './EntryPointTypes.flow';
20
21
 
21
22
  const preloadQuery = require('./preloadQuery_DEPRECATED');
22
23
 
23
24
  function prepareEntryPoint<
24
25
  TEntryPointParams: {...},
25
- TPreloadedQueries: {...},
26
+ // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
27
+ TPreloadedQueries: {+[string]: PreloadedQuery<any>},
26
28
  TPreloadedEntryPoints: {...},
27
29
  TRuntimeProps: {...},
28
30
  TExtraProps,
@@ -59,6 +61,7 @@ function prepareEntryPoint<
59
61
  environmentProviderOptions,
60
62
  );
61
63
 
64
+ // $FlowFixMe[incompatible-type]
62
65
  preloadedQueries[queryPropName] = preloadQuery<OperationType, mixed>(
63
66
  environment,
64
67
  parameters,
@@ -11,7 +11,7 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- import type {QueryResult} from '../QueryResource';
14
+ import type {QueryResult} from './QueryResource';
15
15
  import type {
16
16
  CacheConfig,
17
17
  FetchPolicy,
@@ -23,7 +23,7 @@ import type {
23
23
  } from 'relay-runtime';
24
24
  import type {MissingClientEdgeRequestInfo} from 'relay-runtime/store/RelayStoreTypes';
25
25
 
26
- const {getQueryResourceForEnvironment} = require('../QueryResource');
26
+ const {getQueryResourceForEnvironment} = require('./QueryResource');
27
27
  const invariant = require('invariant');
28
28
  const {
29
29
  __internal: {fetchQuery: fetchQueryInternal},
@@ -88,6 +88,7 @@ function handlePotentialSnapshotErrorsForState(
88
88
  state.snapshot.missingRequiredFields,
89
89
  state.snapshot.relayResolverErrors,
90
90
  state.snapshot.errorResponseFields,
91
+ state.snapshot.selector.node.metadata?.throwOnFieldError ?? false,
91
92
  );
92
93
  } else if (state.kind === 'plural') {
93
94
  for (const snapshot of state.snapshots) {
@@ -96,6 +97,7 @@ function handlePotentialSnapshotErrorsForState(
96
97
  snapshot.missingRequiredFields,
97
98
  snapshot.relayResolverErrors,
98
99
  snapshot.errorResponseFields,
100
+ snapshot.selector.node.metadata?.throwOnFieldError ?? false,
99
101
  );
100
102
  }
101
103
  }
@@ -159,7 +161,7 @@ function getFragmentState(
159
161
  }
160
162
 
161
163
  // fragmentNode cannot change during the lifetime of the component, though fragmentRef may change.
162
- function readFragmentInternal_EXPERIMENTAL(
164
+ function readFragmentInternal(
163
165
  environment: IEnvironment,
164
166
  fragmentNode: ReaderFragment,
165
167
  fragmentRef: mixed,
@@ -297,4 +299,4 @@ function readFragmentInternal_EXPERIMENTAL(
297
299
  return {data, clientEdgeQueries};
298
300
  }
299
301
 
300
- module.exports = readFragmentInternal_EXPERIMENTAL;
302
+ module.exports = readFragmentInternal;
@@ -20,7 +20,7 @@ const useLazyLoadQuery = require('./useLazyLoadQuery');
20
20
  * These queries are consist of queries for client-only data,
21
21
  * schematized via local schema extensions and/or Relay resolvers.
22
22
  */
23
- function useClientQuery<TVariables: Variables, TData, TRawResponse>(
23
+ hook useClientQuery<TVariables: Variables, TData, TRawResponse>(
24
24
  gqlQuery: ClientQuery<TVariables, TData, TRawResponse>,
25
25
  variables: TVariables,
26
26
  options?: {
@@ -17,10 +17,10 @@ import type {
17
17
  EnvironmentProviderOptions,
18
18
  IEnvironmentProvider,
19
19
  PreloadedEntryPoint,
20
+ PreloadedQuery,
20
21
  } from './EntryPointTypes.flow';
21
22
 
22
23
  const loadEntryPoint = require('./loadEntryPoint');
23
- const {useTrackLoadQueryInRender} = require('./loadQuery');
24
24
  const useIsMountedRef = require('./useIsMountedRef');
25
25
  const {useCallback, useEffect, useRef, useState} = require('react');
26
26
 
@@ -50,9 +50,10 @@ type NullEntryPointReference = {
50
50
  };
51
51
  const initialNullEntryPointReferenceState = {kind: 'NullEntryPointReference'};
52
52
 
53
- function useLoadEntryPoint<
53
+ hook useLoadEntryPoint<
54
54
  TEntryPointParams: {...},
55
- TPreloadedQueries: {...},
55
+ // $FlowExpectedError[unclear-type] Need any to make it supertype of all PreloadedQuery
56
+ TPreloadedQueries: {+[string]: PreloadedQuery<any>},
56
57
  TPreloadedEntryPoints: {...},
57
58
  TRuntimeProps: {...},
58
59
  TExtraProps,
@@ -102,8 +103,6 @@ function useLoadEntryPoint<
102
103
  * entry point references.
103
104
  */
104
105
 
105
- useTrackLoadQueryInRender();
106
-
107
106
  const initialEntryPointReferenceInternal =
108
107
  options?.TEST_ONLY__initialEntryPointData?.entryPointReference ??
109
108
  initialNullEntryPointReferenceState;
@@ -28,7 +28,7 @@ const {useCallback, useEffect} = require('react');
28
28
  * The additional functions returned by this Hook can be used to mutate
29
29
  * the ref.
30
30
  */
31
- function useFetchTrackingRef(): {
31
+ hook useFetchTrackingRef(): {
32
32
  isFetchingRef: {current: ?boolean, ...},
33
33
  startFetch: Subscription => void,
34
34
  disposeFetch: () => void,