( subgraph: Subgraph<RootType>, )
| 30 | * @param subgraph |
| 31 | */ |
| 32 | export 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`. |
no test coverage detected