react-relay 17.0.0 → 18.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +2 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -1
- package/ReactRelayFragmentContainer.js.flow +2 -2
- package/ReactRelayPaginationContainer.js.flow +2 -2
- package/ReactRelayQueryRenderer.js.flow +1 -1
- package/ReactRelayQueryRendererContext.js.flow +1 -1
- package/ReactRelayRefetchContainer.js.flow +2 -2
- package/ReactRelayTypes.js.flow +45 -18
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -2
- package/buildReactRelayContainer.js.flow +5 -5
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/relay-hooks/loadEntryPoint.js +8 -5
- package/lib/relay-hooks/loadQuery.js +2 -14
- package/lib/relay-hooks/useEntryPointLoader.js +5 -8
- package/lib/relay-hooks/useFragment.js +4 -7
- package/lib/relay-hooks/useFragmentInternal.js +6 -484
- package/lib/relay-hooks/useFragmentInternal_CURRENT.js +483 -0
- package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +520 -0
- package/lib/relay-hooks/useLazyLoadQuery.js +2 -5
- package/lib/relay-hooks/usePreloadedQuery.js +6 -9
- package/lib/relay-hooks/useQueryLoader.js +1 -3
- package/multi-actor/ActorChange.js.flow +1 -1
- package/package.json +3 -3
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +1 -1
- package/react-relay-legacy.min.js +1 -1
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointTypes.flow.js.flow +35 -12
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +8 -4
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +43 -0
- package/relay-hooks/loadEntryPoint.js.flow +10 -4
- package/relay-hooks/loadQuery.js.flow +4 -28
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -1
- package/relay-hooks/useEntryPointLoader.js.flow +3 -4
- package/relay-hooks/useFragment.js.flow +0 -5
- package/relay-hooks/useFragmentInternal.js.flow +19 -643
- package/relay-hooks/useFragmentInternal_CURRENT.js.flow +669 -0
- package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +764 -0
- package/relay-hooks/useLazyLoadQuery.js.flow +0 -5
- package/relay-hooks/usePaginationFragment.js.flow +1 -1
- package/relay-hooks/usePreloadedQuery.js.flow +0 -5
- package/relay-hooks/useQueryLoader.js.flow +1 -2
@@ -11,11 +11,11 @@
|
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
function getComponentName(component: React
|
14
|
+
function getComponentName(component: React.ComponentType<any>): string {
|
15
15
|
return component.displayName || component.name || 'Component';
|
16
16
|
}
|
17
17
|
|
18
|
-
function getContainerName(Component: React
|
18
|
+
function getContainerName(Component: React.ComponentType<any>): string {
|
19
19
|
return 'Relay(' + getComponentName(Component) + ')';
|
20
20
|
}
|
21
21
|
|
package/ReactRelayContext.js
CHANGED
@@ -51,7 +51,7 @@ function createContainerWithFragments<
|
|
51
51
|
Component: TComponent,
|
52
52
|
fragments: FragmentMap,
|
53
53
|
): React.ComponentType<
|
54
|
-
$RelayProps<React
|
54
|
+
$RelayProps<React.ElementConfig<TComponent>, RelayProp>,
|
55
55
|
> {
|
56
56
|
const containerName = getContainerName(Component);
|
57
57
|
|
@@ -275,7 +275,7 @@ function createContainer<
|
|
275
275
|
Component: TComponent,
|
276
276
|
fragmentSpec: GeneratedNodeMap,
|
277
277
|
): React.AbstractComponent<
|
278
|
-
$RelayProps<React
|
278
|
+
$RelayProps<React.ElementConfig<TComponent>, RelayProp>,
|
279
279
|
Instance,
|
280
280
|
> {
|
281
281
|
// $FlowFixMe[incompatible-return]
|
@@ -325,7 +325,7 @@ function createContainerWithFragments<
|
|
325
325
|
fragments: FragmentMap,
|
326
326
|
connectionConfig: ConnectionConfig,
|
327
327
|
): React.ComponentType<
|
328
|
-
$RelayProps<React
|
328
|
+
$RelayProps<React.ElementConfig<TComponent>, RelayPaginationProp>,
|
329
329
|
> {
|
330
330
|
const componentName = getComponentName(Component);
|
331
331
|
const containerName = getContainerName(Component);
|
@@ -942,7 +942,7 @@ function createContainer<Props: {...}, TComponent: React.ComponentType<Props>>(
|
|
942
942
|
fragmentSpec: GeneratedNodeMap,
|
943
943
|
connectionConfig: ConnectionConfig,
|
944
944
|
): React.ComponentType<
|
945
|
-
$RelayProps<React
|
945
|
+
$RelayProps<React.ElementConfig<TComponent>, RelayPaginationProp>,
|
946
946
|
> {
|
947
947
|
// $FlowFixMe[incompatible-return]
|
948
948
|
return buildReactRelayContainer(
|
@@ -263,7 +263,7 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
|
|
263
263
|
});
|
264
264
|
};
|
265
265
|
|
266
|
-
render(): React.
|
266
|
+
render(): React.MixedElement {
|
267
267
|
const {renderProps, relayContext} = this.state;
|
268
268
|
// Note that the root fragment results in `renderProps.props` is already
|
269
269
|
// frozen by the store; this call is to freeze the renderProps object and
|
@@ -16,4 +16,4 @@ export type ReactRelayQueryRendererContext = {rootIsQueryRenderer: boolean};
|
|
16
16
|
|
17
17
|
module.exports = (React.createContext({
|
18
18
|
rootIsQueryRenderer: false,
|
19
|
-
}): React
|
19
|
+
}): React.Context<ReactRelayQueryRendererContext | null>);
|
@@ -75,7 +75,7 @@ function createContainerWithFragments<
|
|
75
75
|
fragments: FragmentMap,
|
76
76
|
taggedNode: GraphQLTaggedNode,
|
77
77
|
): React.ComponentType<
|
78
|
-
$RelayProps<React
|
78
|
+
$RelayProps<React.ElementConfig<TComponent>, RelayRefetchProp>,
|
79
79
|
> {
|
80
80
|
const containerName = getContainerName(Component);
|
81
81
|
|
@@ -491,7 +491,7 @@ function createContainer<Props: {...}, TComponent: React.ComponentType<Props>>(
|
|
491
491
|
fragmentSpec: GeneratedNodeMap,
|
492
492
|
taggedNode: GraphQLTaggedNode,
|
493
493
|
): React.ComponentType<
|
494
|
-
$RelayProps<React
|
494
|
+
$RelayProps<React.ElementConfig<TComponent>, RelayRefetchProp>,
|
495
495
|
> {
|
496
496
|
// $FlowFixMe[incompatible-return]
|
497
497
|
return buildReactRelayContainer(
|
package/ReactRelayTypes.js.flow
CHANGED
@@ -103,28 +103,55 @@ export type $FragmentRef<T> = {
|
|
103
103
|
*/
|
104
104
|
// prettier-ignore
|
105
105
|
// $FlowFixMe[extra-type-arg] xplat redux flow type error
|
106
|
-
|
107
|
-
|
108
|
-
$Diff<Props, { relay: RelayPropT | void, ... }>,
|
109
|
-
& (<T: { +$fragmentType: empty, ... }>( T) => T)
|
110
|
-
& (<T: { +$fragmentType: empty, ... }>(?T) => ?T)
|
111
|
-
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( T ) => $FragmentRef<T> )
|
112
|
-
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(? T ) => ? $FragmentRef<T> )
|
113
|
-
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( $ReadOnlyArray< T>) => $ReadOnlyArray< $FragmentRef<T>>)
|
114
|
-
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(?$ReadOnlyArray< T>) => ?$ReadOnlyArray< $FragmentRef<T>>)
|
115
|
-
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( $ReadOnlyArray<?T>) => $ReadOnlyArray<?$FragmentRef<T>>)
|
116
|
-
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(?$ReadOnlyArray<?T>) => ?$ReadOnlyArray<?$FragmentRef<T>>)
|
117
|
-
& (<T>(T) => T),
|
106
|
+
export type $RelayProps<Props, RelayPropT = RelayProp> = MapRelayProps<
|
107
|
+
$Diff<Props, {relay: RelayPropT | void, ...}>,
|
118
108
|
>;
|
119
109
|
|
120
|
-
|
121
|
-
|
110
|
+
type MapRelayProps<Props> = {[K in keyof Props]: MapRelayProp<Props[K]>};
|
111
|
+
type MapRelayProp<T> = [+t: T] extends [+t: {+$fragmentType: empty, ...}]
|
112
|
+
? T
|
113
|
+
: [+t: T] extends [+t: ?{+$fragmentType: empty, ...}]
|
114
|
+
? ?T
|
115
|
+
: [+t: T] extends [+t: {+$fragmentType: FragmentType, ...}]
|
116
|
+
? $FragmentRef<T>
|
117
|
+
: [+t: T] extends [+t: ?{+$fragmentType: FragmentType, ...}]
|
118
|
+
? ?$FragmentRef<$NonMaybeType<T>>
|
119
|
+
: [+t: T] extends [
|
120
|
+
+t: $ReadOnlyArray<
|
121
|
+
infer V extends {+$fragmentType: FragmentType, ...},
|
122
|
+
>,
|
123
|
+
]
|
124
|
+
? $ReadOnlyArray<$FragmentRef<V>>
|
125
|
+
: [+t: T] extends [
|
126
|
+
+t: ?$ReadOnlyArray<
|
127
|
+
infer V extends {+$fragmentType: FragmentType, ...},
|
128
|
+
>,
|
129
|
+
]
|
130
|
+
? ?$ReadOnlyArray<$FragmentRef<V>>
|
131
|
+
: [+t: T] extends [
|
132
|
+
+t: $ReadOnlyArray<?infer V extends {
|
133
|
+
+$fragmentType: FragmentType,
|
134
|
+
...
|
135
|
+
}>,
|
136
|
+
]
|
137
|
+
? $ReadOnlyArray<?$FragmentRef<$NonMaybeType<V>>>
|
138
|
+
: [+t: T] extends [
|
139
|
+
+t: ?$ReadOnlyArray<?infer V extends {
|
140
|
+
+$fragmentType: FragmentType,
|
141
|
+
...
|
142
|
+
}>,
|
143
|
+
]
|
144
|
+
? ?$ReadOnlyArray<?$FragmentRef<$NonMaybeType<V>>>
|
145
|
+
: T;
|
146
|
+
|
147
|
+
export type RelayFragmentContainer<TComponent> = React.ComponentType<
|
148
|
+
$RelayProps<React.ElementConfig<TComponent>, RelayProp>,
|
122
149
|
>;
|
123
150
|
|
124
|
-
export type RelayPaginationContainer<TComponent> = React
|
125
|
-
$RelayProps<React
|
151
|
+
export type RelayPaginationContainer<TComponent> = React.ComponentType<
|
152
|
+
$RelayProps<React.ElementConfig<TComponent>, RelayPaginationProp>,
|
126
153
|
>;
|
127
154
|
|
128
|
-
export type RelayRefetchContainer<TComponent> = React
|
129
|
-
$RelayProps<React
|
155
|
+
export type RelayRefetchContainer<TComponent> = React.ComponentType<
|
156
|
+
$RelayProps<React.ElementConfig<TComponent>, RelayRefetchProp>,
|
130
157
|
>;
|
@@ -50,7 +50,7 @@ class BarComponent extends React.Component<{
|
|
50
50
|
getNum(): number {
|
51
51
|
return 42;
|
52
52
|
}
|
53
|
-
render(): React.
|
53
|
+
render(): React.MixedElement {
|
54
54
|
const reqLen = this.props.requiredProp.length;
|
55
55
|
const optionalProp = this.props.optionalProp;
|
56
56
|
|
@@ -137,7 +137,7 @@ module.exports = {
|
|
137
137
|
/** $FlowExpectedError: Bar `getNum` gives number, but `getString` assumes string **/
|
138
138
|
return bad ? 'not good' : ok;
|
139
139
|
}
|
140
|
-
render(): React.
|
140
|
+
render(): React.MixedElement {
|
141
141
|
return (
|
142
142
|
<Bar
|
143
143
|
componentRef={(ref: empty) => {
|
@@ -28,15 +28,15 @@ const {getFragment} = require('relay-runtime');
|
|
28
28
|
const {useContext} = React;
|
29
29
|
|
30
30
|
type ContainerCreator = (
|
31
|
-
Component: React
|
31
|
+
Component: React.ComponentType<any>,
|
32
32
|
fragments: FragmentMap,
|
33
|
-
) => React
|
33
|
+
) => React.ComponentType<any>;
|
34
34
|
|
35
35
|
/**
|
36
36
|
* Helper to create the Relay HOCs with ref forwarding, setting the displayName
|
37
37
|
* and reading the React context.
|
38
38
|
*/
|
39
|
-
function buildReactRelayContainer<TBase: React
|
39
|
+
function buildReactRelayContainer<TBase: React.ComponentType<any>>(
|
40
40
|
ComponentClass: TBase,
|
41
41
|
fragmentSpec: GeneratedNodeMap,
|
42
42
|
createContainerWithFragments: ContainerCreator,
|
@@ -55,8 +55,8 @@ function buildReactRelayContainer<TBase: React$ComponentType<any>>(
|
|
55
55
|
function ForwardRef(
|
56
56
|
props: any,
|
57
57
|
ref:
|
58
|
-
| ((null | React
|
59
|
-
| {-current: null | React
|
58
|
+
| ((null | React.ElementRef<TBase>) => mixed)
|
59
|
+
| {-current: null | React.ElementRef<TBase>, ...},
|
60
60
|
) {
|
61
61
|
// $FlowFixMe[react-rule-hook]
|
62
62
|
const context = useContext(ReactRelayContext);
|
package/hooks.js
CHANGED
package/index.js
CHANGED
package/legacy.js
CHANGED
@@ -16,11 +16,14 @@ function loadEntryPoint(environmentProvider, entryPoint, entryPointParams) {
|
|
16
16
|
if (queries != null) {
|
17
17
|
var queriesPropNames = Object.keys(queries);
|
18
18
|
queriesPropNames.forEach(function (queryPropName) {
|
19
|
-
var
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
var query = queries[queryPropName];
|
20
|
+
if (query == null) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
var environmentProviderOptions = query.environmentProviderOptions,
|
24
|
+
options = query.options,
|
25
|
+
parameters = query.parameters,
|
26
|
+
variables = query.variables;
|
24
27
|
var environment = environmentProvider.getEnvironment(environmentProviderOptions);
|
25
28
|
preloadedQueries[queryPropName] = loadQuery(environment, parameters, variables, {
|
26
29
|
fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
|
@@ -3,7 +3,6 @@
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
4
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
5
5
|
var invariant = require('invariant');
|
6
|
-
var React = require('react');
|
7
6
|
var _require = require('relay-runtime'),
|
8
7
|
fetchQueryDeduped = _require.__internal.fetchQueryDeduped,
|
9
8
|
Observable = _require.Observable,
|
@@ -13,19 +12,9 @@ var _require = require('relay-runtime'),
|
|
13
12
|
createOperationDescriptor = _require.createOperationDescriptor,
|
14
13
|
getRequest = _require.getRequest,
|
15
14
|
getRequestIdentifier = _require.getRequestIdentifier;
|
16
|
-
var warning = require("fbjs/lib/warning");
|
17
|
-
var RenderDispatcher = null;
|
18
15
|
var fetchKey = 100001;
|
19
|
-
function useTrackLoadQueryInRender() {
|
20
|
-
if (RenderDispatcher === null) {
|
21
|
-
var _React$__SECRET_INTER, _React$__SECRET_INTER2;
|
22
|
-
RenderDispatcher = (_React$__SECRET_INTER = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _React$__SECRET_INTER === void 0 ? void 0 : (_React$__SECRET_INTER2 = _React$__SECRET_INTER.ReactCurrentDispatcher) === null || _React$__SECRET_INTER2 === void 0 ? void 0 : _React$__SECRET_INTER2.current;
|
23
|
-
}
|
24
|
-
}
|
25
16
|
function loadQuery(environment, preloadableRequest, variables, options, environmentProviderOptions) {
|
26
|
-
var
|
27
|
-
var CurrentDispatcher = (_React$__SECRET_INTER3 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _React$__SECRET_INTER3 === void 0 ? void 0 : (_React$__SECRET_INTER4 = _React$__SECRET_INTER3.ReactCurrentDispatcher) === null || _React$__SECRET_INTER4 === void 0 ? void 0 : _React$__SECRET_INTER4.current;
|
28
|
-
process.env.NODE_ENV !== "production" ? warning(RenderDispatcher == null || CurrentDispatcher !== RenderDispatcher, 'Relay: `%s` should not be called inside a React render function.', (_options$__nameForWar = options === null || options === void 0 ? void 0 : options.__nameForWarning) !== null && _options$__nameForWar !== void 0 ? _options$__nameForWar : 'loadQuery') : void 0;
|
17
|
+
var _options$fetchPolicy;
|
29
18
|
fetchKey++;
|
30
19
|
var fetchPolicy = (_options$fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy) !== null && _options$fetchPolicy !== void 0 ? _options$fetchPolicy : 'store-or-network';
|
31
20
|
var networkCacheConfig = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options === null || options === void 0 ? void 0 : options.networkCacheConfig), {}, {
|
@@ -201,6 +190,5 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
|
|
201
190
|
};
|
202
191
|
}
|
203
192
|
module.exports = {
|
204
|
-
loadQuery: loadQuery
|
205
|
-
useTrackLoadQueryInRender: useTrackLoadQueryInRender
|
193
|
+
loadQuery: loadQuery
|
206
194
|
};
|
@@ -3,20 +3,17 @@
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
4
4
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
5
5
|
var loadEntryPoint = require('./loadEntryPoint');
|
6
|
-
var _require = require('./loadQuery'),
|
7
|
-
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
8
6
|
var useIsMountedRef = require('./useIsMountedRef');
|
9
|
-
var
|
10
|
-
useCallback =
|
11
|
-
useEffect =
|
12
|
-
useRef =
|
13
|
-
useState =
|
7
|
+
var _require = require('react'),
|
8
|
+
useCallback = _require.useCallback,
|
9
|
+
useEffect = _require.useEffect,
|
10
|
+
useRef = _require.useRef,
|
11
|
+
useState = _require.useState;
|
14
12
|
var initialNullEntryPointReferenceState = {
|
15
13
|
kind: 'NullEntryPointReference'
|
16
14
|
};
|
17
15
|
function useLoadEntryPoint(environmentProvider, entryPoint, options) {
|
18
16
|
var _options$TEST_ONLY__i, _options$TEST_ONLY__i2, _options$TEST_ONLY__i3, _options$TEST_ONLY__i4;
|
19
|
-
useTrackLoadQueryInRender();
|
20
17
|
var initialEntryPointReferenceInternal = (_options$TEST_ONLY__i = options === null || options === void 0 ? void 0 : (_options$TEST_ONLY__i2 = options.TEST_ONLY__initialEntryPointData) === null || _options$TEST_ONLY__i2 === void 0 ? void 0 : _options$TEST_ONLY__i2.entryPointReference) !== null && _options$TEST_ONLY__i !== void 0 ? _options$TEST_ONLY__i : initialNullEntryPointReferenceState;
|
21
18
|
var initialEntryPointParamsInternal = (_options$TEST_ONLY__i3 = options === null || options === void 0 ? void 0 : (_options$TEST_ONLY__i4 = options.TEST_ONLY__initialEntryPointData) === null || _options$TEST_ONLY__i4 === void 0 ? void 0 : _options$TEST_ONLY__i4.entryPointParams) !== null && _options$TEST_ONLY__i3 !== void 0 ? _options$TEST_ONLY__i3 : null;
|
22
19
|
var isMountedRef = useIsMountedRef();
|
@@ -1,15 +1,12 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var _require = require('./loadQuery'),
|
4
|
-
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
5
3
|
var useFragmentInternal = require('./useFragmentInternal');
|
6
4
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
7
|
-
var
|
8
|
-
useDebugValue =
|
9
|
-
var
|
10
|
-
getFragment =
|
5
|
+
var _require = require('react'),
|
6
|
+
useDebugValue = _require.useDebugValue;
|
7
|
+
var _require2 = require('relay-runtime'),
|
8
|
+
getFragment = _require2.getFragment;
|
11
9
|
function useFragment(fragment, key) {
|
12
|
-
useTrackLoadQueryInRender();
|
13
10
|
var fragmentNode = getFragment(fragment);
|
14
11
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
15
12
|
var data = useFragmentInternal(fragmentNode, key, 'useFragment()');
|