react-relay 14.1.0 → 16.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -0
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -0
- package/ReactRelayFragmentContainer.js.flow +6 -2
- package/ReactRelayFragmentMockRenderer.js.flow +1 -0
- package/ReactRelayLocalQueryRenderer.js.flow +5 -3
- package/ReactRelayPaginationContainer.js.flow +21 -12
- package/ReactRelayQueryFetcher.js.flow +20 -10
- package/ReactRelayQueryRenderer.js.flow +15 -11
- package/ReactRelayQueryRendererContext.js.flow +1 -0
- package/ReactRelayRefetchContainer.js.flow +9 -5
- package/ReactRelayTestMocker.js.flow +3 -1
- package/ReactRelayTypes.js.flow +2 -0
- package/RelayContext.js.flow +1 -0
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +10 -6
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -0
- package/index.js +1 -1
- package/index.js.flow +4 -0
- package/isRelayEnvironment.js.flow +1 -0
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -0
- package/lib/ReactRelayContainerUtils.js +0 -11
- package/lib/ReactRelayContext.js +1 -12
- package/lib/ReactRelayFragmentContainer.js +23 -122
- package/lib/ReactRelayFragmentMockRenderer.js +0 -12
- package/lib/ReactRelayLocalQueryRenderer.js +12 -41
- package/lib/ReactRelayPaginationContainer.js +45 -341
- package/lib/ReactRelayQueryFetcher.js +36 -111
- package/lib/ReactRelayQueryRenderer.js +29 -137
- package/lib/ReactRelayQueryRendererContext.js +0 -10
- package/lib/ReactRelayRefetchContainer.js +33 -166
- package/lib/ReactRelayTestMocker.js +18 -128
- package/lib/ReactRelayTypes.js +0 -9
- package/lib/RelayContext.js +0 -23
- package/lib/assertFragmentMap.js +0 -16
- package/lib/buildReactRelayContainer.js +7 -41
- package/lib/getRootVariablesForFragments.js +2 -19
- package/lib/hooks.js +3 -30
- package/lib/index.js +3 -39
- package/lib/isRelayEnvironment.js +1 -16
- package/lib/jest-react/enqueueTask.js +1 -25
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +2 -51
- package/lib/legacy.js +0 -20
- package/lib/multi-actor/ActorChange.js +0 -14
- package/lib/multi-actor/index.js +0 -10
- package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
- package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
- package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
- package/lib/relay-hooks/FragmentResource.js +130 -280
- package/lib/relay-hooks/HooksImplementation.js +0 -14
- package/lib/relay-hooks/InternalLogger.js +0 -11
- package/lib/relay-hooks/LRUCache.js +0 -39
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
- package/lib/relay-hooks/MatchContainer.js +9 -111
- package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
- package/lib/relay-hooks/ProfilerContext.js +0 -14
- package/lib/relay-hooks/QueryResource.js +14 -149
- package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
- package/lib/relay-hooks/SuspenseResource.js +2 -59
- package/lib/relay-hooks/loadEntryPoint.js +10 -45
- package/lib/relay-hooks/loadQuery.js +29 -169
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
- package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
- package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
- package/lib/relay-hooks/useClientQuery.js +0 -21
- package/lib/relay-hooks/useEntryPointLoader.js +12 -100
- package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
- package/lib/relay-hooks/useFragment.js +5 -32
- package/lib/relay-hooks/useFragmentNode.js +14 -55
- package/lib/relay-hooks/useIsMountedRef.js +2 -14
- package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
- package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
- package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
- package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
- package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
- package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
- package/lib/relay-hooks/useMemoVariables.js +8 -43
- package/lib/relay-hooks/useMutation.js +6 -34
- package/lib/relay-hooks/usePaginationFragment.js +49 -89
- package/lib/relay-hooks/usePreloadedQuery.js +10 -54
- package/lib/relay-hooks/useQueryLoader.js +18 -116
- package/lib/relay-hooks/useRefetchableFragment.js +4 -30
- package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
- package/lib/relay-hooks/useRelayEnvironment.js +2 -16
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
- package/lib/relay-hooks/useSubscription.js +3 -22
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +6 -1
- package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
- package/relay-hooks/FragmentResource.js.flow +148 -34
- package/relay-hooks/HooksImplementation.js.flow +1 -1
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +25 -5
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/SuspenseResource.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +40 -33
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
- package/relay-hooks/__flowtests__/utils.js.flow +13 -2
- package/relay-hooks/loadEntryPoint.js.flow +15 -8
- package/relay-hooks/loadQuery.js.flow +32 -8
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
- package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
- package/relay-hooks/useClientQuery.js.flow +3 -3
- package/relay-hooks/useEntryPointLoader.js.flow +10 -6
- package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
- package/relay-hooks/useFragment.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +7 -6
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
- package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
- package/relay-hooks/useMemoVariables.js.flow +13 -29
- package/relay-hooks/useMutation.js.flow +30 -13
- package/relay-hooks/usePaginationFragment.js.flow +55 -54
- package/relay-hooks/usePreloadedQuery.js.flow +47 -22
- package/relay-hooks/useQueryLoader.js.flow +78 -21
- package/relay-hooks/useRefetchableFragment.js.flow +65 -33
- package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
- package/relay-hooks/useRelayEnvironment.js.flow +2 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -27
- package/readContext.js.flow +0 -29
@@ -1,86 +1,38 @@
|
|
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
|
-
*/
|
10
1
|
'use strict';
|
11
2
|
|
12
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
13
|
-
|
14
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
15
|
-
|
16
5
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
17
|
-
|
18
6
|
var areEqual = require("fbjs/lib/areEqual");
|
19
|
-
|
20
7
|
var invariant = require('invariant');
|
21
|
-
|
22
8
|
var _require = require('relay-runtime'),
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
9
|
+
Network = _require.Network,
|
10
|
+
createOperationDescriptor = _require.createOperationDescriptor,
|
11
|
+
isRelayModernEnvironment = _require.isRelayModernEnvironment;
|
27
12
|
var warning = require("fbjs/lib/warning");
|
28
|
-
|
29
|
-
/**
|
30
|
-
* The next id to return from `generateId()`.
|
31
|
-
*/
|
32
13
|
var nextId = 0;
|
33
|
-
|
34
14
|
var ReactRelayTestMocker = /*#__PURE__*/function () {
|
35
15
|
function ReactRelayTestMocker(env) {
|
36
16
|
(0, _defineProperty2["default"])(this, "_defaults", {});
|
37
17
|
(0, _defineProperty2["default"])(this, "_pendingFetches", []);
|
38
|
-
|
39
18
|
if (isRelayModernEnvironment(env)) {
|
40
19
|
this._mockNetworkLayer(env);
|
41
20
|
} else {
|
42
21
|
process.env.NODE_ENV !== "production" ? warning(false, 'Network mocking is currently only supported in Relay Modern. ' + 'You will not be able to resolve requests made with Relay ' + 'Classic environments.') : void 0;
|
43
22
|
}
|
44
|
-
|
45
23
|
this._environment = env;
|
46
24
|
}
|
47
|
-
|
48
25
|
ReactRelayTestMocker.mockOutEnvironment = function mockOutEnvironment(env) {
|
49
26
|
return new ReactRelayTestMocker(env);
|
50
|
-
}
|
51
|
-
/**
|
52
|
-
* Get a unique id number (as a string). Note: will wrap around after 2^32
|
53
|
-
* calls, if your test needs that many IDs.
|
54
|
-
*
|
55
|
-
* @returns a unique id string
|
56
|
-
*/
|
57
|
-
;
|
58
|
-
|
27
|
+
};
|
59
28
|
ReactRelayTestMocker.generateId = function generateId() {
|
60
29
|
var toRet = nextId.toString();
|
61
30
|
nextId++;
|
62
31
|
return toRet;
|
63
|
-
}
|
64
|
-
/**
|
65
|
-
* Create a unique identifier for a (query, variables) pair.
|
66
|
-
* @param request: the request associated with the query
|
67
|
-
* @param variables: the variables associated with this invocation of the
|
68
|
-
* query
|
69
|
-
*
|
70
|
-
* @returns a string which can later be used to uniquely identify this query
|
71
|
-
* in the list of pending queries
|
72
|
-
*/
|
73
|
-
;
|
74
|
-
|
32
|
+
};
|
75
33
|
ReactRelayTestMocker.getIdentifier = function getIdentifier(request) {
|
76
34
|
return request.name;
|
77
|
-
}
|
78
|
-
/**
|
79
|
-
* Remove variables that we don't need from the query that will make it more
|
80
|
-
* annoying to test (e.g. client_mutation_id, actor_id)
|
81
|
-
*/
|
82
|
-
;
|
83
|
-
|
35
|
+
};
|
84
36
|
ReactRelayTestMocker.stripUnused = function stripUnused(variables) {
|
85
37
|
if (variables.input) {
|
86
38
|
var toRemove = ['client_mutation_id', 'actor_id', 'clientMutationId', 'actorId'];
|
@@ -92,23 +44,11 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
|
|
92
44
|
});
|
93
45
|
return strippedVariables;
|
94
46
|
}
|
95
|
-
|
96
47
|
return variables;
|
97
|
-
}
|
98
|
-
/**
|
99
|
-
* Replace the environment's network layer with a mocked out one to allow for
|
100
|
-
* better testing. Mocking the network allows testing without using a mocked
|
101
|
-
* out QueryRenderer, and will allow for easier testing of components wrapped
|
102
|
-
* in refetch containers, for example. It also allows test writers to see how
|
103
|
-
* their components behave under error conditions.
|
104
|
-
*/
|
105
|
-
;
|
106
|
-
|
48
|
+
};
|
107
49
|
var _proto = ReactRelayTestMocker.prototype;
|
108
|
-
|
109
50
|
_proto._mockNetworkLayer = function _mockNetworkLayer(env) {
|
110
51
|
var _this = this;
|
111
|
-
|
112
52
|
var fetch = function fetch(request, variables, cacheConfig) {
|
113
53
|
var resolve;
|
114
54
|
var reject;
|
@@ -117,13 +57,11 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
|
|
117
57
|
reject = rej;
|
118
58
|
});
|
119
59
|
var strippedVars = ReactRelayTestMocker.stripUnused(variables);
|
120
|
-
var ident = ReactRelayTestMocker.getIdentifier(request);
|
121
|
-
|
60
|
+
var ident = ReactRelayTestMocker.getIdentifier(request);
|
122
61
|
if (_this._defaults[ident]) {
|
123
62
|
var payload = _this._defaults[ident];
|
124
63
|
return typeof payload === 'function' ? payload(strippedVars) : payload;
|
125
64
|
}
|
126
|
-
|
127
65
|
_this._pendingFetches.push({
|
128
66
|
ident: ident,
|
129
67
|
cacheConfig: cacheConfig,
|
@@ -134,16 +72,13 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
|
|
134
72
|
request: request,
|
135
73
|
variables: strippedVars
|
136
74
|
});
|
137
|
-
|
138
75
|
return promise;
|
139
76
|
};
|
140
|
-
|
141
77
|
var isLoading = function isLoading(ident) {
|
142
78
|
return _this._pendingFetches.some(function (pending) {
|
143
79
|
return pending.ident === ident;
|
144
80
|
});
|
145
81
|
};
|
146
|
-
|
147
82
|
var resolveRawQuery = function resolveRawQuery(toResolve, payload) {
|
148
83
|
_this._pendingFetches = _this._pendingFetches.filter(function (pending) {
|
149
84
|
return pending !== toResolve;
|
@@ -151,7 +86,6 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
|
|
151
86
|
var deferred = toResolve.deferred;
|
152
87
|
deferred.resolve(payload);
|
153
88
|
};
|
154
|
-
|
155
89
|
var rejectQuery = function rejectQuery(toResolve, payload) {
|
156
90
|
_this._pendingFetches = _this._pendingFetches.filter(function (pending) {
|
157
91
|
return pending !== toResolve;
|
@@ -159,7 +93,6 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
|
|
159
93
|
var deferred = toResolve.deferred;
|
160
94
|
deferred.reject(payload.error);
|
161
95
|
};
|
162
|
-
|
163
96
|
env.mock = {
|
164
97
|
isLoading: isLoading,
|
165
98
|
rejectQuery: rejectQuery,
|
@@ -167,82 +100,44 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
|
|
167
100
|
fetch: fetch
|
168
101
|
};
|
169
102
|
env.hasMockedNetwork = true;
|
170
|
-
|
171
103
|
env.__setNet(Network.create(fetch));
|
172
|
-
|
173
104
|
return env;
|
174
|
-
}
|
175
|
-
/**
|
176
|
-
* set a default payload for a given query
|
177
|
-
*/
|
178
|
-
;
|
179
|
-
|
105
|
+
};
|
180
106
|
_proto.setDefault = function setDefault(toSet) {
|
181
107
|
var query = toSet.query,
|
182
|
-
|
108
|
+
payload = toSet.payload;
|
183
109
|
var ident = ReactRelayTestMocker.getIdentifier(query.params);
|
184
110
|
this._defaults[ident] = payload;
|
185
|
-
}
|
186
|
-
/**
|
187
|
-
* remove a default payload for a given query
|
188
|
-
*/
|
189
|
-
;
|
190
|
-
|
111
|
+
};
|
191
112
|
_proto.unsetDefault = function unsetDefault(toUnset) {
|
192
113
|
var query = toUnset.query;
|
193
114
|
var ident = ReactRelayTestMocker.getIdentifier(query.params);
|
194
115
|
delete this._defaults[ident];
|
195
|
-
}
|
196
|
-
/**
|
197
|
-
* Write directly to the Relay store instead of trying to resolve a query that
|
198
|
-
* was sent via the network.
|
199
|
-
*
|
200
|
-
* Use this method when testing a component wrapped in a fragment container
|
201
|
-
* (via `createFragmentContainer`). The component under test should also be
|
202
|
-
* wrapped in a `RelayTestRenderer`.
|
203
|
-
*/
|
204
|
-
;
|
205
|
-
|
116
|
+
};
|
206
117
|
_proto.dataWrite = function dataWrite(config) {
|
207
118
|
var query = config.query,
|
208
|
-
|
209
|
-
|
119
|
+
variables = config.variables,
|
120
|
+
payload = config.payload;
|
210
121
|
var operationDescriptor = createOperationDescriptor(query, variables);
|
211
122
|
!(payload.data != null && payload.errors === undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Only `data` can be written when using `writeDirect`. You may need to ' + 'wrap your payload in an object like `{data: payload}`.') : invariant(false) : void 0;
|
212
|
-
|
213
123
|
this._environment.commitPayload(operationDescriptor, payload.data);
|
214
|
-
}
|
215
|
-
/**
|
216
|
-
* Write the data specified in config's payload to the instance's environment.
|
217
|
-
* NOTE: callers may need to invoke `jest.runOnlyPendingTimers()` after
|
218
|
-
* calling this function.
|
219
|
-
*
|
220
|
-
* @param config: an object containing the data to write and the query and
|
221
|
-
* variables that the payload is simulating a response to
|
222
|
-
*/
|
223
|
-
;
|
224
|
-
|
124
|
+
};
|
225
125
|
_proto.networkWrite = function networkWrite(config) {
|
226
126
|
!this._environment.hasMockedNetwork ? process.env.NODE_ENV !== "production" ? invariant(false, 'You cannot resolve queries without a mocked environment. Did you mean ' + 'to use `writeDirect` instead?') : invariant(false) : void 0;
|
227
127
|
var query = config.query,
|
228
|
-
|
229
|
-
|
128
|
+
variables = config.variables,
|
129
|
+
payload = config.payload;
|
230
130
|
var ident = ReactRelayTestMocker.getIdentifier(query.params);
|
231
131
|
var usedVars;
|
232
|
-
|
233
132
|
if (variables) {
|
234
133
|
var operationDescriptor = createOperationDescriptor(query, variables);
|
235
134
|
usedVars = ReactRelayTestMocker.stripUnused(operationDescriptor.request.variables);
|
236
135
|
}
|
237
|
-
|
238
136
|
var toResolve;
|
239
|
-
|
240
137
|
this._pendingFetches.forEach(function (pending) {
|
241
138
|
var pendingVars = pending.variables;
|
242
|
-
|
243
139
|
if (pending.ident === ident) {
|
244
140
|
!(!toResolve || variables) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Multiple queries with the same name are currently pending. You ' + 'should pass variables to `write` so that it can determine which ' + 'to resolve') : invariant(false) : void 0;
|
245
|
-
|
246
141
|
if (variables) {
|
247
142
|
if (areEqual(pendingVars, usedVars)) {
|
248
143
|
toResolve = pending;
|
@@ -252,12 +147,9 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
|
|
252
147
|
}
|
253
148
|
}
|
254
149
|
});
|
255
|
-
|
256
150
|
var varMessage = usedVars ? ' - variables: ' + JSON.stringify(usedVars) : '';
|
257
151
|
!toResolve ? process.env.NODE_ENV !== "production" ? invariant(false, 'You are attempting to resolve a query that has not been fetched ' + '(%s%s).\n\tPlease ensure you passed the correct variables, or use ' + '`writeDirect` instead.', ident, varMessage) : invariant(false) : void 0;
|
258
|
-
var realPayload =
|
259
|
-
typeof payload === 'function' ? payload(toResolve.variables) : payload; // if there are errors, reject the query
|
260
|
-
|
152
|
+
var realPayload = typeof payload === 'function' ? payload(toResolve.variables) : payload;
|
261
153
|
if (realPayload.errors != null && realPayload.errors.length > 0) {
|
262
154
|
this._environment.mock.rejectQuery(toResolve, {
|
263
155
|
error: realPayload.errors[0]
|
@@ -266,8 +158,6 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
|
|
266
158
|
this._environment.mock.resolveRawQuery(toResolve, realPayload);
|
267
159
|
}
|
268
160
|
};
|
269
|
-
|
270
161
|
return ReactRelayTestMocker;
|
271
162
|
}();
|
272
|
-
|
273
163
|
module.exports = ReactRelayTestMocker;
|
package/lib/ReactRelayTypes.js
CHANGED
package/lib/RelayContext.js
CHANGED
@@ -1,37 +1,14 @@
|
|
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
|
-
*/
|
10
1
|
'use strict';
|
11
2
|
|
12
3
|
var isRelayEnvironment = require('./isRelayEnvironment');
|
13
|
-
|
14
4
|
var invariant = require('invariant');
|
15
|
-
/**
|
16
|
-
* Asserts that the input is a matches the `RelayContext` type defined in
|
17
|
-
* `RelayEnvironmentTypes` and returns it as that type.
|
18
|
-
*/
|
19
|
-
|
20
|
-
|
21
5
|
function assertRelayContext(relay) {
|
22
6
|
!isRelayContext(relay) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayContext: Expected `context.relay` to be an object conforming to ' + 'the `RelayContext` interface, got `%s`.', relay) : invariant(false) : void 0;
|
23
7
|
return relay;
|
24
8
|
}
|
25
|
-
/**
|
26
|
-
* Determine if the input is a plain object that matches the `RelayContext`
|
27
|
-
* type defined in `RelayEnvironmentTypes`.
|
28
|
-
*/
|
29
|
-
|
30
|
-
|
31
9
|
function isRelayContext(context) {
|
32
10
|
return typeof context === 'object' && context !== null && !Array.isArray(context) && isRelayEnvironment(context.environment);
|
33
11
|
}
|
34
|
-
|
35
12
|
module.exports = {
|
36
13
|
assertRelayContext: assertRelayContext,
|
37
14
|
isRelayContext: isRelayContext
|
package/lib/assertFragmentMap.js
CHANGED
@@ -1,23 +1,8 @@
|
|
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
|
-
*/
|
10
1
|
'use strict';
|
11
2
|
|
12
3
|
var invariant = require('invariant');
|
13
|
-
/**
|
14
|
-
* Fail fast if the user supplies invalid fragments as input.
|
15
|
-
*/
|
16
|
-
|
17
|
-
|
18
4
|
function assertFragmentMap(componentName, fragmentSpec) {
|
19
5
|
!(fragmentSpec && typeof fragmentSpec === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Could not create Relay Container for `%s`. ' + 'Expected a set of GraphQL fragments, got `%s` instead.', componentName, fragmentSpec) : invariant(false) : void 0;
|
20
|
-
|
21
6
|
for (var key in fragmentSpec) {
|
22
7
|
if (fragmentSpec.hasOwnProperty(key)) {
|
23
8
|
var fragment = fragmentSpec[key];
|
@@ -25,5 +10,4 @@ function assertFragmentMap(componentName, fragmentSpec) {
|
|
25
10
|
}
|
26
11
|
}
|
27
12
|
}
|
28
|
-
|
29
13
|
module.exports = assertFragmentMap;
|
@@ -1,78 +1,44 @@
|
|
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
|
-
*/
|
10
1
|
'use strict';
|
11
2
|
|
12
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
13
|
-
|
14
4
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
15
|
-
|
16
5
|
var assertFragmentMap = require('./assertFragmentMap');
|
17
|
-
|
18
6
|
var _require = require('./ReactRelayContainerUtils'),
|
19
|
-
|
20
|
-
|
21
|
-
|
7
|
+
getComponentName = _require.getComponentName,
|
8
|
+
getContainerName = _require.getContainerName;
|
22
9
|
var ReactRelayContext = require('./ReactRelayContext');
|
23
|
-
|
24
10
|
var ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
|
25
|
-
|
26
|
-
var readContext = require('./readContext');
|
27
|
-
|
28
11
|
var invariant = require('invariant');
|
29
|
-
|
30
12
|
var React = require('react');
|
31
|
-
|
32
13
|
var _require2 = require('relay-runtime'),
|
33
|
-
|
34
|
-
|
35
|
-
/**
|
36
|
-
* Helper to create the Relay HOCs with ref forwarding, setting the displayName
|
37
|
-
* and reading the React context.
|
38
|
-
*/
|
14
|
+
getFragment = _require2.getFragment;
|
15
|
+
var useContext = React.useContext;
|
39
16
|
function buildReactRelayContainer(ComponentClass, fragmentSpec, createContainerWithFragments) {
|
40
|
-
// Sanity-check user-defined fragment input
|
41
17
|
var containerName = getContainerName(ComponentClass);
|
42
18
|
assertFragmentMap(getComponentName(ComponentClass), fragmentSpec);
|
43
19
|
var fragments = {};
|
44
|
-
|
45
20
|
for (var key in fragmentSpec) {
|
46
21
|
fragments[key] = getFragment(fragmentSpec[key]);
|
47
22
|
}
|
48
|
-
|
49
23
|
var Container = createContainerWithFragments(ComponentClass, fragments);
|
50
24
|
Container.displayName = containerName;
|
51
|
-
|
52
25
|
function forwardRef(props, ref) {
|
53
26
|
var _queryRendererContext;
|
54
|
-
|
55
|
-
var context = readContext(ReactRelayContext);
|
27
|
+
var context = useContext(ReactRelayContext);
|
56
28
|
!(context != null) ? process.env.NODE_ENV !== "production" ? invariant(false, '`%s` tried to render a context that was not valid this means that ' + '`%s` was rendered outside of a query renderer.', containerName, containerName) : invariant(false) : void 0;
|
57
|
-
var queryRendererContext =
|
29
|
+
var queryRendererContext = useContext(ReactRelayQueryRendererContext);
|
58
30
|
return /*#__PURE__*/React.createElement(Container, (0, _extends2["default"])({}, props, {
|
59
31
|
__relayContext: context,
|
60
32
|
__rootIsQueryRenderer: (_queryRendererContext = queryRendererContext === null || queryRendererContext === void 0 ? void 0 : queryRendererContext.rootIsQueryRenderer) !== null && _queryRendererContext !== void 0 ? _queryRendererContext : false,
|
61
33
|
componentRef: props.componentRef || ref
|
62
34
|
}));
|
63
35
|
}
|
64
|
-
|
65
36
|
forwardRef.displayName = containerName;
|
66
37
|
var ForwardContainer = React.forwardRef(forwardRef);
|
67
|
-
|
68
38
|
if (process.env.NODE_ENV !== "production") {
|
69
|
-
// Used by RelayModernTestUtils
|
70
39
|
ForwardContainer.__ComponentClass = ComponentClass;
|
71
40
|
ForwardContainer.displayName = containerName;
|
72
|
-
}
|
73
|
-
|
74
|
-
|
41
|
+
}
|
75
42
|
return ForwardContainer;
|
76
43
|
}
|
77
|
-
|
78
44
|
module.exports = buildReactRelayContainer;
|
@@ -1,29 +1,13 @@
|
|
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
|
-
*/
|
10
1
|
'use strict';
|
11
2
|
|
12
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
13
|
-
|
14
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
15
|
-
|
16
5
|
var _require = require('relay-runtime'),
|
17
|
-
|
18
|
-
|
6
|
+
getSelector = _require.getSelector;
|
19
7
|
function getRootVariablesForFragments(fragments, props) {
|
20
|
-
var rootVariables = {};
|
21
|
-
// variables from all owners in this fragmentSpec, even though they
|
22
|
-
// should all point to the same owner
|
23
|
-
|
8
|
+
var rootVariables = {};
|
24
9
|
Object.keys(fragments).forEach(function (key) {
|
25
10
|
var _selector$selectors$, _selector$selectors$2, _selector$owner$varia;
|
26
|
-
|
27
11
|
var fragmentNode = fragments[key];
|
28
12
|
var fragmentRef = props[key];
|
29
13
|
var selector = getSelector(fragmentNode, fragmentRef);
|
@@ -32,5 +16,4 @@ function getRootVariablesForFragments(fragments, props) {
|
|
32
16
|
});
|
33
17
|
return rootVariables;
|
34
18
|
}
|
35
|
-
|
36
19
|
module.exports = getRootVariablesForFragments;
|
package/lib/hooks.js
CHANGED
@@ -1,51 +1,23 @@
|
|
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
|
-
*/
|
10
1
|
'use strict';
|
11
2
|
|
12
3
|
var EntryPointContainer = require('./relay-hooks/EntryPointContainer.react');
|
13
|
-
|
14
4
|
var loadEntryPoint = require('./relay-hooks/loadEntryPoint');
|
15
|
-
|
16
5
|
var _require = require('./relay-hooks/loadQuery'),
|
17
|
-
|
18
|
-
|
6
|
+
loadQuery = _require.loadQuery;
|
7
|
+
var ProfilerContext = require('./relay-hooks/ProfilerContext');
|
19
8
|
var RelayEnvironmentProvider = require('./relay-hooks/RelayEnvironmentProvider');
|
20
|
-
|
21
9
|
var useEntryPointLoader = require('./relay-hooks/useEntryPointLoader');
|
22
|
-
|
23
10
|
var useFragment = require('./relay-hooks/useFragment');
|
24
|
-
|
25
11
|
var useLazyLoadQuery = require('./relay-hooks/useLazyLoadQuery');
|
26
|
-
|
27
12
|
var useMutation = require('./relay-hooks/useMutation');
|
28
|
-
|
29
13
|
var usePaginationFragment = require('./relay-hooks/usePaginationFragment');
|
30
|
-
|
31
14
|
var usePreloadedQuery = require('./relay-hooks/usePreloadedQuery');
|
32
|
-
|
33
15
|
var useQueryLoader = require('./relay-hooks/useQueryLoader');
|
34
|
-
|
35
16
|
var useRefetchableFragment = require('./relay-hooks/useRefetchableFragment');
|
36
|
-
|
37
17
|
var useRelayEnvironment = require('./relay-hooks/useRelayEnvironment');
|
38
|
-
|
39
18
|
var useSubscribeToInvalidationState = require('./relay-hooks/useSubscribeToInvalidationState');
|
40
|
-
|
41
19
|
var useSubscription = require('./relay-hooks/useSubscription');
|
42
|
-
|
43
20
|
var RelayRuntime = require('relay-runtime');
|
44
|
-
|
45
|
-
/**
|
46
|
-
* The public interface for Relay Hooks.
|
47
|
-
* This will eventually become the main public interface for react-relay.
|
48
|
-
*/
|
49
21
|
module.exports = {
|
50
22
|
ConnectionHandler: RelayRuntime.ConnectionHandler,
|
51
23
|
applyOptimisticMutation: RelayRuntime.applyOptimisticMutation,
|
@@ -56,6 +28,7 @@ module.exports = {
|
|
56
28
|
requestSubscription: RelayRuntime.requestSubscription,
|
57
29
|
EntryPointContainer: EntryPointContainer,
|
58
30
|
RelayEnvironmentProvider: RelayEnvironmentProvider,
|
31
|
+
ProfilerContext: ProfilerContext,
|
59
32
|
fetchQuery: RelayRuntime.fetchQuery,
|
60
33
|
loadQuery: loadQuery,
|
61
34
|
loadEntryPoint: loadEntryPoint,
|
package/lib/index.js
CHANGED
@@ -1,66 +1,30 @@
|
|
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
|
-
*/
|
10
1
|
'use strict';
|
11
2
|
|
12
3
|
var ReactRelayContext = require('./ReactRelayContext');
|
13
|
-
|
14
4
|
var ReactRelayFragmentContainer = require('./ReactRelayFragmentContainer');
|
15
|
-
|
16
5
|
var ReactRelayLocalQueryRenderer = require('./ReactRelayLocalQueryRenderer');
|
17
|
-
|
18
6
|
var ReactRelayPaginationContainer = require('./ReactRelayPaginationContainer');
|
19
|
-
|
20
7
|
var ReactRelayQueryRenderer = require('./ReactRelayQueryRenderer');
|
21
|
-
|
22
8
|
var ReactRelayRefetchContainer = require('./ReactRelayRefetchContainer');
|
23
|
-
|
24
9
|
var EntryPointContainer = require('./relay-hooks/EntryPointContainer.react');
|
25
|
-
|
26
10
|
var loadEntryPoint = require('./relay-hooks/loadEntryPoint');
|
27
|
-
|
28
11
|
var _require = require('./relay-hooks/loadQuery'),
|
29
|
-
|
30
|
-
|
12
|
+
loadQuery = _require.loadQuery;
|
13
|
+
var ProfilerContext = require('./relay-hooks/ProfilerContext');
|
31
14
|
var RelayEnvironmentProvider = require('./relay-hooks/RelayEnvironmentProvider');
|
32
|
-
|
33
15
|
var useClientQuery = require('./relay-hooks/useClientQuery');
|
34
|
-
|
35
16
|
var useEntryPointLoader = require('./relay-hooks/useEntryPointLoader');
|
36
|
-
|
37
17
|
var useFragment = require('./relay-hooks/useFragment');
|
38
|
-
|
39
18
|
var useLazyLoadQuery = require('./relay-hooks/useLazyLoadQuery');
|
40
|
-
|
41
19
|
var useMutation = require('./relay-hooks/useMutation');
|
42
|
-
|
43
20
|
var usePaginationFragment = require('./relay-hooks/usePaginationFragment');
|
44
|
-
|
45
21
|
var usePreloadedQuery = require('./relay-hooks/usePreloadedQuery');
|
46
|
-
|
47
22
|
var useQueryLoader = require('./relay-hooks/useQueryLoader');
|
48
|
-
|
49
23
|
var useRefetchableFragment = require('./relay-hooks/useRefetchableFragment');
|
50
|
-
|
51
24
|
var useRelayEnvironment = require('./relay-hooks/useRelayEnvironment');
|
52
|
-
|
53
25
|
var useSubscribeToInvalidationState = require('./relay-hooks/useSubscribeToInvalidationState');
|
54
|
-
|
55
26
|
var useSubscription = require('./relay-hooks/useSubscription');
|
56
|
-
|
57
27
|
var RelayRuntime = require('relay-runtime');
|
58
|
-
|
59
|
-
/**
|
60
|
-
* The public interface to react-relay.
|
61
|
-
* Currently contains both Relay Hooks and legacy Container APIs.
|
62
|
-
* Will eventually only export the interface from ./hooks.js.
|
63
|
-
*/
|
64
28
|
module.exports = {
|
65
29
|
ConnectionHandler: RelayRuntime.ConnectionHandler,
|
66
30
|
QueryRenderer: ReactRelayQueryRenderer,
|
@@ -78,9 +42,9 @@ module.exports = {
|
|
78
42
|
graphql: RelayRuntime.graphql,
|
79
43
|
readInlineData: RelayRuntime.readInlineData,
|
80
44
|
requestSubscription: RelayRuntime.requestSubscription,
|
81
|
-
// Relay Hooks
|
82
45
|
EntryPointContainer: EntryPointContainer,
|
83
46
|
RelayEnvironmentProvider: RelayEnvironmentProvider,
|
47
|
+
ProfilerContext: ProfilerContext,
|
84
48
|
fetchQuery: RelayRuntime.fetchQuery,
|
85
49
|
loadQuery: loadQuery,
|
86
50
|
loadEntryPoint: loadEntryPoint,
|
@@ -1,21 +1,6 @@
|
|
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
|
-
*/
|
10
1
|
'use strict';
|
11
|
-
/**
|
12
|
-
* Determine if a given value is an object that implements the `Environment`
|
13
|
-
* interface defined in `RelayEnvironmentTypes`.
|
14
|
-
*/
|
15
2
|
|
16
3
|
function isRelayEnvironment(environment) {
|
17
|
-
return typeof environment === 'object' && environment !== null &&
|
18
|
-
typeof environment.check === 'function' && typeof environment.lookup === 'function' && typeof environment.retain === 'function' && typeof environment.execute === 'function' && typeof environment.subscribe === 'function';
|
4
|
+
return typeof environment === 'object' && environment !== null && typeof environment.check === 'function' && typeof environment.lookup === 'function' && typeof environment.retain === 'function' && typeof environment.execute === 'function' && typeof environment.subscribe === 'function';
|
19
5
|
}
|
20
|
-
|
21
6
|
module.exports = isRelayEnvironment;
|