Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const op = entry.operation.op;
const operationName = op.context.operationName as string;
const optimisticResponse = op.optimisticResponse as {[key: string]: any};
const idField = op.context.idField || "id";
if (!result || !optimisticResponse || !optimisticResponse[operationName]) {
return;
}
let clientId = optimisticResponse[operationName][idField];
if (!clientId) {
return;
}
// Ensure we dealing with string
clientId = clientId.toString();
if (isClientGeneratedId(optimisticResponse[operationName][idField])) {
queue.forEach(({ operation }) => {
if (operation.op.variables && operation.op.variables[idField] === clientId) {
operation.op.variables[idField] = result.data && result.data[operationName][idField];
}
});
}
}
}
const op = operation.op;
const operationName = op.context.operationName as string;
const optimisticResponse = op.optimisticResponse as {[key: string]: any};
const idField = op.context.idField || "id";
if (!result || !optimisticResponse || !optimisticResponse[operationName]) {
return;
}
let clientId = optimisticResponse[operationName][idField];
if (!clientId) {
return;
}
// Ensure we dealing with string
clientId = clientId.toString();
if (isClientGeneratedId(optimisticResponse[operationName][idField])) {
queue.forEach((entry) => {
if (entry.operation.op.variables && entry.operation.op.variables[idField] === clientId) {
entry.operation.op.variables[idField] = result.data && result.data[operationName][idField];
}
});
}
}
public hasClientId() {
return isClientGeneratedId(this.variables[this.idField as string]);
}