relay-runtime 10.1.3 → 11.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/handlers/connection/ConnectionHandler.js.flow +60 -0
- package/handlers/connection/MutationHandlers.js.flow +28 -0
- package/index.js +1 -1
- package/index.js.flow +9 -3
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +68 -6
- package/lib/handlers/connection/MutationHandlers.js +67 -8
- package/lib/index.js +3 -0
- package/lib/multi-actor-environment/ActorIdentifier.js +23 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +108 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +156 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +17 -0
- package/lib/mutations/RelayRecordProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceMutator.js +1 -1
- package/lib/mutations/RelayRecordSourceProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +1 -1
- package/lib/mutations/applyOptimisticMutation.js +1 -1
- package/lib/mutations/commitMutation.js +1 -1
- package/lib/mutations/validateMutation.js +36 -15
- package/lib/network/RelayNetwork.js +1 -1
- package/lib/network/RelayQueryResponseCache.js +3 -2
- package/lib/query/GraphQLTag.js +1 -1
- package/lib/query/fetchQuery.js +129 -13
- package/lib/query/fetchQueryInternal.js +3 -4
- package/lib/query/fetchQuery_DEPRECATED.js +39 -0
- package/lib/store/DataChecker.js +26 -14
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +117 -47
- package/lib/store/RelayConcreteVariables.js +8 -4
- package/lib/store/RelayModernEnvironment.js +105 -136
- package/lib/store/RelayModernFragmentSpecResolver.js +16 -9
- package/lib/store/RelayModernRecord.js +1 -1
- package/lib/store/RelayModernSelector.js +1 -1
- package/lib/store/RelayModernStore.js +19 -20
- package/lib/store/RelayOperationTracker.js +55 -49
- package/lib/store/RelayPublishQueue.js +9 -5
- package/lib/store/RelayReader.js +68 -14
- package/lib/store/RelayReferenceMarker.js +28 -14
- package/lib/store/RelayResponseNormalizer.js +109 -15
- package/lib/store/RelayStoreReactFlightUtils.js +6 -4
- package/lib/store/RelayStoreSubscriptions.js +18 -8
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +90 -30
- package/lib/store/RelayStoreUtils.js +3 -2
- package/lib/store/ResolverFragments.js +57 -0
- package/lib/store/cloneRelayHandleSourceField.js +1 -1
- package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
- package/lib/store/createFragmentSpecResolver.js +2 -2
- package/lib/store/createRelayContext.js +1 -1
- package/lib/store/defaultGetDataID.js +3 -1
- package/lib/store/hasOverlappingIDs.js +11 -3
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +33 -5
- package/lib/util/RelayConcreteNode.js +2 -0
- package/lib/util/RelayFeatureFlags.js +8 -3
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +1 -1
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/getRelayHandleKey.js +1 -1
- package/lib/util/getRequestIdentifier.js +1 -1
- package/multi-actor-environment/ActorIdentifier.js.flow +27 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +189 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +233 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +196 -0
- package/multi-actor-environment/index.js.flow +24 -0
- package/mutations/RelayRecordSourceProxy.js.flow +3 -2
- package/mutations/commitMutation.js.flow +1 -1
- package/mutations/validateMutation.js.flow +40 -15
- package/network/RelayNetworkTypes.js.flow +31 -11
- package/network/RelayQueryResponseCache.js.flow +2 -1
- package/package.json +3 -2
- package/query/fetchQuery.js.flow +147 -20
- package/query/fetchQueryInternal.js.flow +2 -3
- package/query/fetchQuery_DEPRECATED.js.flow +47 -0
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/DataChecker.js.flow +23 -15
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +128 -40
- package/store/RelayConcreteVariables.js.flow +5 -0
- package/store/RelayModernEnvironment.js.flow +100 -130
- package/store/RelayModernFragmentSpecResolver.js.flow +30 -8
- package/store/RelayModernStore.js.flow +28 -24
- package/store/RelayOperationTracker.js.flow +69 -56
- package/store/RelayPublishQueue.js.flow +7 -4
- package/store/RelayReader.js.flow +63 -11
- package/store/RelayRecordSource.js.flow +3 -3
- package/store/RelayRecordSourceMapImpl.js.flow +6 -2
- package/store/RelayReferenceMarker.js.flow +28 -18
- package/store/RelayResponseNormalizer.js.flow +134 -23
- package/store/RelayStoreReactFlightUtils.js.flow +9 -4
- package/store/RelayStoreSubscriptions.js.flow +22 -7
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +36 -12
- package/store/RelayStoreTypes.js.flow +51 -22
- package/store/RelayStoreUtils.js.flow +2 -1
- package/store/ResolverFragments.js.flow +125 -0
- package/store/createFragmentSpecResolver.js.flow +2 -0
- package/store/defaultGetDataID.js.flow +3 -1
- package/store/hasOverlappingIDs.js.flow +11 -9
- package/subscription/requestSubscription.js.flow +25 -2
- package/util/NormalizationNode.js.flow +13 -0
- package/util/ReaderNode.js.flow +14 -1
- package/util/RelayConcreteNode.js.flow +2 -0
- package/util/RelayFeatureFlags.js.flow +12 -2
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayRuntimeTypes.js.flow +4 -5
- package/util/deepFreeze.js.flow +2 -1
- package/util/isEmptyObject.js.flow +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "relay-runtime",
|
|
3
3
|
"description": "A core runtime for building GraphQL-driven applications.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "11.0.2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
7
|
"relay"
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"repository": "facebook/relay",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@babel/runtime": "^7.0.0",
|
|
15
|
-
"fbjs": "^3.0.0"
|
|
15
|
+
"fbjs": "^3.0.0",
|
|
16
|
+
"invariant": "^2.2.4"
|
|
16
17
|
},
|
|
17
18
|
"directories": {
|
|
18
19
|
"": "./"
|
package/query/fetchQuery.js.flow
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
+
* @emails oncall+relay
|
|
7
8
|
* @flow strict-local
|
|
8
9
|
* @format
|
|
9
10
|
*/
|
|
@@ -12,36 +13,162 @@
|
|
|
12
13
|
|
|
13
14
|
'use strict';
|
|
14
15
|
|
|
16
|
+
const RelayObservable = require('../network/RelayObservable');
|
|
17
|
+
|
|
18
|
+
const fetchQueryInternal = require('./fetchQueryInternal');
|
|
19
|
+
const invariant = require('invariant');
|
|
20
|
+
const reportMissingRequiredFields = require('../util/reportMissingRequiredFields');
|
|
21
|
+
|
|
15
22
|
const {
|
|
16
23
|
createOperationDescriptor,
|
|
17
24
|
} = require('../store/RelayModernOperationDescriptor');
|
|
18
25
|
const {getRequest} = require('./GraphQLTag');
|
|
19
26
|
|
|
20
|
-
import type {
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
import type {
|
|
28
|
+
CacheConfig,
|
|
29
|
+
FetchQueryFetchPolicy,
|
|
30
|
+
GraphQLTaggedNode,
|
|
31
|
+
IEnvironment,
|
|
32
|
+
OperationDescriptor,
|
|
33
|
+
OperationType,
|
|
34
|
+
Snapshot,
|
|
35
|
+
VariablesOf,
|
|
36
|
+
} from 'relay-runtime';
|
|
23
37
|
|
|
24
38
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
39
|
+
* Fetches the given query and variables on the provided environment,
|
|
40
|
+
* and de-dupes identical in-flight requests.
|
|
41
|
+
*
|
|
42
|
+
* Observing a request:
|
|
43
|
+
* ====================
|
|
44
|
+
* fetchQuery returns an Observable which you can call .subscribe()
|
|
45
|
+
* on. Subscribe optionally takes an Observer, which you can provide to
|
|
46
|
+
* observe network events:
|
|
47
|
+
*
|
|
48
|
+
* ```
|
|
49
|
+
* fetchQuery(environment, query, variables).subscribe({
|
|
50
|
+
* // Called when network requests starts
|
|
51
|
+
* start: (subsctiption) => {},
|
|
52
|
+
*
|
|
53
|
+
* // Called after a payload is received and written to the local store
|
|
54
|
+
* next: (payload) => {},
|
|
55
|
+
*
|
|
56
|
+
* // Called when network requests errors
|
|
57
|
+
* error: (error) => {},
|
|
58
|
+
*
|
|
59
|
+
* // Called when network requests fully completes
|
|
60
|
+
* complete: () => {},
|
|
61
|
+
*
|
|
62
|
+
* // Called when network request is unsubscribed
|
|
63
|
+
* unsubscribe: (subscription) => {},
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* Request Promise:
|
|
68
|
+
* ================
|
|
69
|
+
* The obervable can be converted to a Promise with .toPromise(), which will
|
|
70
|
+
* resolve to a snapshot of the query data when the first response is received
|
|
71
|
+
* from the server.
|
|
72
|
+
*
|
|
73
|
+
* ```
|
|
74
|
+
* fetchQuery(environment, query, variables).toPromise().then((data) => {
|
|
75
|
+
* // ...
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* In-flight request de-duping:
|
|
80
|
+
* ============================
|
|
81
|
+
* By default, calling fetchQuery multiple times with the same
|
|
82
|
+
* environment, query and variables will not initiate a new request if a request
|
|
83
|
+
* for those same parameters is already in flight.
|
|
84
|
+
*
|
|
85
|
+
* A request is marked in-flight from the moment it starts until the moment it
|
|
86
|
+
* fully completes, regardless of error or successful completion.
|
|
87
|
+
*
|
|
88
|
+
* NOTE: If the request completes _synchronously_, calling fetchQuery
|
|
89
|
+
* a second time with the same arguments in the same tick will _NOT_ de-dupe
|
|
90
|
+
* the request given that it will no longer be in-flight.
|
|
91
|
+
*
|
|
92
|
+
*
|
|
93
|
+
* Data Retention:
|
|
94
|
+
* ===============
|
|
95
|
+
* This function will NOT retain query data, meaning that it is not guaranteed
|
|
96
|
+
* that the fetched data will remain in the Relay store after the request has
|
|
97
|
+
* completed.
|
|
98
|
+
* If you need to retain the query data outside of the network request,
|
|
99
|
+
* you need to use `environment.retain()`.
|
|
100
|
+
*
|
|
101
|
+
*
|
|
102
|
+
* Cancelling requests:
|
|
103
|
+
* ====================
|
|
104
|
+
* If the disposable returned by subscribe is called while the
|
|
105
|
+
* request is in-flight, the request will be cancelled.
|
|
106
|
+
*
|
|
107
|
+
* ```
|
|
108
|
+
* const disposable = fetchQuery(...).subscribe(...);
|
|
109
|
+
*
|
|
110
|
+
* // This will cancel the request if it is in-flight.
|
|
111
|
+
* disposable.dispose();
|
|
112
|
+
* ```
|
|
113
|
+
* NOTE: When using .toPromise(), the request cannot be cancelled.
|
|
28
114
|
*/
|
|
29
|
-
|
|
30
|
-
function fetchQuery<T: OperationType>(
|
|
115
|
+
function fetchQuery<TQuery: OperationType>(
|
|
31
116
|
environment: IEnvironment,
|
|
32
|
-
|
|
33
|
-
variables:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
117
|
+
query: GraphQLTaggedNode,
|
|
118
|
+
variables: VariablesOf<TQuery>,
|
|
119
|
+
options?: $ReadOnly<{|
|
|
120
|
+
fetchPolicy?: FetchQueryFetchPolicy,
|
|
121
|
+
networkCacheConfig?: CacheConfig,
|
|
122
|
+
|}>,
|
|
123
|
+
): RelayObservable<$ElementType<TQuery, 'response'>> {
|
|
124
|
+
const queryNode = getRequest(query);
|
|
125
|
+
invariant(
|
|
126
|
+
queryNode.params.operationKind === 'query',
|
|
127
|
+
'fetchQuery: Expected query operation',
|
|
128
|
+
);
|
|
129
|
+
const networkCacheConfig = {
|
|
130
|
+
force: true,
|
|
131
|
+
...options?.networkCacheConfig,
|
|
132
|
+
};
|
|
133
|
+
const operation = createOperationDescriptor(
|
|
134
|
+
queryNode,
|
|
135
|
+
variables,
|
|
136
|
+
networkCacheConfig,
|
|
137
|
+
);
|
|
138
|
+
const fetchPolicy = options?.fetchPolicy ?? 'network-only';
|
|
139
|
+
|
|
140
|
+
function readData(snapshot: Snapshot) {
|
|
141
|
+
if (snapshot.missingRequiredFields != null) {
|
|
142
|
+
reportMissingRequiredFields(environment, snapshot.missingRequiredFields);
|
|
143
|
+
}
|
|
144
|
+
return snapshot.data;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
switch (fetchPolicy) {
|
|
148
|
+
case 'network-only': {
|
|
149
|
+
return getNetworkObservable(environment, operation).map(readData);
|
|
150
|
+
}
|
|
151
|
+
case 'store-or-network': {
|
|
152
|
+
if (environment.check(operation).status === 'available') {
|
|
153
|
+
return RelayObservable.from(environment.lookup(operation.fragment)).map(
|
|
154
|
+
readData,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
return getNetworkObservable(environment, operation).map(readData);
|
|
158
|
+
}
|
|
159
|
+
default:
|
|
160
|
+
(fetchPolicy: empty);
|
|
161
|
+
throw new Error('fetchQuery: Invalid fetchPolicy ' + fetchPolicy);
|
|
39
162
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function getNetworkObservable<TQuery: OperationType>(
|
|
166
|
+
environment: IEnvironment,
|
|
167
|
+
operation: OperationDescriptor,
|
|
168
|
+
): RelayObservable<$ElementType<TQuery, 'response'>> {
|
|
169
|
+
return fetchQueryInternal
|
|
170
|
+
.fetchQuery(environment, operation)
|
|
171
|
+
.map(() => environment.lookup(operation.fragment));
|
|
45
172
|
}
|
|
46
173
|
|
|
47
174
|
module.exports = fetchQuery;
|
|
@@ -92,8 +92,7 @@ const requestCachesByEnvironment = WEAKMAP_SUPPORTED
|
|
|
92
92
|
* Cancelling requests:
|
|
93
93
|
* ====================
|
|
94
94
|
* If the subscription returned by subscribe is called while the
|
|
95
|
-
* request is in-flight,
|
|
96
|
-
* also be cancelled.
|
|
95
|
+
* request is in-flight, the request will be cancelled.
|
|
97
96
|
*
|
|
98
97
|
* ```
|
|
99
98
|
* const subscription = fetchQuery(...).subscribe(...);
|
|
@@ -233,7 +232,7 @@ function getActiveStatusObservableForCachedRequest(
|
|
|
233
232
|
|
|
234
233
|
/**
|
|
235
234
|
* If a request is active for the given query, variables and environment,
|
|
236
|
-
* this function will return a Promise that will resolve when that request
|
|
235
|
+
* this function will return a Promise that will resolve when that request
|
|
237
236
|
* stops being active (receives a final payload), and the data has been saved
|
|
238
237
|
* to the store.
|
|
239
238
|
* If no request is active, null will be returned
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its 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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
createOperationDescriptor,
|
|
17
|
+
} = require('../store/RelayModernOperationDescriptor');
|
|
18
|
+
const {getRequest} = require('./GraphQLTag');
|
|
19
|
+
|
|
20
|
+
import type {IEnvironment} from '../store/RelayStoreTypes';
|
|
21
|
+
import type {CacheConfig, OperationType} from '../util/RelayRuntimeTypes';
|
|
22
|
+
import type {GraphQLTaggedNode} from './GraphQLTag';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A helper function to fetch the results of a query. Note that results for
|
|
26
|
+
* fragment spreads are masked: fields must be explicitly listed in the query in
|
|
27
|
+
* order to be accessible in the result object.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
function fetchQuery_DEPRECATED<T: OperationType>(
|
|
31
|
+
environment: IEnvironment,
|
|
32
|
+
taggedNode: GraphQLTaggedNode,
|
|
33
|
+
variables: $PropertyType<T, 'variables'>,
|
|
34
|
+
cacheConfig?: ?CacheConfig,
|
|
35
|
+
): Promise<$PropertyType<T, 'response'>> {
|
|
36
|
+
const query = getRequest(taggedNode);
|
|
37
|
+
if (query.params.operationKind !== 'query') {
|
|
38
|
+
throw new Error('fetchQuery: Expected query operation');
|
|
39
|
+
}
|
|
40
|
+
const operation = createOperationDescriptor(query, variables, cacheConfig);
|
|
41
|
+
return environment
|
|
42
|
+
.execute({operation})
|
|
43
|
+
.map(() => environment.lookup(operation.fragment).data)
|
|
44
|
+
.toPromise();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = fetchQuery_DEPRECATED;
|