Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const prevVariables = this.pending
? this.pending.rawVariables
: lastVariables;
const rawVariables = mergeVariables(prevVariables, partialVariables);
let nextVariables = rawVariables;
if (prepareVariables) {
const metaRoute = RelayMetaRoute.get(
this.props.__relayContext.route.name,
);
nextVariables = prepareVariables(rawVariables, metaRoute);
validateVariables(initialVariables, nextVariables);
}
this.pending && this.pending.request.abort();
const completeProfiler = RelayProfiler.profile(
'RelayContainer.setVariables',
{
containerName,
nextVariables,
},
);
// Because the pending fetch is always canceled, we need to build a new
// set of queries that includes the updated variables and initiate a new
// fetch.
const {
querySet,
fragmentPointers,
} = this._createQuerySetAndFragmentPointers(nextVariables);
const onReadyStateChange = ErrorUtils.guard(readyState => {
...this.state.relayProp,
pendingVariables: null,
variables: nextVariables,
},
};
} else {
partialState = {
relayProp: {
...this.state.relayProp,
pendingVariables: isComplete ? null : nextVariables,
},
};
}
const mounted = this.mounted;
if (mounted) {
const updateProfiler = RelayProfiler.profile('RelayContainer.update');
relayUnstableBatchedUpdates(() => {
this.setState(partialState, () => {
updateProfiler.stop();
if (isComplete) {
completeProfiler.stop();
}
});
if (callback) {
callback.call(
// eslint-disable-next-line react/no-string-refs
this.refs.component || null,
{...readyState, mounted},
);
}
});
} else {
function profileQueue(currentQueue: Array): void {
// TODO #8783781: remove aggregate `fetchRelayQuery` profiler
let firstResultProfiler = RelayProfiler.profile('fetchRelayQuery');
currentQueue.forEach(query => {
const profiler = RelayProfiler.profile(
'fetchRelayQuery.query',
query.getQuery().getName(),
);
const onSettle = () => {
profiler.stop();
if (firstResultProfiler) {
firstResultProfiler.stop();
firstResultProfiler = null;
}
};
query
.getPromise()
.then(onSettle, onSettle)
.catch(error => {
restoreFragmentFromCache(
dataID: DataID,
fragment: RelayQuery.Fragment,
path: QueryPath,
callbacks: CacheProcessorCallbacks,
): Abortable {
const cacheManager = this._cacheManager;
invariant(
cacheManager,
'RelayStoreData: `restoreFragmentFromCache` should only be called when ' +
'cache manager is available.',
);
const changeTracker = new RelayChangeTracker();
const profile = RelayProfiler.profile(
'RelayStoreData.readFragmentFromDiskCache',
);
return restoreFragmentDataFromCache(
dataID,
fragment,
path,
this._queuedStore,
this._cachedRecords,
this._cachedRootCallMap,
cacheManager,
changeTracker,
{
onSuccess: () => {
this._handleChangedAndNewDataIDs(changeTracker.getChangeSet());
profile.stop();
callbacks.onSuccess && callbacks.onSuccess();
function runQueries(
storeData: RelayStoreData,
querySet: RelayQuerySet,
callback: ReadyStateChangeCallback,
fetchMode: FetchMode,
): Abortable {
const profiler =
fetchMode === RelayFetchMode.REFETCH
? RelayProfiler.profile('GraphQLQueryRunner.forceFetch')
: RelayProfiler.profile('GraphQLQueryRunner.primeCache');
const readyState = new RelayReadyState(callback);
const remainingFetchMap: {[queryID: string]: PendingFetch} = {};
const remainingRequiredFetchMap: {[queryID: string]: PendingFetch} = {};
function onResolved(pendingFetch: PendingFetch) {
const pendingQuery = pendingFetch.getQuery();
const pendingQueryID = pendingQuery.getID();
delete remainingFetchMap[pendingQueryID];
if (!pendingQuery.isDeferred()) {
delete remainingRequiredFetchMap[pendingQueryID];
}
if (hasItems(remainingRequiredFetchMap)) {
function runQueries(
storeData: RelayStoreData,
querySet: RelayQuerySet,
callback: ReadyStateChangeCallback,
fetchMode: FetchMode,
): Abortable {
const profiler =
fetchMode === RelayFetchMode.REFETCH
? RelayProfiler.profile('GraphQLQueryRunner.forceFetch')
: RelayProfiler.profile('GraphQLQueryRunner.primeCache');
const readyState = new RelayReadyState(callback);
const remainingFetchMap: {[queryID: string]: PendingFetch} = {};
const remainingRequiredFetchMap: {[queryID: string]: PendingFetch} = {};
function onResolved(pendingFetch: PendingFetch) {
const pendingQuery = pendingFetch.getQuery();
const pendingQueryID = pendingQuery.getID();
delete remainingFetchMap[pendingQueryID];
if (!pendingQuery.isDeferred()) {
delete remainingRequiredFetchMap[pendingQueryID];
}
if (hasItems(remainingRequiredFetchMap)) {
return;
currentQueue.forEach(query => {
const profiler = RelayProfiler.profile(
'fetchRelayQuery.query',
query.getQuery().getName(),
);
const onSettle = () => {
profiler.stop();
if (firstResultProfiler) {
firstResultProfiler.stop();
firstResultProfiler = null;
}
};
query
.getPromise()
.then(onSettle, onSettle)
.catch(error => {
setTimeout(() => {
throw error;
handleQueryPayload(
query: RelayQuery.Root,
payload: QueryPayload,
forceIndex: ?number,
): void {
const profiler = RelayProfiler.profile('RelayStoreData.handleQueryPayload');
const changeTracker = new RelayChangeTracker();
const writer = new RelayQueryWriter(
this._queuedStore,
this.getRecordWriter(),
this._queryTracker,
changeTracker,
{
forceIndex,
updateTrackedQueries: true,
},
);
writeRelayQueryPayload(writer, query, payload);
this._handleChangedAndNewDataIDs(changeTracker.getChangeSet());
profiler.stop();
}