Resolved Graph
Also check out Resolved Graph Query, a fledgling query language for this package available here
Introduction
This is a tiny package that takes a more or less standard graph and make its entities directly accesible (and iterable with standard methods) through memory, like so:
Now, lets resolve it:
//...
...And try it out for size:
//...for of resolvedGraph.nodes
Expected output:
Tommy is in love with Viktoria
Viktoria is head over heels for Tommy
Defining node & link types
You can define the type of the 'data' prop on both nodes and links. This will preserve intellisense even after resolving the graph, making it easy to traverse your data in code. However - as with any self respecting JS application - there is no runtime typechecking ;)
//...
Searching for nodes & links
You can use the .findNode
, .findNodes
, .findLink
or .findLinks
functions to easily query for certain entities. For example, lets find all nodes with name Tommy in the data prop and that has any links to a node with id '2':
//...console.logresolvedGraph.findNodes
Expected output:
[
{
id: '1',
data: { name: 'Tommy' },
to: [[Object]],
from: [[Object]],
},
]
As mentioned above, you can use Resolved Graph Query for more advanced use cases such as recursive queries
Disclaimer
As long as you use the standard methods found on the ResolvedGraph class, it should keep up with all resolutions for you. You can chuck in whatever properties you like on the nodes & links, as long as you stay away from 'id', 'to' and 'from'. The dissolve() method breaks the circular references and returns a simpler Graph object safe for JSON. No checks are made on other properties so that's up to you.
This project is currently only for my amusement. With that said, I'm glad you found it and welcome any requests!