Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// early return if trying to read from cache during refetch
if (fetchPolicy === 'cache-only') {
return Promise.reject(new InvariantError(
'cache-only fetchPolicy option should not be used together with query refetch.',
));
}
// Unless the provided fetchPolicy always consults the network
// (no-cache, network-only, or cache-and-network), override it with
// network-only to force the refetch for this fetchQuery call.
if (fetchPolicy !== 'no-cache' &&
fetchPolicy !== 'cache-and-network') {
fetchPolicy = 'network-only';
}
if (!isEqual(this.variables, variables)) {
// update observable variables
this.variables = {
...this.variables,
...variables,
};
}
if (!isEqual(this.options.variables, this.variables)) {
// Update the existing options with new variables
this.options.variables = {
...this.options.variables,
...this.variables,
};
}
return this.queryManager.fetchQuery(
// Note that we're careful to fetch the value of our new container; not
// the outer container.
const previousFieldValue = deepGet(this._getNodeData(containerIdForField), fieldPath);
// For fields with sub selections, we walk into them; only leaf fields are
// directly written via _setValue. This allows us to perform minimal
// edits to the graph.
if (node.children) {
this._mergeSubgraph(referenceEdits, warnings, containerIdForField, fieldPrefixPath, fieldPath, node.children, fieldValue);
// We've hit a leaf field.
//
// Note that we must perform a _deep_ equality check here, to cover cases
// where a leaf value is a complex object.
} else if (!isEqual(fieldValue, previousFieldValue)) {
// We intentionally do not deep copy the nodeValue as Apollo will
// then perform Object.freeze anyway. So any change in the payload
// value afterward will be reflect in the graph as well.
//
// We use selection.name.value instead of payloadKey so that we
// always write to cache using real field name rather than alias
// name.
this._setValue(containerIdForField, fieldPath, fieldValue);
}
}
}
const { fetchPolicy } = this.options;
// early return if trying to read from cache during refetch
if (fetchPolicy === 'cache-only') {
return Promise.reject(
new Error(
'cache-only fetchPolicy option should not be used together with query refetch.',
),
);
}
if (!isEqual(this.variables, variables)) {
// update observable variables
this.variables = Object.assign({}, this.variables, variables);
}
if (!isEqual(this.options.variables, this.variables)) {
// Update the existing options with new variables
this.options.variables = Object.assign(
{},
this.options.variables,
this.variables,
);
}
// Override fetchPolicy for this call only
// only network-only and no-cache are safe to use
const isNetworkFetchPolicy =
fetchPolicy === 'network-only' || fetchPolicy === 'no-cache';
const combinedOptions: WatchQueryOptions = {
...this.options,
fetchPolicy: isNetworkFetchPolicy ? fetchPolicy : 'network-only',
refetch: variables => {
// If variables have not changed and not subscribed, skip refetch
if (!subscribed && isEqual(variables, observable_query.variables))
return observable_query.result();
return observable_query.refetch(variables);
},
result: () => observable_query.result(),
const setData = React.useCallback((data: TData) => {
if (!isEqual(data, prevDataRef.current)) {
prevDataRef.current = data;
setResult({ data, loading: false, error: null });
} else {
setResult(result => ({ ...result, loading: false }));
}
}, []);
function _mergeNodes(path: string[], target: ParsedQueryNode, source?: ParsedQueryNode) {
if (!source) return target;
if (!isEqual(target.args, source.args)) {
throw new ConflictingFieldsError(`parameterization mismatch`, path, [target, source]);
}
if (target.schemaName !== source.schemaName) {
throw new ConflictingFieldsError(`alias mismatch`, path, [target, source]);
}
if (!source.children) return target;
if (!target.children) {
target.children = source.children;
} else {
for (const name in source.children) {
target.children[name] = _mergeNodes([...path, name], source.children[name], target.children[name]);
}
}
if (source.hasParameterizedChildren && !target.hasParameterizedChildren) {
Query.prototype.updateObservableQuery = function (client, context) {
if (!this.observableQuery) {
this.initializeObservableQuery(client, this.props, context);
}
var newOptions = tslib_1.__assign({}, this.extractOptsFromProps(this.props), { children: null });
if (!isEqual(newOptions, this.previousOptions)) {
this.previousOptions = newOptions;
this.observableQuery.setOptions(newOptions)
.catch(function () { return null; });
}
};
Query.prototype.resubscribeToQuery = function (client) {