Property Graphs as Javascript Module

Federated Wiki represents a page as a relatively flat JSON structure where detailed elements are interpreted with optional plugins. Two fairly recent plugins have dramatically increased wiki's representational and computational capabilities: Assets for files and Frames for scripts. In this environment we've sought to extend CSV tables and JSON trees with a file based property graph format as easily read and manipulated in modern Javascript.

Example: Create a Graph

A Graph contains two arrays: nodes and rels, each with type and properties and each referring to the other with integer ids.

Create an empty graph.


      import {Graph} from 'https://wardcunningham.github.io/graph/graph.js'
      const graph = new Graph()
    

Add nodes to the graph.
Remember node ids.


      const repo = graph.addNode('Repo',{name:'Graph',url:'https://github.com/WardCunningham/graph/'})
      const docs = graph.addNode('Docs',{name:'Graph',url:'https://wardcunningham.github.io/graph/'})
    

Add relation to the graph.
Connect remembered nodes by id.


      graph.addRel('Hosts',repo,docs,{})
    

Format graph as JSON.


      graph.stringify(null,2)
    

Graph rendered in wiki.

0 Repo Graph 🔗 1 Docs Graph 🔗 0->1 Hosts

Example: Query a Graph

We parse and execute a small portion of the Cypher query language. This finds and binds temporary variables to individual nodes and rels then returned in an array of matches. The parse doctor provides guidance writing queries within our slowly expanding subset.

Match any node n.


      graph.search('match (n)')
    

Match Repo node n.


      graph.search('match (n:Repo)')
    

Match any relation r.


      graph.search('match ()-[r]->()')
    

Match Hosts relating node n.


      graph.search('match ()-[:Hosts]->(n)')