mirror of
https://github.com/status-im/sourcecred.git
synced 2025-02-18 15:38:10 +00:00
mirror: add helper to register nullable node results (#889)
Summary: As <https://github.com/sourcecred/sourcecred/pull/883/files#r219648511>. It is somewhat unfortunate that this mixes a command with a query, but the concession is acceptable in this instance, I think. Test Plan: Existing unit tests suffice, retaining full coverage. wchargin-branch: mirror-register-node-field-results
This commit is contained in:
parent
28c4e497fb
commit
3257df63fe
@ -362,6 +362,31 @@ export class Mirror {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register an object corresponding to the provided `NodeFieldResult`,
|
||||||
|
* if any, returning the object's ID. If the provided value is `null`,
|
||||||
|
* no action is taken, no error is thrown, and `null` is returned.
|
||||||
|
*
|
||||||
|
* As with `registerObject`, an error is thrown if an object by the
|
||||||
|
* given ID already exists with a different typename.
|
||||||
|
*
|
||||||
|
* This method does not begin or end any transactions. Other methods
|
||||||
|
* may call this method as a subroutine in a larger transaction.
|
||||||
|
*
|
||||||
|
* See: `registerObject`.
|
||||||
|
*/
|
||||||
|
_nontransactionallyRegisterNodeFieldResult(
|
||||||
|
result: NodeFieldResult
|
||||||
|
): Schema.ObjectId | null {
|
||||||
|
if (result == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
const object = {typename: result.__typename, id: result.id};
|
||||||
|
this._nontransactionallyRegisterObject(object);
|
||||||
|
return object.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find objects and connections that are not known to be up-to-date.
|
* Find objects and connections that are not known to be up-to-date.
|
||||||
*
|
*
|
||||||
@ -674,12 +699,7 @@ export class Mirror {
|
|||||||
`
|
`
|
||||||
);
|
);
|
||||||
for (const node of queryResult.nodes) {
|
for (const node of queryResult.nodes) {
|
||||||
let childId = null;
|
const childId = this._nontransactionallyRegisterNodeFieldResult(node);
|
||||||
if (node != null) {
|
|
||||||
const childObject = {typename: node.__typename, id: node.id};
|
|
||||||
this._nontransactionallyRegisterObject(childObject);
|
|
||||||
childId = childObject.id;
|
|
||||||
}
|
|
||||||
const idx = nextIndex++;
|
const idx = nextIndex++;
|
||||||
addEntry.run({connectionId, idx, childId});
|
addEntry.run({connectionId, idx, childId});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user