react-relay 15.0.0 → 16.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayQueryFetcher.js.flow +1 -5
  3. package/ReactRelayQueryRenderer.js.flow +9 -36
  4. package/ReactRelayTypes.js.flow +1 -0
  5. package/buildReactRelayContainer.js.flow +3 -1
  6. package/hooks.js +1 -1
  7. package/index.js +1 -1
  8. package/legacy.js +1 -1
  9. package/lib/ReactRelayContainerUtils.js +0 -11
  10. package/lib/ReactRelayContext.js +0 -11
  11. package/lib/ReactRelayFragmentContainer.js +6 -78
  12. package/lib/ReactRelayFragmentMockRenderer.js +0 -11
  13. package/lib/ReactRelayLocalQueryRenderer.js +0 -17
  14. package/lib/ReactRelayPaginationContainer.js +5 -208
  15. package/lib/ReactRelayQueryFetcher.js +2 -51
  16. package/lib/ReactRelayQueryRenderer.js +6 -94
  17. package/lib/ReactRelayQueryRendererContext.js +0 -11
  18. package/lib/ReactRelayRefetchContainer.js +5 -91
  19. package/lib/ReactRelayTestMocker.js +9 -85
  20. package/lib/ReactRelayTypes.js +0 -11
  21. package/lib/RelayContext.js +0 -21
  22. package/lib/assertFragmentMap.js +0 -15
  23. package/lib/buildReactRelayContainer.js +0 -19
  24. package/lib/getRootVariablesForFragments.js +0 -14
  25. package/lib/hooks.js +0 -15
  26. package/lib/index.js +0 -17
  27. package/lib/isRelayEnvironment.js +1 -18
  28. package/lib/jest-react/enqueueTask.js +0 -20
  29. package/lib/jest-react/internalAct.js +0 -38
  30. package/lib/legacy.js +0 -15
  31. package/lib/multi-actor/ActorChange.js +0 -11
  32. package/lib/multi-actor/index.js +0 -11
  33. package/lib/multi-actor/useRelayActorEnvironment.js +0 -11
  34. package/lib/relay-hooks/EntryPointContainer.react.js +0 -11
  35. package/lib/relay-hooks/EntryPointTypes.flow.js +1 -14
  36. package/lib/relay-hooks/FragmentResource.js +76 -132
  37. package/lib/relay-hooks/HooksImplementation.js +1 -12
  38. package/lib/relay-hooks/InternalLogger.js +0 -11
  39. package/lib/relay-hooks/LRUCache.js +0 -22
  40. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -18
  41. package/lib/relay-hooks/MatchContainer.js +0 -94
  42. package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
  43. package/lib/relay-hooks/ProfilerContext.js +0 -15
  44. package/lib/relay-hooks/QueryResource.js +2 -68
  45. package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -11
  46. package/lib/relay-hooks/SuspenseResource.js +0 -34
  47. package/lib/relay-hooks/{react-cache/readFragmentInternal_REACT_CACHE.js → experimental/readFragmentInternal_EXPERIMENTAL.js} +5 -29
  48. package/lib/relay-hooks/{react-cache/useFragmentInternal_REACT_CACHE.js → experimental/useFragmentInternal_EXPERIMENTAL.js} +35 -100
  49. package/lib/relay-hooks/{react-cache/useFragment_REACT_CACHE.js → experimental/useFragment_EXPERIMENTAL.js} +1 -16
  50. package/lib/relay-hooks/{react-cache/usePaginationFragment_REACT_CACHE.js → experimental/usePaginationFragment_EXPERIMENTAL.js} +2 -24
  51. package/lib/relay-hooks/{react-cache/useRefetchableFragmentInternal_REACT_CACHE.js → experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js} +14 -98
  52. package/lib/relay-hooks/{react-cache/useRefetchableFragment_REACT_CACHE.js → experimental/useRefetchableFragment_EXPERIMENTAL.js} +1 -15
  53. package/lib/relay-hooks/loadEntryPoint.js +1 -24
  54. package/lib/relay-hooks/loadQuery.js +2 -106
  55. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +2 -27
  56. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -13
  57. package/lib/relay-hooks/useBlockingPaginationFragment.js +0 -42
  58. package/lib/relay-hooks/useClientQuery.js +0 -18
  59. package/lib/relay-hooks/useEntryPointLoader.js +0 -69
  60. package/lib/relay-hooks/useFetchTrackingRef.js +0 -26
  61. package/lib/relay-hooks/useFragment.js +0 -17
  62. package/lib/relay-hooks/useFragmentNode.js +2 -32
  63. package/lib/relay-hooks/useIsMountedRef.js +0 -11
  64. package/lib/relay-hooks/useIsOperationNodeActive.js +0 -11
  65. package/lib/relay-hooks/useIsParentQueryActive.js +0 -11
  66. package/lib/relay-hooks/useLazyLoadQuery.js +0 -18
  67. package/lib/relay-hooks/useLazyLoadQueryNode.js +12 -37
  68. package/lib/relay-hooks/useLoadMoreFunction.js +9 -34
  69. package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -11
  70. package/lib/relay-hooks/useMemoVariables.js +0 -17
  71. package/lib/relay-hooks/useMutation.js +0 -11
  72. package/lib/relay-hooks/usePaginationFragment.js +1 -26
  73. package/lib/relay-hooks/usePreloadedQuery.js +0 -27
  74. package/lib/relay-hooks/useQueryLoader.js +0 -74
  75. package/lib/relay-hooks/useRefetchableFragment.js +0 -16
  76. package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -97
  77. package/lib/relay-hooks/useRelayEnvironment.js +0 -11
  78. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -15
  79. package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -25
  80. package/lib/relay-hooks/useSubscription.js +0 -15
  81. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +0 -17
  82. package/package.json +2 -2
  83. package/react-relay-hooks.js +2 -2
  84. package/react-relay-hooks.min.js +2 -2
  85. package/react-relay-legacy.js +2 -2
  86. package/react-relay-legacy.min.js +2 -2
  87. package/react-relay.js +2 -2
  88. package/react-relay.min.js +2 -2
  89. package/relay-hooks/EntryPointContainer.react.js.flow +5 -0
  90. package/relay-hooks/EntryPointTypes.flow.js.flow +34 -35
  91. package/relay-hooks/FragmentResource.js.flow +114 -26
  92. package/relay-hooks/HooksImplementation.js.flow +3 -1
  93. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -2
  94. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
  95. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +7 -5
  96. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +5 -0
  97. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +5 -0
  98. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +2 -0
  99. package/relay-hooks/{react-cache/readFragmentInternal_REACT_CACHE.js.flow → experimental/readFragmentInternal_EXPERIMENTAL.js.flow} +4 -3
  100. package/relay-hooks/{react-cache/useFragmentInternal_REACT_CACHE.js.flow → experimental/useFragmentInternal_EXPERIMENTAL.js.flow} +32 -14
  101. package/relay-hooks/{react-cache/useFragment_REACT_CACHE.js.flow → experimental/useFragment_EXPERIMENTAL.js.flow} +4 -10
  102. package/relay-hooks/{react-cache/usePaginationFragment_REACT_CACHE.js.flow → experimental/usePaginationFragment_EXPERIMENTAL.js.flow} +30 -59
  103. package/relay-hooks/{react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow → experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow} +30 -23
  104. package/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js.flow +49 -0
  105. package/relay-hooks/loadEntryPoint.js.flow +4 -2
  106. package/relay-hooks/loadQuery.js.flow +21 -1
  107. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -2
  108. package/relay-hooks/useBlockingPaginationFragment.js.flow +10 -17
  109. package/relay-hooks/useClientQuery.js.flow +2 -2
  110. package/relay-hooks/useFragmentNode.js.flow +2 -2
  111. package/relay-hooks/useLazyLoadQueryNode.js.flow +17 -1
  112. package/relay-hooks/useLoadMoreFunction.js.flow +15 -9
  113. package/relay-hooks/useMutation.js.flow +26 -9
  114. package/relay-hooks/usePaginationFragment.js.flow +7 -15
  115. package/relay-hooks/useQueryLoader.js.flow +2 -8
  116. package/relay-hooks/useRefetchableFragment.js.flow +14 -16
  117. package/relay-hooks/useRefetchableFragmentNode.js.flow +33 -20
  118. package/lib/relay-hooks/react-cache/RelayReactCache.js +0 -32
  119. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +0 -290
  120. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +0 -49
  121. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +0 -110
  122. package/relay-hooks/react-cache/RelayReactCache.js.flow +0 -40
  123. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +0 -430
  124. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +0 -70
  125. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +0 -150
  126. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +0 -65
@@ -12,15 +12,16 @@
12
12
  'use strict';
13
13
 
14
14
  import type {
15
+ CommitMutationConfig,
15
16
  DeclarativeMutationConfig,
16
17
  Disposable,
17
- GraphQLTaggedNode,
18
18
  IEnvironment,
19
- MutationConfig,
19
+ Mutation,
20
20
  MutationParameters,
21
21
  PayloadError,
22
22
  SelectorStoreUpdater,
23
23
  UploadableMap,
24
+ Variables,
24
25
  } from 'relay-runtime';
25
26
 
26
27
  const useIsMountedRef = require('./useIsMountedRef');
@@ -50,13 +51,29 @@ export type UseMutationConfig<TMutation: MutationParameters> = {
50
51
  variables: TMutation['variables'],
51
52
  };
52
53
 
53
- function useMutation<TMutation: MutationParameters>(
54
- mutation: GraphQLTaggedNode,
54
+ type UseMutationConfigInternal<TVariables, TData, TRawResponse> = {
55
+ configs?: Array<DeclarativeMutationConfig>,
56
+ onError?: ?(error: Error) => void,
57
+ onCompleted?: ?(response: TData, errors: ?Array<PayloadError>) => void,
58
+ onNext?: ?() => void,
59
+ onUnsubscribe?: ?() => void,
60
+ optimisticResponse?: TRawResponse,
61
+ optimisticUpdater?: ?SelectorStoreUpdater<TData>,
62
+ updater?: ?SelectorStoreUpdater<TData>,
63
+ uploadables?: UploadableMap,
64
+ variables: TVariables,
65
+ };
66
+
67
+ function useMutation<TVariables: Variables, TData, TRawResponse = {...}>(
68
+ mutation: Mutation<TVariables, TData, TRawResponse>,
55
69
  commitMutationFn?: (
56
70
  environment: IEnvironment,
57
- config: MutationConfig<TMutation>,
71
+ config: CommitMutationConfig<TVariables, TData, TRawResponse>,
58
72
  ) => Disposable = defaultCommitMutation,
59
- ): [(UseMutationConfig<TMutation>) => Disposable, boolean] {
73
+ ): [
74
+ (UseMutationConfigInternal<TVariables, TData, TRawResponse>) => Disposable,
75
+ boolean,
76
+ ] {
60
77
  const environment = useRelayEnvironment();
61
78
  const isMountedRef = useIsMountedRef();
62
79
  const environmentRef = useRef(environment);
@@ -94,18 +111,18 @@ function useMutation<TMutation: MutationParameters>(
94
111
  }, [environment, isMountedRef, mutation]);
95
112
 
96
113
  const commit = useCallback(
97
- (config: UseMutationConfig<TMutation>) => {
114
+ (config: UseMutationConfigInternal<TVariables, TData, TRawResponse>) => {
98
115
  if (isMountedRef.current) {
99
116
  setMutationInFlight(true);
100
117
  }
101
118
  const disposable: Disposable = commitMutationFn(environment, {
102
119
  ...config,
103
120
  mutation,
104
- onCompleted: (response, errors) => {
121
+ onCompleted: (response: TData, errors: ?Array<PayloadError>) => {
105
122
  cleanup(disposable);
106
123
  config.onCompleted?.(response, errors);
107
124
  },
108
- onError: error => {
125
+ onError: (error: Error) => {
109
126
  cleanup(disposable);
110
127
  config.onError?.(error);
111
128
  },
@@ -62,12 +62,8 @@ function usePaginationFragment_LEGACY<
62
62
  );
63
63
  const componentDisplayName = 'usePaginationFragment()';
64
64
 
65
- const {
66
- connectionPathInFragmentData,
67
- paginationRequest,
68
- paginationMetadata,
69
- identifierField,
70
- } = getPaginationMetadata(fragmentNode, componentDisplayName);
65
+ const {connectionPathInFragmentData, paginationRequest, paginationMetadata} =
66
+ getPaginationMetadata(fragmentNode, componentDisplayName);
71
67
 
72
68
  const {fragmentData, fragmentRef, refetch} = useRefetchableFragmentNode<
73
69
  $FlowFixMe,
@@ -85,7 +81,6 @@ function usePaginationFragment_LEGACY<
85
81
  fragmentIdentifier,
86
82
  fragmentNode,
87
83
  fragmentRef,
88
- identifierField,
89
84
  paginationMetadata,
90
85
  paginationRequest,
91
86
  });
@@ -100,7 +95,6 @@ function usePaginationFragment_LEGACY<
100
95
  fragmentIdentifier,
101
96
  fragmentNode,
102
97
  fragmentRef,
103
- identifierField,
104
98
  paginationMetadata,
105
99
  paginationRequest,
106
100
  });
@@ -163,15 +157,12 @@ function useLoadMore<TVariables: Variables>(
163
157
  }
164
158
 
165
159
  export type ReturnType<TVariables, TData, TKey> = {
166
- // NOTE: This $Call ensures that the type of the returned data is either:
160
+ // NOTE: This type ensures that the type of the returned data is either:
167
161
  // - nullable if the provided ref type is nullable
168
162
  // - non-nullable if the provided ref type is non-nullable
169
- // prettier-ignore
170
- data: $Call<
171
- & (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
172
- & (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
173
- TKey,
174
- >,
163
+ data: [+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}]
164
+ ? TData
165
+ : ?TData,
175
166
  loadNext: LoadMoreFn<TVariables>,
176
167
  loadPrevious: LoadMoreFn<TVariables>,
177
168
  hasNext: boolean,
@@ -192,6 +183,7 @@ function usePaginationFragment<
192
183
  ): ReturnType<TVariables, TData, TKey> {
193
184
  const impl = HooksImplementation.get();
194
185
  if (impl) {
186
+ // $FlowExpectedError[incompatible-return] Flow cannot prove that two conditional type satisfy each other
195
187
  return impl.usePaginationFragment<TFragmentType, TVariables, TData, TKey>(
196
188
  fragmentInput,
197
189
  parentFragmentRef,
@@ -82,9 +82,6 @@ type UseQueryLoaderHookReturnType<
82
82
  () => void,
83
83
  ];
84
84
 
85
- type ExtractVariablesType = <T>({+variables: T, ...}) => T;
86
- type ExtractResponseType = <T>({+response: T, ...}) => T;
87
-
88
85
  declare function useQueryLoader<
89
86
  TVariables: Variables,
90
87
  TData,
@@ -109,10 +106,7 @@ declare function useQueryLoader<
109
106
  declare function useQueryLoader<TQuery: OperationType>(
110
107
  preloadableRequest: PreloadableConcreteRequest<TQuery>,
111
108
  initialQueryReference?: ?PreloadedQuery<TQuery>,
112
- ): UseQueryLoaderHookReturnType<
113
- $Call<ExtractVariablesType, TQuery>,
114
- $Call<ExtractResponseType, TQuery>,
115
- >;
109
+ ): UseQueryLoaderHookReturnType<TQuery['variables'], TQuery['response']>;
116
110
 
117
111
  function useQueryLoader<
118
112
  TVariables: Variables,
@@ -201,7 +195,7 @@ function useQueryLoader<
201
195
  }
202
196
  : options;
203
197
  if (isMountedRef.current) {
204
- const updatedQueryReference = loadQuery<QueryType>(
198
+ const updatedQueryReference = loadQuery(
205
199
  options?.__environment ?? environment,
206
200
  preloadableRequest,
207
201
  variables,
@@ -25,16 +25,13 @@ const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
25
25
  const {useDebugValue} = require('react');
26
26
  const {getFragment} = require('relay-runtime');
27
27
 
28
- type RefetchVariables<TVariables, TKey> =
29
- // NOTE: This $Call ensures that the type of the returned variables is either:
28
+ type RefetchVariables<TVariables, TKey: ?{+$fragmentSpreads: mixed, ...}> =
29
+ // NOTE: This type ensures that the type of the returned variables is either:
30
30
  // - nullable if the provided ref type is nullable
31
31
  // - non-nullable if the provided ref type is non-nullable
32
- // prettier-ignore
33
- $Call<
34
- & (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => $Shape<TVariables>)
35
- & (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => TVariables),
36
- TKey,
37
- >;
32
+ [+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}]
33
+ ? Partial<TVariables>
34
+ : TVariables;
38
35
 
39
36
  type RefetchFnBase<TVars, TOptions> = (
40
37
  vars: TVars,
@@ -46,16 +43,15 @@ export type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
46
43
  TOptions,
47
44
  >;
48
45
 
49
- type ReturnType<TVariables, TData, TKey> = [
50
- // NOTE: This $Call ensures that the type of the returned data is either:
46
+ export type ReturnType<
47
+ TVariables,
48
+ TData,
49
+ TKey: ?{+$fragmentSpreads: mixed, ...},
50
+ > = [
51
+ // NOTE: This type ensures that the type of the returned data is either:
51
52
  // - nullable if the provided ref type is nullable
52
53
  // - non-nullable if the provided ref type is non-nullable
53
- // prettier-ignore
54
- $Call<
55
- & (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
56
- & (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
57
- TKey,
58
- >,
54
+ [+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}] ? TData : ?TData,
59
55
  RefetchFn<TVariables, TKey>,
60
56
  ];
61
57
 
@@ -100,6 +96,7 @@ function useRefetchableFragment_LEGACY<
100
96
 
101
97
  // $FlowFixMe[incompatible-return]
102
98
  // $FlowFixMe[prop-missing]
99
+ // $FlowFixMe[incompatible-variance]
103
100
  return [fragmentData, refetch];
104
101
  }
105
102
 
@@ -114,6 +111,7 @@ function useRefetchableFragment<
114
111
  ): ReturnType<TVariables, TData, TKey> {
115
112
  const impl = HooksImplementation.get();
116
113
  if (impl) {
114
+ // $FlowExpectedError[incompatible-return] Flow cannot prove that two conditional type satisfy each other
117
115
  return impl.useRefetchableFragment<TFragmentType, TVariables, TData, TKey>(
118
116
  fragmentInput,
119
117
  parentFragmentRef,
@@ -11,6 +11,7 @@
11
11
 
12
12
  'use strict';
13
13
 
14
+ import type {RefetchableIdentifierInfo} from '../../relay-runtime/util/ReaderNode';
14
15
  import type {LoaderFn} from './useQueryLoader';
15
16
  import type {
16
17
  ConcreteRequest,
@@ -54,16 +55,13 @@ export type RefetchFn<
54
55
  // /nullable/.
55
56
  // - Or, expects /a subset/ of the query variables if the provided key type is
56
57
  // /non-null/.
57
- // prettier-ignore
58
58
  export type RefetchFnDynamic<
59
59
  TQuery: OperationType,
60
- TKey: ?{ +$data?: mixed, ... },
60
+ TKey: ?{+$data?: mixed, ...},
61
61
  TOptions = Options,
62
- > = $Call<
63
- & (( { +$data?: mixed, ... }) => RefetchFnInexact<TQuery, TOptions>)
64
- & ((?{ +$data?: mixed, ... }) => RefetchFnExact<TQuery, TOptions>),
65
- TKey
66
- >;
62
+ > = [TKey] extends [{+$data?: mixed, ...}]
63
+ ? RefetchFnInexact<TQuery, TOptions>
64
+ : RefetchFnExact<TQuery, TOptions>;
67
65
 
68
66
  export type ReturnType<
69
67
  TQuery: OperationType,
@@ -100,7 +98,7 @@ type RefetchFnExact<TQuery: OperationType, TOptions = Options> = RefetchFnBase<
100
98
  type RefetchFnInexact<
101
99
  TQuery: OperationType,
102
100
  TOptions = Options,
103
- > = RefetchFnBase<$Shape<VariablesOf<TQuery>>, TOptions>;
101
+ > = RefetchFnBase<Partial<VariablesOf<TQuery>>, TOptions>;
104
102
 
105
103
  type Action =
106
104
  | {
@@ -173,8 +171,10 @@ function useRefetchableFragmentNode<
173
171
  componentDisplayName: string,
174
172
  ): ReturnType<TQuery, TKey, InternalOptions> {
175
173
  const parentEnvironment = useRelayEnvironment();
176
- const {refetchableRequest, fragmentRefPathInResponse, identifierField} =
177
- getRefetchMetadata(fragmentNode, componentDisplayName);
174
+ const {refetchableRequest, fragmentRefPathInResponse} = getRefetchMetadata(
175
+ fragmentNode,
176
+ componentDisplayName,
177
+ );
178
178
  const fragmentIdentifier = getFragmentIdentifier(
179
179
  fragmentNode,
180
180
  parentFragmentRef,
@@ -214,6 +214,12 @@ function useRefetchableFragmentNode<
214
214
  >((refetchableRequest: $FlowFixMe));
215
215
 
216
216
  let fragmentRef = parentFragmentRef;
217
+
218
+ const {identifierInfo} = getRefetchMetadata(
219
+ fragmentNode,
220
+ componentDisplayName,
221
+ );
222
+
217
223
  if (shouldReset) {
218
224
  dispatch({
219
225
  type: 'reset',
@@ -239,6 +245,7 @@ function useRefetchableFragmentNode<
239
245
  debugPreviousIDAndTypename = debugFunctions.getInitialIDAndType(
240
246
  refetchQuery.request.variables,
241
247
  fragmentRefPathInResponse,
248
+ identifierInfo?.identifierQueryVariableName,
242
249
  environment,
243
250
  );
244
251
  }
@@ -345,7 +352,7 @@ function useRefetchableFragmentNode<
345
352
  fragmentIdentifier,
346
353
  fragmentNode,
347
354
  fragmentRefPathInResponse,
348
- identifierField,
355
+ identifierInfo,
349
356
  loadQuery,
350
357
  parentFragmentRef,
351
358
  refetchableRequest,
@@ -353,6 +360,7 @@ function useRefetchableFragmentNode<
353
360
  return {
354
361
  fragmentData,
355
362
  fragmentRef,
363
+ // $FlowFixMe[incompatible-return] RefetchFn not compatible with RefetchFnDynamic
356
364
  refetch,
357
365
  disableStoreUpdates,
358
366
  enableStoreUpdates,
@@ -381,17 +389,17 @@ function useRefetchFunction<TQuery: OperationType>(
381
389
  fragmentIdentifier: string,
382
390
  fragmentNode: ReaderFragment,
383
391
  fragmentRefPathInResponse: $ReadOnlyArray<string | number>,
384
- identifierField: ?string,
392
+ identifierInfo: ?RefetchableIdentifierInfo,
385
393
  loadQuery: LoaderFn<TQuery>,
386
394
  parentFragmentRef: mixed,
387
395
  refetchableRequest: ConcreteRequest,
388
396
  ): RefetchFn<TQuery, InternalOptions> {
389
397
  const isMountedRef = useIsMountedRef();
390
398
  const identifierValue =
391
- identifierField != null &&
399
+ identifierInfo?.identifierField != null &&
392
400
  fragmentData != null &&
393
401
  typeof fragmentData === 'object'
394
- ? fragmentData[identifierField]
402
+ ? fragmentData[identifierInfo.identifierField]
395
403
  : null;
396
404
  return useCallback(
397
405
  (
@@ -458,8 +466,10 @@ function useRefetchFunction<TQuery: OperationType>(
458
466
  // If the query needs an identifier value ('id' or similar) and one
459
467
  // was not explicitly provided, read it from the fragment data.
460
468
  if (
461
- identifierField != null &&
462
- !providedRefetchVariables.hasOwnProperty('id')
469
+ identifierInfo != null &&
470
+ !providedRefetchVariables.hasOwnProperty(
471
+ identifierInfo.identifierQueryVariableName,
472
+ )
463
473
  ) {
464
474
  // @refetchable fragments are guaranteed to have an `id` selection
465
475
  // if the type is Node, implements Node, or is @fetchable. Double-check
@@ -469,11 +479,13 @@ function useRefetchFunction<TQuery: OperationType>(
469
479
  false,
470
480
  'Relay: Expected result to have a string ' +
471
481
  '`%s` in order to refetch, got `%s`.',
472
- identifierField,
482
+ identifierInfo.identifierField,
473
483
  identifierValue,
474
484
  );
475
485
  }
476
- (refetchVariables: $FlowFixMe).id = identifierValue;
486
+ (refetchVariables: $FlowFixMe)[
487
+ identifierInfo.identifierQueryVariableName
488
+ ] = identifierValue;
477
489
  }
478
490
 
479
491
  const refetchQuery = createOperationDescriptor(
@@ -522,10 +534,11 @@ if (__DEV__) {
522
534
  getInitialIDAndType(
523
535
  memoRefetchVariables: ?Variables,
524
536
  fragmentRefPathInResponse: $ReadOnlyArray<string | number>,
537
+ identifierQueryVariableName: ?string,
525
538
  environment: IEnvironment,
526
539
  ): ?DebugIDandTypename {
527
540
  const {Record} = require('relay-runtime');
528
- const id = memoRefetchVariables?.id;
541
+ const id = memoRefetchVariables?.[identifierQueryVariableName ?? 'id'];
529
542
  if (
530
543
  fragmentRefPathInResponse.length !== 1 ||
531
544
  fragmentRefPathInResponse[0] !== 'node' ||
@@ -535,7 +548,7 @@ if (__DEV__) {
535
548
  }
536
549
  const recordSource = environment.getStore().getSource();
537
550
  const record = recordSource.get(id);
538
- const typename = record && Record.getType(record);
551
+ const typename = record == null ? null : Record.getType(record);
539
552
  if (typename == null) {
540
553
  return null;
541
554
  }
@@ -1,32 +0,0 @@
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
- *
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
- 'use strict';
13
-
14
- var invariant = require('invariant');
15
- // $FlowFixMe[prop-missing] These exist in experimental builds but aren't in React's types yet.
16
- var _require = require('react'),
17
- unstable_getCacheForType = _require.unstable_getCacheForType,
18
- unstable_getCacheSignal = _require.unstable_getCacheSignal;
19
- var _require2 = require('relay-runtime'),
20
- RelayFeatureFlags = _require2.RelayFeatureFlags;
21
- function getCacheForType(factory) {
22
- !(typeof unstable_getCacheForType === 'function' && RelayFeatureFlags.USE_REACT_CACHE) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReactCache.getCacheForType should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.') : invariant(false) : void 0;
23
- return unstable_getCacheForType(factory);
24
- }
25
- function getCacheSignal() {
26
- !(typeof unstable_getCacheSignal === 'function' && RelayFeatureFlags.USE_REACT_CACHE) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReactCache.getCacheSignal should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.') : invariant(false) : void 0;
27
- return unstable_getCacheSignal();
28
- }
29
- module.exports = {
30
- getCacheForType: getCacheForType,
31
- getCacheSignal: getCacheSignal
32
- };