react-relay 2.0.0-rc.2 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +2 -2
- package/lib/ReactRelayContext.js +6 -3
- package/lib/ReactRelayFragmentContainer.js +48 -46
- package/lib/ReactRelayFragmentMockRenderer.js +5 -1
- package/lib/ReactRelayPaginationContainer.js +102 -68
- package/lib/ReactRelayQueryFetcher.js +54 -28
- package/lib/ReactRelayQueryRenderer.js +28 -20
- package/lib/ReactRelayRefetchContainer.js +70 -58
- package/lib/ReactRelayTestMocker.js +56 -43
- package/lib/ReactRelayTypes.js +1 -1
- package/lib/RelayContext.js +8 -2
- package/lib/assertFragmentMap.js +9 -7
- package/lib/buildReactRelayContainer.js +32 -23
- package/lib/index.js +41 -0
- package/lib/isRelayEnvironment.js +1 -1
- package/lib/isRelayVariables.js +1 -1
- package/lib/readContext.js +7 -4
- package/package.json +4 -4
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/classic.js +0 -10
- package/compat.js +0 -10
- package/lib/ConcreteQuery.js +0 -10
- package/lib/GraphQLQueryRunner.js +0 -264
- package/lib/GraphQLRange.js +0 -1124
- package/lib/GraphQLSegment.js +0 -743
- package/lib/GraphQLStoreChangeEmitter.js +0 -141
- package/lib/GraphQLStoreQueryResolver.js +0 -288
- package/lib/GraphQLStoreRangeUtils.js +0 -126
- package/lib/QueryBuilder.js +0 -228
- package/lib/ReactRelayClassicExports.js +0 -29
- package/lib/ReactRelayCompatContainerBuilder.js +0 -175
- package/lib/ReactRelayCompatPublic.js +0 -28
- package/lib/ReactRelayContainerProfiler.js +0 -30
- package/lib/ReactRelayFragmentContainer-flowtest.js +0 -201
- package/lib/ReactRelayPaginationContainer-flowtest.js +0 -213
- package/lib/ReactRelayPublic.js +0 -29
- package/lib/ReactRelayRefetchContainer-flowtest.js +0 -191
- package/lib/RelayCacheProcessor.js +0 -196
- package/lib/RelayChangeTracker.js +0 -83
- package/lib/RelayClassicContainerUtils.js +0 -49
- package/lib/RelayClassicCore.js +0 -34
- package/lib/RelayClassicRecordState.js +0 -31
- package/lib/RelayCompatContainer.js +0 -25
- package/lib/RelayCompatEnvironment.js +0 -27
- package/lib/RelayCompatMutations.js +0 -133
- package/lib/RelayCompatPaginationContainer.js +0 -27
- package/lib/RelayCompatRefetchContainer.js +0 -27
- package/lib/RelayCompatTypes.js +0 -10
- package/lib/RelayContainer.js +0 -889
- package/lib/RelayContainerComparators.js +0 -75
- package/lib/RelayContainerProxy.js +0 -21
- package/lib/RelayDefaultNetworkLayer.js +0 -192
- package/lib/RelayEnvironment.js +0 -449
- package/lib/RelayEnvironmentTypes.js +0 -10
- package/lib/RelayFetchMode.js +0 -17
- package/lib/RelayFragmentPointer.js +0 -161
- package/lib/RelayFragmentReference.js +0 -249
- package/lib/RelayFragmentSpecResolver.js +0 -305
- package/lib/RelayGraphQLMutation.js +0 -288
- package/lib/RelayGraphQLTag.js +0 -42
- package/lib/RelayInternalTypes.js +0 -15
- package/lib/RelayInternals.js +0 -24
- package/lib/RelayMetaRoute.js +0 -35
- package/lib/RelayMockRenderer.js +0 -71
- package/lib/RelayModern-flowtest.js +0 -342
- package/lib/RelayModernFlowtest_badref.graphql.js +0 -10
- package/lib/RelayModernFlowtest_notref.graphql.js +0 -10
- package/lib/RelayModernFlowtest_user.graphql.js +0 -10
- package/lib/RelayModernFlowtest_users.graphql.js +0 -10
- package/lib/RelayMutation.js +0 -322
- package/lib/RelayMutationDebugPrinter.js +0 -47
- package/lib/RelayMutationQuery.js +0 -558
- package/lib/RelayMutationQueue.js +0 -530
- package/lib/RelayMutationRequest.js +0 -103
- package/lib/RelayMutationTracker.js +0 -113
- package/lib/RelayMutationTransaction.js +0 -92
- package/lib/RelayMutationTransactionStatus.js +0 -55
- package/lib/RelayNetworkDebug.js +0 -131
- package/lib/RelayNetworkLayer.js +0 -185
- package/lib/RelayNodeInterface.js +0 -104
- package/lib/RelayOperationDescriptor.js +0 -40
- package/lib/RelayOptimisticMutationUtils.js +0 -208
- package/lib/RelayPendingQueryTracker.js +0 -166
- package/lib/RelayPropTypes.js +0 -57
- package/lib/RelayPublic.js +0 -44
- package/lib/RelayQL.js +0 -128
- package/lib/RelayQuery.js +0 -1584
- package/lib/RelayQueryCaching.js +0 -33
- package/lib/RelayQueryConfig.js +0 -58
- package/lib/RelayQueryPath.js +0 -204
- package/lib/RelayQueryRequest.js +0 -103
- package/lib/RelayQueryTracker.js +0 -86
- package/lib/RelayQueryTransform.js +0 -91
- package/lib/RelayQueryVisitor.js +0 -93
- package/lib/RelayQueryWriter.js +0 -573
- package/lib/RelayReadyState.js +0 -83
- package/lib/RelayReadyStateRenderer.js +0 -145
- package/lib/RelayRecord.js +0 -75
- package/lib/RelayRecordStatusMap.js +0 -57
- package/lib/RelayRecordStore.js +0 -433
- package/lib/RelayRecordWriter.js +0 -601
- package/lib/RelayRefQueryDescriptor.js +0 -27
- package/lib/RelayRenderer.js +0 -268
- package/lib/RelayRootContainer.js +0 -125
- package/lib/RelayRoute.js +0 -92
- package/lib/RelayRouteFragment.js +0 -44
- package/lib/RelaySelector.js +0 -201
- package/lib/RelayShallowMock.js +0 -69
- package/lib/RelayStaticContainer.js +0 -38
- package/lib/RelayStore.js +0 -12
- package/lib/RelayStoreConstants.js +0 -20
- package/lib/RelayStoreData.js +0 -660
- package/lib/RelayTaskQueue.js +0 -189
- package/lib/RelayTypes.js +0 -13
- package/lib/RelayVariable.js +0 -32
- package/lib/RelayVariables.js +0 -92
- package/lib/buildRQL.js +0 -160
- package/lib/callsFromGraphQL.js +0 -74
- package/lib/callsToGraphQL.js +0 -34
- package/lib/checkRelayQueryData.js +0 -250
- package/lib/createRelayQuery.js +0 -17
- package/lib/dedent.js +0 -49
- package/lib/diffRelayQuery.js +0 -757
- package/lib/directivesToGraphQL.js +0 -39
- package/lib/filterRelayQuery.js +0 -29
- package/lib/findRelayQueryLeaves.js +0 -293
- package/lib/flattenRelayQuery.js +0 -121
- package/lib/flattenSplitRelayQueries.js +0 -44
- package/lib/forEachRootCallArg.js +0 -40
- package/lib/fromGraphQL.js +0 -48
- package/lib/generateClientEdgeID.js +0 -22
- package/lib/generateClientID.js +0 -27
- package/lib/generateConcreteFragmentID.js +0 -30
- package/lib/generateForceIndex.js +0 -24
- package/lib/generateRQLFieldAlias.js +0 -39
- package/lib/getRangeBehavior.js +0 -58
- package/lib/getRelayQueries.js +0 -83
- package/lib/intersectRelayQuery.js +0 -149
- package/lib/isClassicRelayContext.js +0 -20
- package/lib/isClassicRelayEnvironment.js +0 -20
- package/lib/isCompatibleRelayFragmentType.js +0 -27
- package/lib/isRelayContainer.js +0 -16
- package/lib/makeLegacyStringishComponentRef.js +0 -52
- package/lib/printRelayOSSQuery.js +0 -329
- package/lib/printRelayQuery.js +0 -26
- package/lib/rangeOperationToMetadataKey.js +0 -25
- package/lib/readRelayQueryData.js +0 -551
- package/lib/relayUnstableBatchedUpdates.js +0 -12
- package/lib/relayUnstableBatchedUpdates.native.js +0 -11
- package/lib/restoreRelayCacheData.js +0 -188
- package/lib/serializeRelayQueryCall.js +0 -42
- package/lib/splitDeferredRelayQueries.js +0 -298
- package/lib/stableStringify.js +0 -85
- package/lib/testEditDistance.js +0 -112
- package/lib/throwFailedPromise.js +0 -26
- package/lib/toGraphQL.js +0 -94
- package/lib/transformRelayQueryPayload.js +0 -145
- package/lib/validateMutationConfig.js +0 -117
- package/lib/validateRelayReadQuery.js +0 -112
- package/lib/writeRelayQueryPayload.js +0 -44
- package/lib/writeRelayUpdatePayload.js +0 -513
- package/react-relay-classic.js +0 -4
- package/react-relay-classic.min.js +0 -9
- package/react-relay-compat.js +0 -4
- package/react-relay-compat.min.js +0 -9
@@ -1,141 +0,0 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
/**
|
13
|
-
* Asynchronous change emitter for nodes stored in the Relay cache.
|
14
|
-
*
|
15
|
-
* Changes are produced by `RelayStoreData` after writing query and mutation
|
16
|
-
* payloads into the store and consumed by `GraphQLStoreQueryResolver`, which
|
17
|
-
* subscribes to all records that are part of an active query result set.
|
18
|
-
*
|
19
|
-
* @internal
|
20
|
-
*/
|
21
|
-
var GraphQLStoreChangeEmitter =
|
22
|
-
/*#__PURE__*/
|
23
|
-
function () {
|
24
|
-
// Should be GraphQLStoreRangeUtils
|
25
|
-
function GraphQLStoreChangeEmitter(rangeData) {
|
26
|
-
this._batchUpdate = function (callback) {
|
27
|
-
return callback();
|
28
|
-
};
|
29
|
-
|
30
|
-
this._executingIDs = {};
|
31
|
-
this._rangeData = rangeData;
|
32
|
-
this._scheduledIDs = null;
|
33
|
-
this._subscribers = [];
|
34
|
-
}
|
35
|
-
|
36
|
-
var _proto = GraphQLStoreChangeEmitter.prototype;
|
37
|
-
|
38
|
-
_proto.addListenerForIDs = function addListenerForIDs(ids, callback) {
|
39
|
-
var _this = this;
|
40
|
-
|
41
|
-
var subscribedIDs = ids.map(function (id) {
|
42
|
-
return _this._getBroadcastID(id);
|
43
|
-
});
|
44
|
-
var index = this._subscribers.length;
|
45
|
-
|
46
|
-
this._subscribers.push({
|
47
|
-
subscribedIDs: subscribedIDs,
|
48
|
-
callback: callback
|
49
|
-
});
|
50
|
-
|
51
|
-
return {
|
52
|
-
remove: function remove() {
|
53
|
-
delete _this._subscribers[index];
|
54
|
-
}
|
55
|
-
};
|
56
|
-
};
|
57
|
-
|
58
|
-
_proto.broadcastChangeForID = function broadcastChangeForID(id) {
|
59
|
-
var _this2 = this;
|
60
|
-
|
61
|
-
var scheduledIDs = this._scheduledIDs;
|
62
|
-
|
63
|
-
if (scheduledIDs == null) {
|
64
|
-
require("fbjs/lib/resolveImmediate")(function () {
|
65
|
-
return _this2._processBroadcasts();
|
66
|
-
});
|
67
|
-
|
68
|
-
scheduledIDs = this._scheduledIDs = {};
|
69
|
-
} // Record index of the last subscriber so we do not later unintentionally
|
70
|
-
// invoke callbacks that were subscribed after this broadcast.
|
71
|
-
|
72
|
-
|
73
|
-
scheduledIDs[this._getBroadcastID(id)] = this._subscribers.length - 1;
|
74
|
-
};
|
75
|
-
|
76
|
-
_proto.injectBatchingStrategy = function injectBatchingStrategy(batchStrategy) {
|
77
|
-
this._batchUpdate = batchStrategy;
|
78
|
-
};
|
79
|
-
|
80
|
-
_proto._processBroadcasts = function _processBroadcasts() {
|
81
|
-
var _this3 = this;
|
82
|
-
|
83
|
-
if (this._scheduledIDs) {
|
84
|
-
this._executingIDs = this._scheduledIDs;
|
85
|
-
this._scheduledIDs = null;
|
86
|
-
|
87
|
-
this._batchUpdate(function () {
|
88
|
-
return _this3._processSubscribers();
|
89
|
-
});
|
90
|
-
}
|
91
|
-
};
|
92
|
-
/**
|
93
|
-
* Exposed for profiling reasons.
|
94
|
-
* @private
|
95
|
-
*/
|
96
|
-
|
97
|
-
|
98
|
-
_proto._processSubscribers = function _processSubscribers() {
|
99
|
-
var _this4 = this;
|
100
|
-
|
101
|
-
this._subscribers.forEach(function (subscriber, subscriberIndex) {
|
102
|
-
return _this4._processSubscriber(subscriber, subscriberIndex);
|
103
|
-
});
|
104
|
-
};
|
105
|
-
|
106
|
-
_proto._processSubscriber = function _processSubscriber(_ref, subscriberIndex) {
|
107
|
-
var subscribedIDs = _ref.subscribedIDs,
|
108
|
-
callback = _ref.callback;
|
109
|
-
|
110
|
-
for (var broadcastID in this._executingIDs) {
|
111
|
-
if (this._executingIDs.hasOwnProperty(broadcastID)) {
|
112
|
-
var broadcastIndex = this._executingIDs[broadcastID];
|
113
|
-
|
114
|
-
if (broadcastIndex < subscriberIndex) {
|
115
|
-
// Callback was subscribed after this particular broadcast.
|
116
|
-
break;
|
117
|
-
}
|
118
|
-
|
119
|
-
if (subscribedIDs.indexOf(broadcastID) >= 0) {
|
120
|
-
require("fbjs/lib/ErrorUtils").applyWithGuard(callback, null, null, null, 'GraphQLStoreChangeEmitter');
|
121
|
-
|
122
|
-
break;
|
123
|
-
}
|
124
|
-
}
|
125
|
-
}
|
126
|
-
};
|
127
|
-
/**
|
128
|
-
* Ranges publish events for the entire range, not the specific view of that
|
129
|
-
* range. For example, if "client:1" is a range, the event is on "client:1",
|
130
|
-
* not "client:1_first(5)".
|
131
|
-
*/
|
132
|
-
|
133
|
-
|
134
|
-
_proto._getBroadcastID = function _getBroadcastID(id) {
|
135
|
-
return this._rangeData.getCanonicalClientID(id);
|
136
|
-
};
|
137
|
-
|
138
|
-
return GraphQLStoreChangeEmitter;
|
139
|
-
}();
|
140
|
-
|
141
|
-
module.exports = GraphQLStoreChangeEmitter;
|
@@ -1,288 +0,0 @@
|
|
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
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
/**
|
13
|
-
* @internal
|
14
|
-
*
|
15
|
-
* Resolves data from fragment pointers.
|
16
|
-
*
|
17
|
-
* The supplied `callback` will be invoked whenever data returned by the last
|
18
|
-
* invocation to `resolve` has changed.
|
19
|
-
*/
|
20
|
-
var GraphQLStoreQueryResolver =
|
21
|
-
/*#__PURE__*/
|
22
|
-
function () {
|
23
|
-
function GraphQLStoreQueryResolver(storeData, fragment, callback) {
|
24
|
-
this.dispose();
|
25
|
-
this._callback = callback;
|
26
|
-
this._fragment = fragment;
|
27
|
-
this._resolver = null;
|
28
|
-
this._storeData = storeData;
|
29
|
-
}
|
30
|
-
/**
|
31
|
-
* disposes the resolver's internal state such that future `resolve()` results
|
32
|
-
* will not be `===` to previous results, and unsubscribes any subscriptions.
|
33
|
-
*/
|
34
|
-
|
35
|
-
|
36
|
-
var _proto = GraphQLStoreQueryResolver.prototype;
|
37
|
-
|
38
|
-
_proto.dispose = function dispose() {
|
39
|
-
if (this._resolver) {
|
40
|
-
this._resolver.dispose();
|
41
|
-
}
|
42
|
-
};
|
43
|
-
|
44
|
-
_proto.resolve = function resolve(fragment, dataIDs) {
|
45
|
-
// Warn but don't crash if resolved with the wrong fragment.
|
46
|
-
if (this._fragment.getConcreteFragmentID() !== fragment.getConcreteFragmentID()) {
|
47
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'GraphQLStoreQueryResolver: Expected `resolve` to be called with the ' + 'same concrete fragment as the constructor. The resolver was created ' + 'with fragment `%s` but resolved with fragment `%s`.', this._fragment.getDebugName(), fragment.getDebugName()) : void 0;
|
48
|
-
} // Rather than crash on mismatched plurality of fragment/ids just warn
|
49
|
-
// and resolve as if the fragment's pluarity matched the format of the ids.
|
50
|
-
// Note that the inverse - attempt to resolve based on fragment plurarity -
|
51
|
-
// doesn't work because there's no way convert plural ids to singular w/o
|
52
|
-
// losing data.
|
53
|
-
|
54
|
-
|
55
|
-
if (Array.isArray(dataIDs)) {
|
56
|
-
// Fragment should be plural if data is pluaral.
|
57
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(fragment.isPlural(), 'GraphQLStoreQueryResolver: Expected id/fragment plurality to be ' + 'consistent: got plural ids for singular fragment `%s`.', fragment.getDebugName()) : void 0;
|
58
|
-
var resolver = this._resolver;
|
59
|
-
|
60
|
-
if (resolver instanceof GraphQLStoreSingleQueryResolver) {
|
61
|
-
resolver.dispose();
|
62
|
-
resolver = null;
|
63
|
-
}
|
64
|
-
|
65
|
-
if (!resolver) {
|
66
|
-
resolver = new GraphQLStorePluralQueryResolver(this._storeData, this._callback);
|
67
|
-
}
|
68
|
-
|
69
|
-
this._resolver = resolver;
|
70
|
-
return resolver.resolve(fragment, dataIDs);
|
71
|
-
} else {
|
72
|
-
// Fragment should be singular if data is singular.
|
73
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(!fragment.isPlural(), 'GraphQLStoreQueryResolver: Expected id/fragment plurality to be ' + 'consistent: got a singular id for plural fragment `%s`.', fragment.getDebugName()) : void 0;
|
74
|
-
var _resolver = this._resolver;
|
75
|
-
|
76
|
-
if (_resolver instanceof GraphQLStorePluralQueryResolver) {
|
77
|
-
_resolver.dispose();
|
78
|
-
|
79
|
-
_resolver = null;
|
80
|
-
}
|
81
|
-
|
82
|
-
if (!_resolver) {
|
83
|
-
_resolver = new GraphQLStoreSingleQueryResolver(this._storeData, this._callback);
|
84
|
-
}
|
85
|
-
|
86
|
-
this._resolver = _resolver;
|
87
|
-
return _resolver.resolve(fragment, dataIDs);
|
88
|
-
}
|
89
|
-
};
|
90
|
-
|
91
|
-
return GraphQLStoreQueryResolver;
|
92
|
-
}();
|
93
|
-
/**
|
94
|
-
* Resolves plural fragments.
|
95
|
-
*/
|
96
|
-
|
97
|
-
|
98
|
-
var GraphQLStorePluralQueryResolver =
|
99
|
-
/*#__PURE__*/
|
100
|
-
function () {
|
101
|
-
function GraphQLStorePluralQueryResolver(storeData, callback) {
|
102
|
-
this.dispose();
|
103
|
-
this._callback = callback;
|
104
|
-
this._storeData = storeData;
|
105
|
-
}
|
106
|
-
|
107
|
-
var _proto2 = GraphQLStorePluralQueryResolver.prototype;
|
108
|
-
|
109
|
-
_proto2.dispose = function dispose() {
|
110
|
-
if (this._resolvers) {
|
111
|
-
this._resolvers.forEach(function (resolver) {
|
112
|
-
return resolver.dispose();
|
113
|
-
});
|
114
|
-
}
|
115
|
-
|
116
|
-
this._resolvers = [];
|
117
|
-
this._results = [];
|
118
|
-
};
|
119
|
-
/**
|
120
|
-
* Resolves a plural fragment pointer into an array of records.
|
121
|
-
*
|
122
|
-
* If the data, order, and number of resolved records has not changed since
|
123
|
-
* the last call to `resolve`, the same array will be returned. Otherwise, a
|
124
|
-
* new array will be returned.
|
125
|
-
*/
|
126
|
-
|
127
|
-
|
128
|
-
_proto2.resolve = function resolve(fragment, nextIDs) {
|
129
|
-
var prevResults = this._results;
|
130
|
-
var nextResults;
|
131
|
-
var prevLength = prevResults.length;
|
132
|
-
var nextLength = nextIDs.length;
|
133
|
-
var resolvers = this._resolvers; // Ensure that we have exactly `nextLength` resolvers.
|
134
|
-
|
135
|
-
while (resolvers.length < nextLength) {
|
136
|
-
resolvers.push(new GraphQLStoreSingleQueryResolver(this._storeData, this._callback));
|
137
|
-
}
|
138
|
-
|
139
|
-
while (resolvers.length > nextLength) {
|
140
|
-
resolvers.pop().dispose();
|
141
|
-
} // Allocate `nextResults` if and only if results have changed.
|
142
|
-
|
143
|
-
|
144
|
-
if (prevLength !== nextLength) {
|
145
|
-
nextResults = [];
|
146
|
-
}
|
147
|
-
|
148
|
-
for (var ii = 0; ii < nextLength; ii++) {
|
149
|
-
var nextResult = resolvers[ii].resolve(fragment, nextIDs[ii]);
|
150
|
-
|
151
|
-
if (nextResults || ii >= prevLength || nextResult !== prevResults[ii]) {
|
152
|
-
nextResults = nextResults || prevResults.slice(0, ii);
|
153
|
-
nextResults.push(nextResult);
|
154
|
-
}
|
155
|
-
}
|
156
|
-
|
157
|
-
if (nextResults) {
|
158
|
-
this._results = nextResults;
|
159
|
-
}
|
160
|
-
|
161
|
-
return this._results;
|
162
|
-
};
|
163
|
-
|
164
|
-
return GraphQLStorePluralQueryResolver;
|
165
|
-
}();
|
166
|
-
/**
|
167
|
-
* Resolves non-plural fragments.
|
168
|
-
*/
|
169
|
-
|
170
|
-
|
171
|
-
var GraphQLStoreSingleQueryResolver =
|
172
|
-
/*#__PURE__*/
|
173
|
-
function () {
|
174
|
-
function GraphQLStoreSingleQueryResolver(storeData, callback) {
|
175
|
-
this.dispose();
|
176
|
-
this._callback = callback;
|
177
|
-
this._storeData = storeData;
|
178
|
-
this._subscribedIDs = {};
|
179
|
-
}
|
180
|
-
|
181
|
-
var _proto3 = GraphQLStoreSingleQueryResolver.prototype;
|
182
|
-
|
183
|
-
_proto3.dispose = function dispose() {
|
184
|
-
if (this._subscription) {
|
185
|
-
this._subscription.remove();
|
186
|
-
}
|
187
|
-
|
188
|
-
this._hasDataChanged = false;
|
189
|
-
this._fragment = null;
|
190
|
-
this._result = null;
|
191
|
-
this._resultID = null;
|
192
|
-
this._subscription = null;
|
193
|
-
this._subscribedIDs = {};
|
194
|
-
};
|
195
|
-
/**
|
196
|
-
* Resolves data for a single fragment pointer.
|
197
|
-
*/
|
198
|
-
|
199
|
-
|
200
|
-
_proto3.resolve = function resolve(nextFragment, nextID) {
|
201
|
-
var prevFragment = this._fragment;
|
202
|
-
var prevID = this._resultID;
|
203
|
-
var nextResult;
|
204
|
-
var prevResult = this._result;
|
205
|
-
var subscribedIDs;
|
206
|
-
|
207
|
-
if (prevFragment != null && prevID != null && this._getCanonicalID(prevID) === this._getCanonicalID(nextID)) {
|
208
|
-
if (prevID !== nextID || this._hasDataChanged || !nextFragment.isEquivalent(prevFragment)) {
|
209
|
-
// same canonical ID,
|
210
|
-
// but the data, call(s), route, and/or variables have changed
|
211
|
-
var _this$_resolveFragmen = this._resolveFragment(nextFragment, nextID);
|
212
|
-
|
213
|
-
nextResult = _this$_resolveFragmen[0];
|
214
|
-
subscribedIDs = _this$_resolveFragmen[1];
|
215
|
-
nextResult = require("relay-runtime").recycleNodesInto(prevResult, nextResult);
|
216
|
-
} else {
|
217
|
-
// same id, route, variables, and data
|
218
|
-
nextResult = prevResult;
|
219
|
-
}
|
220
|
-
} else {
|
221
|
-
// Pointer has a different ID or is/was fake data.
|
222
|
-
var _this$_resolveFragmen2 = this._resolveFragment(nextFragment, nextID);
|
223
|
-
|
224
|
-
nextResult = _this$_resolveFragmen2[0];
|
225
|
-
subscribedIDs = _this$_resolveFragmen2[1];
|
226
|
-
} // update subscriptions whenever results change
|
227
|
-
|
228
|
-
|
229
|
-
if (prevResult !== nextResult) {
|
230
|
-
if (this._subscription) {
|
231
|
-
this._subscription.remove();
|
232
|
-
|
233
|
-
this._subscription = null;
|
234
|
-
}
|
235
|
-
|
236
|
-
if (subscribedIDs) {
|
237
|
-
// always subscribe to the root ID
|
238
|
-
subscribedIDs[nextID] = true;
|
239
|
-
|
240
|
-
var changeEmitter = this._storeData.getChangeEmitter();
|
241
|
-
|
242
|
-
this._subscription = changeEmitter.addListenerForIDs(Object.keys(subscribedIDs), this._handleChange.bind(this));
|
243
|
-
this._subscribedIDs = subscribedIDs;
|
244
|
-
}
|
245
|
-
|
246
|
-
this._resultID = nextID;
|
247
|
-
this._result = nextResult;
|
248
|
-
}
|
249
|
-
|
250
|
-
this._hasDataChanged = false;
|
251
|
-
this._fragment = nextFragment;
|
252
|
-
return this._result;
|
253
|
-
};
|
254
|
-
/**
|
255
|
-
* Ranges publish events for the entire range, not the specific view of that
|
256
|
-
* range. For example, if "client:1" is a range, the event is on "client:1",
|
257
|
-
* not "client:1_first(5)".
|
258
|
-
*/
|
259
|
-
|
260
|
-
|
261
|
-
_proto3._getCanonicalID = function _getCanonicalID(id) {
|
262
|
-
return this._storeData.getRangeData().getCanonicalClientID(id);
|
263
|
-
};
|
264
|
-
|
265
|
-
_proto3._handleChange = function _handleChange() {
|
266
|
-
if (!this._hasDataChanged) {
|
267
|
-
this._hasDataChanged = true;
|
268
|
-
|
269
|
-
this._callback();
|
270
|
-
}
|
271
|
-
};
|
272
|
-
|
273
|
-
_proto3._resolveFragment = function _resolveFragment(fragment, dataID) {
|
274
|
-
var _readRelayQueryData = require("./readRelayQueryData")(this._storeData, fragment, dataID),
|
275
|
-
data = _readRelayQueryData.data,
|
276
|
-
dataIDs = _readRelayQueryData.dataIDs;
|
277
|
-
|
278
|
-
return [data, dataIDs];
|
279
|
-
};
|
280
|
-
|
281
|
-
return GraphQLStoreSingleQueryResolver;
|
282
|
-
}();
|
283
|
-
|
284
|
-
require("relay-runtime").RelayProfiler.instrumentMethods(GraphQLStoreQueryResolver.prototype, {
|
285
|
-
resolve: 'GraphQLStoreQueryResolver.resolve'
|
286
|
-
});
|
287
|
-
|
288
|
-
module.exports = GraphQLStoreQueryResolver;
|
@@ -1,126 +0,0 @@
|
|
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
|
-
* @format
|
8
|
-
*/
|
9
|
-
'use strict';
|
10
|
-
|
11
|
-
/**
|
12
|
-
* Utilities used by GraphQLStore for storing ranges
|
13
|
-
*
|
14
|
-
* GraphQLStore stores all of the parts of a range in a single GraphQLRange
|
15
|
-
* object. For example, `node(4808495){friends.first(5){id,name}}` might be
|
16
|
-
* stored similar to this (pseudo-code):
|
17
|
-
*
|
18
|
-
* "4808495": {
|
19
|
-
* "friends": { __dataID__: "client:1" }
|
20
|
-
* },
|
21
|
-
* "client:1": {
|
22
|
-
* "nodes": new GraphQLRange(...) // all friends, not just the first 5
|
23
|
-
* }
|
24
|
-
*
|
25
|
-
* and when that query is run, the store would return a result pointing at
|
26
|
-
* a specific part of the range, encoded into the data ID:
|
27
|
-
*
|
28
|
-
* {
|
29
|
-
* "4808495": {
|
30
|
-
* "friends": { __dataID__: "client:1_first(5)" }
|
31
|
-
* }
|
32
|
-
* }
|
33
|
-
*
|
34
|
-
* That "client:1_first(5)" ID can then be used to query for the first 5
|
35
|
-
* friends.
|
36
|
-
*
|
37
|
-
* @internal
|
38
|
-
*/
|
39
|
-
var GraphQLStoreRangeUtils =
|
40
|
-
/*#__PURE__*/
|
41
|
-
function () {
|
42
|
-
function GraphQLStoreRangeUtils() {
|
43
|
-
this._rangeData = {};
|
44
|
-
this._rangeDataKeyMap = {};
|
45
|
-
}
|
46
|
-
/**
|
47
|
-
* Returns a token that can be parsed using parseRangeClientID to recover
|
48
|
-
* the attributes needed to retrieve the corresponding items from a
|
49
|
-
* GraphQLRange.
|
50
|
-
*
|
51
|
-
* @param {array<*>} calls
|
52
|
-
* @param {object} callValues
|
53
|
-
* @param {string} dataID
|
54
|
-
* @return {string}
|
55
|
-
*/
|
56
|
-
|
57
|
-
|
58
|
-
var _proto = GraphQLStoreRangeUtils.prototype;
|
59
|
-
|
60
|
-
_proto.getClientIDForRangeWithID = function getClientIDForRangeWithID(calls, callValues, dataID) {
|
61
|
-
var callsAsString = require("./callsFromGraphQL")(calls, callValues).map(function (call) {
|
62
|
-
return require("./serializeRelayQueryCall")(call).substring(1);
|
63
|
-
}).join(',');
|
64
|
-
|
65
|
-
var key = dataID + '_' + callsAsString;
|
66
|
-
var edge = this._rangeData[key];
|
67
|
-
|
68
|
-
if (!edge) {
|
69
|
-
this._rangeData[key] = {
|
70
|
-
dataID: dataID,
|
71
|
-
calls: calls,
|
72
|
-
callValues: callValues
|
73
|
-
};
|
74
|
-
var rangeDataKeys = this._rangeDataKeyMap[dataID];
|
75
|
-
|
76
|
-
if (!rangeDataKeys) {
|
77
|
-
this._rangeDataKeyMap[dataID] = rangeDataKeys = [];
|
78
|
-
}
|
79
|
-
|
80
|
-
rangeDataKeys.push(key);
|
81
|
-
}
|
82
|
-
|
83
|
-
return key;
|
84
|
-
};
|
85
|
-
/**
|
86
|
-
* Parses an ID back into its data ID and calls
|
87
|
-
*
|
88
|
-
* @param {string} rangeSpecificClientID
|
89
|
-
* @return {?object}
|
90
|
-
*/
|
91
|
-
|
92
|
-
|
93
|
-
_proto.parseRangeClientID = function parseRangeClientID(rangeSpecificClientID) {
|
94
|
-
return this._rangeData[rangeSpecificClientID] || null;
|
95
|
-
};
|
96
|
-
/**
|
97
|
-
* If given the client id for a range view, returns the canonical client id
|
98
|
-
* for the entire range. e.g. converts "client:1_first(5)" to "client:1".
|
99
|
-
* Otherwise returns the input.
|
100
|
-
*
|
101
|
-
* @param {string} dataID
|
102
|
-
* @return {string}
|
103
|
-
*/
|
104
|
-
|
105
|
-
|
106
|
-
_proto.getCanonicalClientID = function getCanonicalClientID(dataID) {
|
107
|
-
return this._rangeData[dataID] ? this._rangeData[dataID].dataID : dataID;
|
108
|
-
};
|
109
|
-
|
110
|
-
_proto.removeRecord = function removeRecord(dataID) {
|
111
|
-
var _this = this;
|
112
|
-
|
113
|
-
var rangeDataKeys = this._rangeDataKeyMap[dataID];
|
114
|
-
|
115
|
-
if (rangeDataKeys) {
|
116
|
-
rangeDataKeys.forEach(function (key) {
|
117
|
-
delete _this._rangeData[key];
|
118
|
-
});
|
119
|
-
delete this._rangeDataKeyMap[dataID];
|
120
|
-
}
|
121
|
-
};
|
122
|
-
|
123
|
-
return GraphQLStoreRangeUtils;
|
124
|
-
}();
|
125
|
-
|
126
|
-
module.exports = GraphQLStoreRangeUtils;
|