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
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
* @emails oncall+relay
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var RelayOperationTracker = require('../store/RelayOperationTracker');
|
|
14
|
+
|
|
15
|
+
function todo() {
|
|
16
|
+
throw new Error('Not implementd');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var ActorSpecificEnvironment = /*#__PURE__*/function () {
|
|
20
|
+
// Actor specific properties
|
|
21
|
+
function ActorSpecificEnvironment(config) {
|
|
22
|
+
this.actorIdentifier = config.actorIdentifier;
|
|
23
|
+
this.multiActorEnvironment = config.multiActorEnvironment;
|
|
24
|
+
this.__log = config.logFn;
|
|
25
|
+
this.requiredFieldLogger = config.requiredFieldLogger;
|
|
26
|
+
this._operationTracker = new RelayOperationTracker();
|
|
27
|
+
this._store = config.store;
|
|
28
|
+
this._network = config.network;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var _proto = ActorSpecificEnvironment.prototype;
|
|
32
|
+
|
|
33
|
+
_proto.UNSTABLE_getDefaultRenderPolicy = function UNSTABLE_getDefaultRenderPolicy() {
|
|
34
|
+
return todo();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
_proto.applyMutation = function applyMutation(optimisticConfig) {
|
|
38
|
+
return this.multiActorEnvironment.applyMutation(this.actorIdentifier, optimisticConfig);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
_proto.applyUpdate = function applyUpdate(optimisticUpdate) {
|
|
42
|
+
return this.multiActorEnvironment.applyUpdate(this.actorIdentifier, optimisticUpdate);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
_proto.check = function check(operation) {
|
|
46
|
+
return this.multiActorEnvironment.check(this.actorIdentifier, operation);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
_proto.subscribe = function subscribe(snapshot, callback) {
|
|
50
|
+
return this.multiActorEnvironment.subscribe(this.actorIdentifier, snapshot, callback);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
_proto.retain = function retain(operation) {
|
|
54
|
+
return this.multiActorEnvironment.retain(this.actorIdentifier, operation);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
_proto.commitUpdate = function commitUpdate(updater) {
|
|
58
|
+
return this.multiActorEnvironment.commitUpdate(this.actorIdentifier, updater);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Commit a payload to the environment using the given operation selector.
|
|
62
|
+
*/
|
|
63
|
+
;
|
|
64
|
+
|
|
65
|
+
_proto.commitPayload = function commitPayload(operationDescriptor, payload) {
|
|
66
|
+
return this.multiActorEnvironment.commitPayload(this.actorIdentifier, operationDescriptor, payload);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
_proto.getNetwork = function getNetwork() {
|
|
70
|
+
return this._network;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
_proto.getStore = function getStore() {
|
|
74
|
+
return this._store;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
_proto.getOperationTracker = function getOperationTracker() {
|
|
78
|
+
return this._operationTracker;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
_proto.lookup = function lookup(selector) {
|
|
82
|
+
return this.multiActorEnvironment.lookup(this.actorIdentifier, selector);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
_proto.execute = function execute(config) {
|
|
86
|
+
return this.multiActorEnvironment.execute(this.actorIdentifier, config);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
_proto.executeMutation = function executeMutation(options) {
|
|
90
|
+
return this.multiActorEnvironment.executeMutation(this.actorIdentifier, options);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
_proto.executeWithSource = function executeWithSource(options) {
|
|
94
|
+
return this.multiActorEnvironment.executeWithSource(this.actorIdentifier, options);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
_proto.isRequestActive = function isRequestActive(requestIdentifier) {
|
|
98
|
+
return this.multiActorEnvironment.isRequestActive(this.actorIdentifier, requestIdentifier);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
_proto.isServer = function isServer() {
|
|
102
|
+
return todo();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return ActorSpecificEnvironment;
|
|
106
|
+
}();
|
|
107
|
+
|
|
108
|
+
module.exports = ActorSpecificEnvironment;
|
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
* @emails oncall+relay
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
|
|
14
|
+
|
|
15
|
+
var OperationExecutor = require('../store/OperationExecutor');
|
|
16
|
+
|
|
17
|
+
var RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
|
|
18
|
+
|
|
19
|
+
var RelayModernStore = require('../store/RelayModernStore');
|
|
20
|
+
|
|
21
|
+
var RelayObservable = require('../network/RelayObservable');
|
|
22
|
+
|
|
23
|
+
var RelayPublishQueue = require('../store/RelayPublishQueue');
|
|
24
|
+
|
|
25
|
+
var RelayRecordSource = require('../store/RelayRecordSource');
|
|
26
|
+
|
|
27
|
+
var defaultGetDataID = require('../store/defaultGetDataID');
|
|
28
|
+
|
|
29
|
+
function todo(what) {
|
|
30
|
+
throw new Error("Not implementd: ".concat(what));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var MultiActorEnvironment = /*#__PURE__*/function () {
|
|
34
|
+
function MultiActorEnvironment(config) {
|
|
35
|
+
var _config$getDataID, _config$treatMissingF;
|
|
36
|
+
|
|
37
|
+
this._actorEnvironments = new Map();
|
|
38
|
+
this._createNetworkForActor = config.createNetworkForActor;
|
|
39
|
+
this._getDataID = (_config$getDataID = config.getDataID) !== null && _config$getDataID !== void 0 ? _config$getDataID : defaultGetDataID;
|
|
40
|
+
this._handlerProvider = config.handlerProvider ? config.handlerProvider : RelayDefaultHandlerProvider;
|
|
41
|
+
this._logFn = config.logFn;
|
|
42
|
+
this._operationExecutions = new Map();
|
|
43
|
+
this._requiredFieldLogger = config.requiredFieldLogger;
|
|
44
|
+
this._treatMissingFieldsAsNull = (_config$treatMissingF = config.treatMissingFieldsAsNull) !== null && _config$treatMissingF !== void 0 ? _config$treatMissingF : false;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* This method will create an actor specfic environment. It will create a new instance
|
|
48
|
+
* and store it in the internal maps. If will return a memozied version
|
|
49
|
+
* of the environment if we already created one for actor.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
var _proto = MultiActorEnvironment.prototype;
|
|
54
|
+
|
|
55
|
+
_proto.forActor = function forActor(actorIdentifier) {
|
|
56
|
+
var environment = this._actorEnvironments.get(actorIdentifier);
|
|
57
|
+
|
|
58
|
+
if (environment == null) {
|
|
59
|
+
var newEnvironment = new ActorSpecificEnvironment({
|
|
60
|
+
actorIdentifier: actorIdentifier,
|
|
61
|
+
multiActorEnvironment: this,
|
|
62
|
+
logFn: this._logFn,
|
|
63
|
+
requiredFieldLogger: this._requiredFieldLogger,
|
|
64
|
+
store: new RelayModernStore(RelayRecordSource.create()),
|
|
65
|
+
network: this._createNetworkForActor(actorIdentifier)
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
this._actorEnvironments.set(actorIdentifier, newEnvironment);
|
|
69
|
+
|
|
70
|
+
return newEnvironment;
|
|
71
|
+
} else {
|
|
72
|
+
return environment;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
_proto.check = function check(actorIdentifier, operation) {
|
|
77
|
+
return todo('check');
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
_proto.subscribe = function subscribe(actorIdentifier, snapshot, callback) {
|
|
81
|
+
return todo('subscribe');
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
_proto.retain = function retain(actorIdentifier, operation) {
|
|
85
|
+
return todo('retain');
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
_proto.applyUpdate = function applyUpdate(actorIdentifier, optimisticUpdate) {
|
|
89
|
+
return todo('applyUpdate');
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
_proto.applyMutation = function applyMutation(actorIdentifier, optimisticConfig) {
|
|
93
|
+
return todo('applyMutation');
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
_proto.commitUpdate = function commitUpdate(actorIdentifier, updater) {
|
|
97
|
+
return todo('commitUpdate');
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
_proto.commitPayload = function commitPayload(actorIdentifier, operationDescriptor, payload) {
|
|
101
|
+
return todo('commitPayload');
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
_proto.lookup = function lookup(actorIdentifier, selector) {
|
|
105
|
+
return todo('lookup');
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
_proto.execute = function execute(actorIdentifier, config) {
|
|
109
|
+
var _this = this;
|
|
110
|
+
|
|
111
|
+
var operation = config.operation,
|
|
112
|
+
updater = config.updater;
|
|
113
|
+
return RelayObservable.create(function (sink) {
|
|
114
|
+
var actorEnvironemnt = _this.forActor(actorIdentifier);
|
|
115
|
+
|
|
116
|
+
var source = actorEnvironemnt.getNetwork().execute(operation.request.node.params, operation.request.variables, operation.request.cacheConfig || {}, null);
|
|
117
|
+
var executor = OperationExecutor.execute({
|
|
118
|
+
operation: operation,
|
|
119
|
+
operationExecutions: _this._operationExecutions,
|
|
120
|
+
operationLoader: null,
|
|
121
|
+
optimisticConfig: null,
|
|
122
|
+
publishQueue: new RelayPublishQueue(actorEnvironemnt.getStore(), _this._handlerProvider, _this._getDataID),
|
|
123
|
+
reactFlightPayloadDeserializer: null,
|
|
124
|
+
reactFlightServerErrorHandler: null,
|
|
125
|
+
scheduler: null,
|
|
126
|
+
sink: sink,
|
|
127
|
+
source: source,
|
|
128
|
+
store: actorEnvironemnt.getStore(),
|
|
129
|
+
updater: updater,
|
|
130
|
+
operationTracker: actorEnvironemnt.getOperationTracker(),
|
|
131
|
+
getDataID: _this._getDataID,
|
|
132
|
+
treatMissingFieldsAsNull: _this._treatMissingFieldsAsNull,
|
|
133
|
+
shouldProcessClientComponents: false
|
|
134
|
+
});
|
|
135
|
+
return function () {
|
|
136
|
+
return executor.cancel();
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
_proto.executeMutation = function executeMutation(actorIdentifier, config) {
|
|
142
|
+
return todo('executeMutation');
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
_proto.executeWithSource = function executeWithSource(actorIdentifier, config) {
|
|
146
|
+
return todo('executeWithSource');
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
_proto.isRequestActive = function isRequestActive(actorIdentifier, requestIdentifier) {
|
|
150
|
+
return todo('isRequestActive');
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return MultiActorEnvironment;
|
|
154
|
+
}();
|
|
155
|
+
|
|
156
|
+
module.exports = MultiActorEnvironment;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
* @emails oncall+relay
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var MultiActorEnvironment = require('./MultiActorEnvironment');
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
MultiActorEnvironment: MultiActorEnvironment
|
|
17
|
+
};
|
|
@@ -14,7 +14,7 @@ var RelayModernRecord = require('../store/RelayModernRecord');
|
|
|
14
14
|
|
|
15
15
|
var RelayRecordProxy = require('./RelayRecordProxy');
|
|
16
16
|
|
|
17
|
-
var invariant = require(
|
|
17
|
+
var invariant = require('invariant');
|
|
18
18
|
|
|
19
19
|
var _require = require('../store/RelayRecordState'),
|
|
20
20
|
EXISTENT = _require.EXISTENT,
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
var RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
14
14
|
|
|
15
|
-
var invariant = require(
|
|
15
|
+
var invariant = require('invariant');
|
|
16
16
|
|
|
17
17
|
var isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
18
18
|
|
|
@@ -16,7 +16,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
16
16
|
|
|
17
17
|
var RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
18
18
|
|
|
19
|
-
var invariant = require(
|
|
19
|
+
var invariant = require('invariant');
|
|
20
20
|
|
|
21
21
|
var isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
22
22
|
|
|
@@ -18,6 +18,22 @@ var warning = require("fbjs/lib/warning");
|
|
|
18
18
|
|
|
19
19
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
20
20
|
|
|
21
|
+
var _require = require('../util/RelayConcreteNode'),
|
|
22
|
+
CONDITION = _require.CONDITION,
|
|
23
|
+
CLIENT_COMPONENT = _require.CLIENT_COMPONENT,
|
|
24
|
+
CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
|
|
25
|
+
DEFER = _require.DEFER,
|
|
26
|
+
FLIGHT_FIELD = _require.FLIGHT_FIELD,
|
|
27
|
+
FRAGMENT_SPREAD = _require.FRAGMENT_SPREAD,
|
|
28
|
+
INLINE_FRAGMENT = _require.INLINE_FRAGMENT,
|
|
29
|
+
LINKED_FIELD = _require.LINKED_FIELD,
|
|
30
|
+
LINKED_HANDLE = _require.LINKED_HANDLE,
|
|
31
|
+
MODULE_IMPORT = _require.MODULE_IMPORT,
|
|
32
|
+
SCALAR_FIELD = _require.SCALAR_FIELD,
|
|
33
|
+
SCALAR_HANDLE = _require.SCALAR_HANDLE,
|
|
34
|
+
STREAM = _require.STREAM,
|
|
35
|
+
TYPE_DISCRIMINATOR = _require.TYPE_DISCRIMINATOR;
|
|
36
|
+
|
|
21
37
|
var validateMutation = function validateMutation() {};
|
|
22
38
|
|
|
23
39
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -60,16 +76,21 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
60
76
|
|
|
61
77
|
var validateSelection = function validateSelection(optimisticResponse, selection, context) {
|
|
62
78
|
switch (selection.kind) {
|
|
63
|
-
case
|
|
79
|
+
case CONDITION:
|
|
64
80
|
validateSelections(optimisticResponse, selection.selections, context);
|
|
65
81
|
return;
|
|
66
82
|
|
|
67
|
-
case
|
|
68
|
-
case
|
|
69
|
-
|
|
83
|
+
case CLIENT_COMPONENT:
|
|
84
|
+
case FRAGMENT_SPREAD:
|
|
85
|
+
validateSelections(optimisticResponse, selection.fragment.selections, context);
|
|
86
|
+
return;
|
|
87
|
+
|
|
88
|
+
case SCALAR_FIELD:
|
|
89
|
+
case LINKED_FIELD:
|
|
90
|
+
case FLIGHT_FIELD:
|
|
70
91
|
return validateField(optimisticResponse, selection, context);
|
|
71
92
|
|
|
72
|
-
case
|
|
93
|
+
case INLINE_FRAGMENT:
|
|
73
94
|
var type = selection.type;
|
|
74
95
|
var isConcreteType = selection.abstractKey == null;
|
|
75
96
|
selection.selections.forEach(function (subselection) {
|
|
@@ -81,20 +102,20 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
81
102
|
});
|
|
82
103
|
return;
|
|
83
104
|
|
|
84
|
-
case
|
|
105
|
+
case CLIENT_EXTENSION:
|
|
85
106
|
selection.selections.forEach(function (subselection) {
|
|
86
107
|
validateSelection(optimisticResponse, subselection, context);
|
|
87
108
|
});
|
|
88
109
|
return;
|
|
89
110
|
|
|
90
|
-
case
|
|
111
|
+
case MODULE_IMPORT:
|
|
91
112
|
return validateModuleImport(context);
|
|
92
113
|
|
|
93
|
-
case
|
|
94
|
-
case
|
|
95
|
-
case
|
|
96
|
-
case
|
|
97
|
-
case
|
|
114
|
+
case LINKED_HANDLE:
|
|
115
|
+
case SCALAR_HANDLE:
|
|
116
|
+
case DEFER:
|
|
117
|
+
case STREAM:
|
|
118
|
+
case TYPE_DISCRIMINATOR:
|
|
98
119
|
{
|
|
99
120
|
// TODO(T35864292) - Add missing validations for these types
|
|
100
121
|
return;
|
|
@@ -116,14 +137,14 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
116
137
|
context.visitedPaths.add(path);
|
|
117
138
|
|
|
118
139
|
switch (field.kind) {
|
|
119
|
-
case
|
|
140
|
+
case SCALAR_FIELD:
|
|
120
141
|
if (hasOwnProperty.call(optimisticResponse, fieldName) === false) {
|
|
121
142
|
addFieldToDiff(path, context.missingDiff, true);
|
|
122
143
|
}
|
|
123
144
|
|
|
124
145
|
return;
|
|
125
146
|
|
|
126
|
-
case
|
|
147
|
+
case LINKED_FIELD:
|
|
127
148
|
var selections = field.selections;
|
|
128
149
|
|
|
129
150
|
if (optimisticResponse[fieldName] === null || hasOwnProperty.call(optimisticResponse, fieldName) && optimisticResponse[fieldName] === undefined) {
|
|
@@ -156,7 +177,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
156
177
|
}
|
|
157
178
|
}
|
|
158
179
|
|
|
159
|
-
case
|
|
180
|
+
case FLIGHT_FIELD:
|
|
160
181
|
if (optimisticResponse[fieldName] === null || hasOwnProperty.call(optimisticResponse, fieldName) && optimisticResponse[fieldName] === undefined) {
|
|
161
182
|
return;
|
|
162
183
|
}
|
|
@@ -14,7 +14,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
14
14
|
|
|
15
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
16
16
|
|
|
17
|
-
var invariant = require(
|
|
17
|
+
var invariant = require('invariant');
|
|
18
18
|
|
|
19
19
|
var stableCopy = require('../util/stableCopy');
|
|
20
20
|
|
|
@@ -53,7 +53,8 @@ var RelayQueryResponseCache = /*#__PURE__*/function () {
|
|
|
53
53
|
|
|
54
54
|
var response = this._responses.get(cacheKey);
|
|
55
55
|
|
|
56
|
-
return response != null ?
|
|
56
|
+
return response != null ? // $FlowFixMe[speculation-ambiguous]
|
|
57
|
+
(0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, response.payload), {}, {
|
|
57
58
|
extensions: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, response.payload.extensions), {}, {
|
|
58
59
|
cacheTimestamp: response.fetchTime
|
|
59
60
|
})
|
package/lib/query/GraphQLTag.js
CHANGED
package/lib/query/fetchQuery.js
CHANGED
|
@@ -4,12 +4,25 @@
|
|
|
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
|
*
|
|
8
9
|
* @format
|
|
9
10
|
*/
|
|
10
11
|
// flowlint ambiguous-object-type:error
|
|
11
12
|
'use strict';
|
|
12
13
|
|
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
15
|
+
|
|
16
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
17
|
+
|
|
18
|
+
var RelayObservable = require('../network/RelayObservable');
|
|
19
|
+
|
|
20
|
+
var fetchQueryInternal = require('./fetchQueryInternal');
|
|
21
|
+
|
|
22
|
+
var invariant = require('invariant');
|
|
23
|
+
|
|
24
|
+
var reportMissingRequiredFields = require('../util/reportMissingRequiredFields');
|
|
25
|
+
|
|
13
26
|
var _require = require('../store/RelayModernOperationDescriptor'),
|
|
14
27
|
createOperationDescriptor = _require.createOperationDescriptor;
|
|
15
28
|
|
|
@@ -17,23 +30,126 @@ var _require2 = require('./GraphQLTag'),
|
|
|
17
30
|
getRequest = _require2.getRequest;
|
|
18
31
|
|
|
19
32
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
33
|
+
* Fetches the given query and variables on the provided environment,
|
|
34
|
+
* and de-dupes identical in-flight requests.
|
|
35
|
+
*
|
|
36
|
+
* Observing a request:
|
|
37
|
+
* ====================
|
|
38
|
+
* fetchQuery returns an Observable which you can call .subscribe()
|
|
39
|
+
* on. Subscribe optionally takes an Observer, which you can provide to
|
|
40
|
+
* observe network events:
|
|
41
|
+
*
|
|
42
|
+
* ```
|
|
43
|
+
* fetchQuery(environment, query, variables).subscribe({
|
|
44
|
+
* // Called when network requests starts
|
|
45
|
+
* start: (subsctiption) => {},
|
|
46
|
+
*
|
|
47
|
+
* // Called after a payload is received and written to the local store
|
|
48
|
+
* next: (payload) => {},
|
|
49
|
+
*
|
|
50
|
+
* // Called when network requests errors
|
|
51
|
+
* error: (error) => {},
|
|
52
|
+
*
|
|
53
|
+
* // Called when network requests fully completes
|
|
54
|
+
* complete: () => {},
|
|
55
|
+
*
|
|
56
|
+
* // Called when network request is unsubscribed
|
|
57
|
+
* unsubscribe: (subscription) => {},
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* Request Promise:
|
|
62
|
+
* ================
|
|
63
|
+
* The obervable can be converted to a Promise with .toPromise(), which will
|
|
64
|
+
* resolve to a snapshot of the query data when the first response is received
|
|
65
|
+
* from the server.
|
|
66
|
+
*
|
|
67
|
+
* ```
|
|
68
|
+
* fetchQuery(environment, query, variables).toPromise().then((data) => {
|
|
69
|
+
* // ...
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* In-flight request de-duping:
|
|
74
|
+
* ============================
|
|
75
|
+
* By default, calling fetchQuery multiple times with the same
|
|
76
|
+
* environment, query and variables will not initiate a new request if a request
|
|
77
|
+
* for those same parameters is already in flight.
|
|
78
|
+
*
|
|
79
|
+
* A request is marked in-flight from the moment it starts until the moment it
|
|
80
|
+
* fully completes, regardless of error or successful completion.
|
|
81
|
+
*
|
|
82
|
+
* NOTE: If the request completes _synchronously_, calling fetchQuery
|
|
83
|
+
* a second time with the same arguments in the same tick will _NOT_ de-dupe
|
|
84
|
+
* the request given that it will no longer be in-flight.
|
|
85
|
+
*
|
|
86
|
+
*
|
|
87
|
+
* Data Retention:
|
|
88
|
+
* ===============
|
|
89
|
+
* This function will NOT retain query data, meaning that it is not guaranteed
|
|
90
|
+
* that the fetched data will remain in the Relay store after the request has
|
|
91
|
+
* completed.
|
|
92
|
+
* If you need to retain the query data outside of the network request,
|
|
93
|
+
* you need to use `environment.retain()`.
|
|
94
|
+
*
|
|
95
|
+
*
|
|
96
|
+
* Cancelling requests:
|
|
97
|
+
* ====================
|
|
98
|
+
* If the disposable returned by subscribe is called while the
|
|
99
|
+
* request is in-flight, the request will be cancelled.
|
|
100
|
+
*
|
|
101
|
+
* ```
|
|
102
|
+
* const disposable = fetchQuery(...).subscribe(...);
|
|
103
|
+
*
|
|
104
|
+
* // This will cancel the request if it is in-flight.
|
|
105
|
+
* disposable.dispose();
|
|
106
|
+
* ```
|
|
107
|
+
* NOTE: When using .toPromise(), the request cannot be cancelled.
|
|
23
108
|
*/
|
|
24
|
-
function fetchQuery(environment,
|
|
25
|
-
var
|
|
109
|
+
function fetchQuery(environment, query, variables, options) {
|
|
110
|
+
var _options$fetchPolicy;
|
|
111
|
+
|
|
112
|
+
var queryNode = getRequest(query);
|
|
113
|
+
!(queryNode.params.operationKind === 'query') ? process.env.NODE_ENV !== "production" ? invariant(false, 'fetchQuery: Expected query operation') : invariant(false) : void 0;
|
|
114
|
+
var networkCacheConfig = (0, _objectSpread2["default"])({
|
|
115
|
+
force: true
|
|
116
|
+
}, options === null || options === void 0 ? void 0 : options.networkCacheConfig);
|
|
117
|
+
var operation = createOperationDescriptor(queryNode, variables, networkCacheConfig);
|
|
118
|
+
var fetchPolicy = (_options$fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy) !== null && _options$fetchPolicy !== void 0 ? _options$fetchPolicy : 'network-only';
|
|
26
119
|
|
|
27
|
-
|
|
28
|
-
|
|
120
|
+
function readData(snapshot) {
|
|
121
|
+
if (snapshot.missingRequiredFields != null) {
|
|
122
|
+
reportMissingRequiredFields(environment, snapshot.missingRequiredFields);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return snapshot.data;
|
|
29
126
|
}
|
|
30
127
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
128
|
+
switch (fetchPolicy) {
|
|
129
|
+
case 'network-only':
|
|
130
|
+
{
|
|
131
|
+
return getNetworkObservable(environment, operation).map(readData);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
case 'store-or-network':
|
|
135
|
+
{
|
|
136
|
+
if (environment.check(operation).status === 'available') {
|
|
137
|
+
return RelayObservable.from(environment.lookup(operation.fragment)).map(readData);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return getNetworkObservable(environment, operation).map(readData);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
default:
|
|
144
|
+
fetchPolicy;
|
|
145
|
+
throw new Error('fetchQuery: Invalid fetchPolicy ' + fetchPolicy);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function getNetworkObservable(environment, operation) {
|
|
150
|
+
return fetchQueryInternal.fetchQuery(environment, operation).map(function () {
|
|
151
|
+
return environment.lookup(operation.fragment);
|
|
152
|
+
});
|
|
37
153
|
}
|
|
38
154
|
|
|
39
155
|
module.exports = fetchQuery;
|