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:
William Chargin 2018-09-24 18:20:28 -07:00 committed by GitHub
parent 28c4e497fb
commit 3257df63fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 6 deletions

View File

@ -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.
*
@ -674,12 +699,7 @@ export class Mirror {
`
);
for (const node of queryResult.nodes) {
let childId = null;
if (node != null) {
const childObject = {typename: node.__typename, id: node.id};
this._nontransactionallyRegisterObject(childObject);
childId = childObject.id;
}
const childId = this._nontransactionallyRegisterNodeFieldResult(node);
const idx = nextIndex++;
addEntry.run({connectionId, idx, childId});
}