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