projectWayfinderGraph function
The live projection of OkfGraph.fromBundle for bundle, filtered as
okf graph filters it, plus each wayfinderLinkFields entry between the
selected nodes (ADR-0012). Opens no index or model. Load findings refuse
the graph, as okf graph does.
Implementation
Future<WayfinderGraphResult> projectWayfinderGraph(
String bundle, {
Iterable<String> types = const [],
Iterable<String> pathPrefixes = const [],
Iterable<String> resolutions = const [],
}) async {
final loaded = await const OkfBundleLoader().inspect(bundle);
if (loaded.hasFindings) {
return WayfinderGraphResult.findings(loaded.report);
}
final query = OkfGraphQuery(
conceptTypes: types,
pathPrefixes: pathPrefixes,
resolutions: resolutions.map(OkfGraphResolution.fromWireValue),
);
final graph = OkfGraph.fromBundle(loaded.bundle, query: query);
final nodes = {for (final node in graph.nodes) node.id};
return WayfinderGraphResult.graph(graph, [
for (final edge in okfFieldEdges(loaded.bundle, wayfinderLinkFields))
if (nodes.contains(edge.source) &&
(edge.targetConcept == null || nodes.contains(edge.targetConcept)) &&
(query.resolutions.isEmpty ||
query.resolutions.contains(edge.resolution)))
edge,
]);
}