Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function addPreviousResultToIdValues(value: any, previousResult: any): any {
// If the value is an `IdValue`, add the previous result to it whether or not that
// `previousResult` is undefined.
//
// If the value is an array, recurse over each item trying to add the `previousResult` for that
// item.
if (isIdValue(value)) {
return {
...value,
previousResult,
};
} else if (Array.isArray(value)) {
const idToPreviousResult: { [id: string]: any } = {};
// If the previous result was an array, we want to build up our map of ids to previous results
// using the private `ID_KEY` property that is added in `resultMapper`.
if (Array.isArray(previousResult)) {
previousResult.forEach(item => {
// item can be null
if (item && item[ID_KEY]) {
idToPreviousResult[item[ID_KEY]] = item;
}
});
export function assertIdValue(idValue: IdValue) {
invariant(isIdValue(idValue), `\
Encountered a sub-selection on the query, but the store doesn't have \
an object reference. This should never happen during normal use unless you have custom code \
that is directly manipulating the store; please file an issue.`);
}
export function assertIdValue(idValue) {
if (!isIdValue(idValue)) {
throw new Error("Encountered a sub-selection on the query, but the store doesn't have an object reference. This should never happen during normal use unless you have custom code that is directly manipulating the store; please file an issue.");
}
}
function addPreviousResultToIdValues(value, previousResult) {
function assertSelectionSetForIdValue(
field: FieldNode,
value: any,
) {
if (!field.selectionSet && isIdValue(value)) {
throw new InvariantError(
`Missing selection set for object of type ${
value.typename
} returned for query field ${field.name.value}`
);
}
}
export function assertIdValue(idValue: IdValue) {
if (!isIdValue(idValue)) {
throw new Error(`Encountered a sub-selection on the query, but the store doesn't have \
an object reference. This should never happen during normal use unless you have custom code \
that is directly manipulating the store; please file an issue.`);
}
}
Object.keys(generated).forEach(function (key) {
var value = generated[key];
var realValue = real[key];
if (isIdValue(value) && isGeneratedId(value.id) && isIdValue(realValue)) {
mergeWithGenerated(value.id, realValue.id, cache);
}
cache.delete(generatedKey);
cache.set(realKey, __assign({}, generated, real));
});
}
Object.keys(generated).forEach(key => {
const value = generated[key];
const realValue = real[key];
if (
isIdValue(value) &&
isGeneratedId(value.id) &&
isIdValue(realValue) &&
!isEqual(value, realValue) &&
mergeWithGenerated(value.id, realValue.id, cache)
) {
madeChanges = true;
}
});
writeSelectionSetToStore({
dataId: valueDataId,
result: value,
selectionSet: field.selectionSet,
context: context,
});
}
storeValue = {
type: 'id',
id: valueDataId,
generated: generated,
};
storeObject = store.get(dataId);
if (storeObject && storeObject[storeFieldName] !== storeValue) {
var escapedId = storeObject[storeFieldName];
if (isIdValue(storeValue) &&
storeValue.generated &&
isIdValue(escapedId) &&
!escapedId.generated) {
throw new Error("Store error: the application attempted to write an object with no provided id" +
(" but the store already contains an id of " + escapedId.id + " for this object. The selectionSet") +
" that was trying to be written is:\n" +
print(field));
}
if (isIdValue(escapedId) && escapedId.generated) {
generatedKey = escapedId.id;
shouldMerge = true;
}
}
}
var newStoreObj = __assign({}, store.get(dataId), (_b = {}, _b[storeFieldName] = storeValue, _b));
if (shouldMerge) {
id: valueDataId,
generated: generated,
};
storeObject = store.get(dataId);
if (storeObject && storeObject[storeFieldName] !== storeValue) {
var escapedId = storeObject[storeFieldName];
if (isIdValue(storeValue) &&
storeValue.generated &&
isIdValue(escapedId) &&
!escapedId.generated) {
throw new Error("Store error: the application attempted to write an object with no provided id" +
(" but the store already contains an id of " + escapedId.id + " for this object. The selectionSet") +
" that was trying to be written is:\n" +
print(field));
}
if (isIdValue(escapedId) && escapedId.generated) {
generatedKey = escapedId.id;
shouldMerge = true;
}
}
}
var newStoreObj = __assign({}, store.get(dataId), (_b = {}, _b[storeFieldName] = storeValue, _b));
if (shouldMerge) {
mergeWithGenerated(generatedKey, storeValue.id, store);
}
storeObject = store.get(dataId);
if (!storeObject || storeValue !== storeObject[storeFieldName]) {
store.set(dataId, newStoreObj);
}
var _b;
}
function processArrayValue(value, generatedId, selectionSet, context) {