MCPcopy Create free account
hub / github.com/hashintel/hash / getRoots

Function getRoots

libs/@blockprotocol/graph/src/stdlib/subgraph/roots.ts:32–50  ·  view source on GitHub ↗
(
  subgraph: Subgraph<RootType>,
)

Source from the content-addressed store, hash-verified

30 * @param subgraph
31 */
32export const getRoots = <RootType extends SubgraphRootType>(
33 subgraph: Subgraph<RootType>,
34): RootType["element"][] =>
35 subgraph.roots.map((rootVertexId) => {
36 if (!("baseId" in rootVertexId && "revisionId" in rootVertexId)) {
37 throw new Error(`Invalid vertex ID: ${JSON.stringify(rootVertexId)}`);
38 }
39
40 const root = mustBeDefined(
41 (subgraph.vertices as Record<string, Record<string, Vertex>>)[
42 rootVertexId.baseId
43 ]?.[rootVertexId.revisionId.toString()],
44 `roots should have corresponding vertices but ${JSON.stringify(
45 rootVertexId,
46 )} was missing`,
47 );
48
49 return root.inner as RootType["element"];
50 });
51
52/**
53 * A type-guard that can be used to constrain the generic parameter of `Subgraph` to `DataTypeWithMetadata`.

Callers 15

useEntityTypesFunction · 0.90
getUserFunction · 0.90
getMentionNotificationFunction · 0.90
getCommentNotificationFunction · 0.90
upgradeWebEntitiesFunction · 0.90
RemoteBlockFunction · 0.90
useUsersWithLinksFunction · 0.90
useAccountPagesFunction · 0.90

Calls 2

mustBeDefinedFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected