react-relay 16.1.0 → 17.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 (80) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayFragmentContainer.js.flow +8 -6
  3. package/ReactRelayLocalQueryRenderer.js.flow +4 -1
  4. package/ReactRelayPaginationContainer.js.flow +2 -0
  5. package/ReactRelayQueryRenderer.js.flow +1 -1
  6. package/ReactRelayTypes.js.flow +1 -0
  7. package/buildReactRelayContainer.js.flow +5 -3
  8. package/getRootVariablesForFragments.js.flow +1 -0
  9. package/hooks.js +1 -1
  10. package/hooks.js.flow +1 -1
  11. package/index.js +1 -1
  12. package/index.js.flow +1 -1
  13. package/legacy.js +1 -1
  14. package/lib/ReactRelayFragmentContainer.js +2 -2
  15. package/lib/buildReactRelayContainer.js +3 -3
  16. package/lib/relay-hooks/SuspenseResource.js +7 -4
  17. package/lib/relay-hooks/{FragmentResource.js → legacy/FragmentResource.js} +19 -20
  18. package/lib/relay-hooks/{useBlockingPaginationFragment.js → legacy/useBlockingPaginationFragment.js} +2 -2
  19. package/lib/relay-hooks/{useFragmentNode.js → legacy/useFragmentNode.js} +2 -2
  20. package/lib/relay-hooks/{useRefetchableFragmentNode.js → legacy/useRefetchableFragmentNode.js} +8 -8
  21. package/lib/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js → readFragmentInternal.js} +7 -5
  22. package/lib/relay-hooks/useFragment.js +3 -13
  23. package/lib/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js → useFragmentInternal.js} +67 -31
  24. package/lib/relay-hooks/useLazyLoadQueryNode.js +2 -13
  25. package/lib/relay-hooks/usePaginationFragment.js +17 -13
  26. package/lib/relay-hooks/useRefetchableFragment.js +3 -12
  27. package/lib/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js → useRefetchableFragmentInternal.js} +7 -7
  28. package/multi-actor/useRelayActorEnvironment.js.flow +1 -1
  29. package/package.json +2 -2
  30. package/react-relay-hooks.js +2 -2
  31. package/react-relay-hooks.min.js +2 -2
  32. package/react-relay-legacy.js +2 -2
  33. package/react-relay-legacy.min.js +2 -2
  34. package/react-relay.js +2 -2
  35. package/react-relay.min.js +2 -2
  36. package/relay-hooks/EntryPointTypes.flow.js.flow +22 -27
  37. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +14 -1
  38. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +5 -11
  39. package/relay-hooks/SuspenseResource.js.flow +11 -8
  40. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +22 -1
  41. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +19 -0
  42. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +22 -0
  43. package/relay-hooks/{FragmentResource.js.flow → legacy/FragmentResource.js.flow} +21 -21
  44. package/relay-hooks/{useBlockingPaginationFragment.js.flow → legacy/useBlockingPaginationFragment.js.flow} +6 -6
  45. package/relay-hooks/{useFragmentNode.js.flow → legacy/useFragmentNode.js.flow} +3 -3
  46. package/relay-hooks/{useRefetchableFragmentNode.js.flow → legacy/useRefetchableFragmentNode.js.flow} +9 -9
  47. package/relay-hooks/loadQuery.js.flow +9 -8
  48. package/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js.flow → readFragmentInternal.js.flow} +8 -4
  49. package/relay-hooks/useClientQuery.js.flow +1 -1
  50. package/relay-hooks/useEntryPointLoader.js.flow +1 -1
  51. package/relay-hooks/useFetchTrackingRef.js.flow +1 -1
  52. package/relay-hooks/useFragment.js.flow +16 -22
  53. package/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js.flow → useFragmentInternal.js.flow} +71 -19
  54. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  55. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  56. package/relay-hooks/useIsParentQueryActive.js.flow +5 -2
  57. package/relay-hooks/useLazyLoadQuery.js.flow +3 -2
  58. package/relay-hooks/useLazyLoadQueryNode.js.flow +3 -19
  59. package/relay-hooks/useLoadMoreFunction.js.flow +1 -1
  60. package/relay-hooks/useMemoOperationDescriptor.js.flow +1 -1
  61. package/relay-hooks/useMemoVariables.js.flow +1 -1
  62. package/relay-hooks/useMutation.js.flow +1 -1
  63. package/relay-hooks/usePaginationFragment.js.flow +62 -50
  64. package/relay-hooks/usePreloadedQuery.js.flow +2 -1
  65. package/relay-hooks/useQueryLoader.js.flow +2 -5
  66. package/relay-hooks/useRefetchableFragment.js.flow +7 -37
  67. package/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow → useRefetchableFragmentInternal.js.flow} +11 -11
  68. package/relay-hooks/useRelayEnvironment.js.flow +1 -1
  69. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -1
  70. package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
  71. package/relay-hooks/useSubscription.js.flow +1 -1
  72. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +1 -1
  73. package/lib/relay-hooks/HooksImplementation.js +0 -15
  74. package/lib/relay-hooks/experimental/useFragment_EXPERIMENTAL.js +0 -26
  75. package/lib/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js +0 -127
  76. package/lib/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js +0 -23
  77. package/relay-hooks/HooksImplementation.js.flow +0 -45
  78. package/relay-hooks/experimental/useFragment_EXPERIMENTAL.js.flow +0 -66
  79. package/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js.flow +0 -161
  80. package/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js.flow +0 -49
@@ -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,
@@ -11,8 +11,8 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- import type {Cache} from './LRUCache';
15
- import type {QueryResource, QueryResult} from './QueryResource';
14
+ import type {Cache} from '../LRUCache';
15
+ import type {QueryResource, QueryResult} from '../QueryResource';
16
16
  import type {
17
17
  ConcreteRequest,
18
18
  DataID,
@@ -24,9 +24,9 @@ import type {
24
24
  } from 'relay-runtime';
25
25
  import type {MissingLiveResolverField} from 'relay-runtime/store/RelayStoreTypes';
26
26
 
27
- const LRUCache = require('./LRUCache');
28
- const {getQueryResourceForEnvironment} = require('./QueryResource');
29
- const SuspenseResource = require('./SuspenseResource');
27
+ const LRUCache = require('../LRUCache');
28
+ const {getQueryResourceForEnvironment} = require('../QueryResource');
29
+ const SuspenseResource = require('../SuspenseResource');
30
30
  const invariant = require('invariant');
31
31
  const {
32
32
  __internal: {fetchQuery, getPromiseForActiveRequest},
@@ -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);
@@ -566,6 +563,8 @@ class FragmentResourceImpl {
566
563
  this._environment,
567
564
  s.missingRequiredFields,
568
565
  s.relayResolverErrors,
566
+ s.errorResponseFields,
567
+ s.selector.node.metadata?.throwOnFieldError ?? false,
569
568
  );
570
569
  });
571
570
  } else {
@@ -573,6 +572,8 @@ class FragmentResourceImpl {
573
572
  this._environment,
574
573
  snapshot.missingRequiredFields,
575
574
  snapshot.relayResolverErrors,
575
+ snapshot.errorResponseFields,
576
+ snapshot.selector.node.metadata?.throwOnFieldError ?? false,
576
577
  );
577
578
  }
578
579
  }
@@ -670,15 +671,13 @@ class FragmentResourceImpl {
670
671
  );
671
672
  }
672
673
 
673
- if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
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
- });
681
- }
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
+ });
682
681
  }
683
682
 
684
683
  return {
@@ -776,6 +775,7 @@ class FragmentResourceImpl {
776
775
  selector: currentSnapshot.selector,
777
776
  missingRequiredFields: currentSnapshot.missingRequiredFields,
778
777
  relayResolverErrors: currentSnapshot.relayResolverErrors,
778
+ errorResponseFields: currentSnapshot.errorResponseFields,
779
779
  };
780
780
  if (updatedData !== renderData) {
781
781
  const result = getFragmentResult(
@@ -11,9 +11,9 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- import type {RefetchableFragment} from '../../relay-runtime/util/RelayRuntimeTypes';
15
- import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
14
+ import type {LoadMoreFn, UseLoadMoreFunctionArgs} from '../useLoadMoreFunction';
16
15
  import type {Options} from './useRefetchableFragmentNode';
16
+ import type {RefetchableFragment} from 'relay-runtime';
17
17
  import type {
18
18
  Disposable,
19
19
  FragmentType,
@@ -22,9 +22,9 @@ import type {
22
22
  Variables,
23
23
  } from 'relay-runtime';
24
24
 
25
- const useLoadMoreFunction = require('./useLoadMoreFunction');
25
+ const useLoadMoreFunction = require('../useLoadMoreFunction');
26
+ const useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
26
27
  const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
27
- const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
28
28
  const invariant = require('invariant');
29
29
  const {useCallback, useEffect, useRef, useState} = require('react');
30
30
  const {
@@ -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<
@@ -13,9 +13,9 @@
13
13
 
14
14
  import type {ReaderFragment} from 'relay-runtime';
15
15
 
16
+ const useRelayEnvironment = require('../useRelayEnvironment');
17
+ const useUnsafeRef_DEPRECATED = require('../useUnsafeRef_DEPRECATED');
16
18
  const {getFragmentResourceForEnvironment} = require('./FragmentResource');
17
- const useRelayEnvironment = require('./useRelayEnvironment');
18
- const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
19
19
  const {useEffect, useState} = require('react');
20
20
  const {RelayFeatureFlags, getFragmentIdentifier} = require('relay-runtime');
21
21
  const warning = require('warning');
@@ -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,
@@ -11,8 +11,8 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- import type {RefetchableIdentifierInfo} from '../../relay-runtime/util/ReaderNode';
15
- import type {LoaderFn} from './useQueryLoader';
14
+ import type {LoaderFn} from '../useQueryLoader';
15
+ import type {RefetchableIdentifierInfo} from 'relay-runtime';
16
16
  import type {
17
17
  ConcreteRequest,
18
18
  Disposable,
@@ -26,13 +26,13 @@ import type {
26
26
  VariablesOf,
27
27
  } from 'relay-runtime';
28
28
 
29
+ const ProfilerContext = require('../ProfilerContext');
30
+ const {getQueryResourceForEnvironment} = require('../QueryResource');
31
+ const useIsMountedRef = require('../useIsMountedRef');
32
+ const useQueryLoader = require('../useQueryLoader');
33
+ const useRelayEnvironment = require('../useRelayEnvironment');
29
34
  const {getFragmentResourceForEnvironment} = require('./FragmentResource');
30
- const ProfilerContext = require('./ProfilerContext');
31
- const {getQueryResourceForEnvironment} = require('./QueryResource');
32
35
  const useFragmentNode = require('./useFragmentNode');
33
- const useIsMountedRef = require('./useIsMountedRef');
34
- const useQueryLoader = require('./useQueryLoader');
35
- const useRelayEnvironment = require('./useRelayEnvironment');
36
36
  const invariant = require('invariant');
37
37
  const {useCallback, useContext, useReducer} = require('react');
38
38
  const {
@@ -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
  | {
@@ -46,7 +46,7 @@ const warning = require('warning');
46
46
  let RenderDispatcher = null;
47
47
  let fetchKey = 100001;
48
48
 
49
- function useTrackLoadQueryInRender() {
49
+ hook useTrackLoadQueryInRender() {
50
50
  if (RenderDispatcher === null) {
51
51
  // Flow does not know of React internals (rightly so), but we need to
52
52
  // ensure here that this function isn't called inside render.
@@ -57,13 +57,14 @@ function useTrackLoadQueryInRender() {
57
57
  }
58
58
  }
59
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
- }
66
- : $Call<<T>(PreloadableConcreteRequest<T>) => T, T>;
60
+ type QueryType<T> =
61
+ T extends Query<infer V, infer D, infer RR>
62
+ ? {
63
+ variables: V,
64
+ response: D,
65
+ rawResponse?: $NonMaybeType<RR>,
66
+ } // $FlowFixMe[deprecated-type]
67
+ : $Call<<T>(PreloadableConcreteRequest<T>) => T, T>;
67
68
 
68
69
  declare function loadQuery<
69
70
  T,
@@ -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},
@@ -87,6 +87,8 @@ function handlePotentialSnapshotErrorsForState(
87
87
  environment,
88
88
  state.snapshot.missingRequiredFields,
89
89
  state.snapshot.relayResolverErrors,
90
+ state.snapshot.errorResponseFields,
91
+ state.snapshot.selector.node.metadata?.throwOnFieldError ?? false,
90
92
  );
91
93
  } else if (state.kind === 'plural') {
92
94
  for (const snapshot of state.snapshots) {
@@ -94,6 +96,8 @@ function handlePotentialSnapshotErrorsForState(
94
96
  environment,
95
97
  snapshot.missingRequiredFields,
96
98
  snapshot.relayResolverErrors,
99
+ snapshot.errorResponseFields,
100
+ snapshot.selector.node.metadata?.throwOnFieldError ?? false,
97
101
  );
98
102
  }
99
103
  }
@@ -157,7 +161,7 @@ function getFragmentState(
157
161
  }
158
162
 
159
163
  // fragmentNode cannot change during the lifetime of the component, though fragmentRef may change.
160
- function readFragmentInternal_EXPERIMENTAL(
164
+ function readFragmentInternal(
161
165
  environment: IEnvironment,
162
166
  fragmentNode: ReaderFragment,
163
167
  fragmentRef: mixed,
@@ -295,4 +299,4 @@ function readFragmentInternal_EXPERIMENTAL(
295
299
  return {data, clientEdgeQueries};
296
300
  }
297
301
 
298
- 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?: {
@@ -50,7 +50,7 @@ type NullEntryPointReference = {
50
50
  };
51
51
  const initialNullEntryPointReferenceState = {kind: 'NullEntryPointReference'};
52
52
 
53
- function useLoadEntryPoint<
53
+ hook useLoadEntryPoint<
54
54
  TEntryPointParams: {...},
55
55
  TPreloadedQueries: {...},
56
56
  TPreloadedEntryPoints: {...},
@@ -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,
@@ -13,9 +13,8 @@
13
13
 
14
14
  import type {Fragment, FragmentType, GraphQLTaggedNode} from 'relay-runtime';
15
15
 
16
- const HooksImplementation = require('./HooksImplementation');
17
16
  const {useTrackLoadQueryInRender} = require('./loadQuery');
18
- const useFragmentNode = require('./useFragmentNode');
17
+ const useFragmentInternal = require('./useFragmentInternal');
19
18
  const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
20
19
  const {useDebugValue} = require('react');
21
20
  const {getFragment} = require('relay-runtime');
@@ -26,48 +25,43 @@ type HasSpread<TFragmentType> = {
26
25
  };
27
26
 
28
27
  // if the key is non-nullable, return non-nullable value
29
- declare function useFragment<TFragmentType: FragmentType, TData>(
28
+ declare hook useFragment<TFragmentType: FragmentType, TData>(
30
29
  fragment: Fragment<TFragmentType, TData>,
31
30
  key: HasSpread<TFragmentType>,
32
31
  ): TData;
33
32
 
33
+ // if the key is nullable, return nullable value
34
+ declare hook useFragment<TFragmentType: FragmentType, TData>(
35
+ fragment: Fragment<TFragmentType, TData>,
36
+ key: ?HasSpread<TFragmentType>,
37
+ ): ?TData;
38
+
34
39
  // if the key is a non-nullable array of keys, return non-nullable array
35
- declare function useFragment<TFragmentType: FragmentType, TData>(
40
+ declare hook useFragment<TFragmentType: FragmentType, TData>(
36
41
  fragment: Fragment<TFragmentType, TData>,
37
42
  key: $ReadOnlyArray<HasSpread<TFragmentType>>,
38
43
  ): TData;
39
44
 
40
- // if the key is null/void, return null/void value
41
- declare function useFragment<TFragmentType: FragmentType, TData>(
45
+ // if the key is a nullable array of keys, return nullable array
46
+ declare hook useFragment<TFragmentType: FragmentType, TData>(
42
47
  fragment: Fragment<TFragmentType, TData>,
43
- key: null | void,
44
- ): null | void;
48
+ key: ?$ReadOnlyArray<HasSpread<TFragmentType>>,
49
+ ): ?TData;
45
50
 
46
- function useFragment_LEGACY(fragment: GraphQLTaggedNode, key: mixed): mixed {
51
+ hook useFragment(fragment: GraphQLTaggedNode, key: mixed): mixed {
47
52
  // We need to use this hook in order to be able to track if
48
53
  // loadQuery was called during render
49
54
  useTrackLoadQueryInRender();
50
55
 
51
56
  const fragmentNode = getFragment(fragment);
52
57
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
53
- const {data} = useFragmentNode<mixed>(fragmentNode, key, 'useFragment()');
58
+ const data = useFragmentInternal(fragmentNode, key, 'useFragment()');
54
59
  if (__DEV__) {
55
60
  // eslint-disable-next-line react-hooks/rules-of-hooks
61
+ // $FlowFixMe[react-rule-hook]
56
62
  useDebugValue({fragment: fragmentNode.name, data});
57
63
  }
58
64
  return data;
59
65
  }
60
66
 
61
- function useFragment(fragment: GraphQLTaggedNode, key: mixed): mixed {
62
- const impl = HooksImplementation.get();
63
- if (impl) {
64
- // $FlowFixMe This is safe because impl.useFragment has the type of useFragment...
65
- return impl.useFragment(fragment, key);
66
- // (i.e. type declared above, but not the supertype used in this function definition)
67
- } else {
68
- // eslint-disable-next-line react-hooks/rules-of-hooks
69
- return useFragment_LEGACY(fragment, key);
70
- }
71
- }
72
-
73
67
  module.exports = useFragment;