Skip to content

Consider changing subgraph serialization format #139

@michael

Description

@michael

The current serialization format (JSON) for subgraphs (aka documents) is an array of nodes, where the last node in the array is the entry point (= root node).

However, as I'm integrating Svedit into an app, I realized that possibly it would be advantageous to have a homogenous format for documents, no matter if serialized or in memory.

// the nav doc - stored as a self-contained document in SQLITE
const nav_doc = {
  document_id: 'nav_1',
  nodes: {
    "nav_item_1": {
      id: 'nav_item_1',
      type: 'nav_item',
      url: '/',
      label: 'Home'
    },
    "nav_1": {
      id: 'nav_1',
      type: 'nav',
      nav_items: ['nav_item_1']
    },
  }
}

// the page doc - stored as a self-contained document in SQLITE
// however, nav_1 is not included, but only referenced
const home_page_doc = {
  document_id: 'page_1',
  nodes: {
    "text_1": {
      id: 'text_1',
      type: 'text',
      layout: 1,
      content: { text: 'This is the home page.', annotations: [] }
    },
    "page_1": {
      id: 'page_1',
      type: 'page',
      body: ['text_1'],
      nav: 'nav_1'
    }
  }
}

Now when we fetch the home_page_doc from the database, the home_page_doc and the subdocs (nav_doc) will be joined like so:

{
  document_id: 'page_1',
  nodes: {...nav_doc.nodes, ...home_page_doc.nodes}
}

This is how Svedit (the client) sees the data (as just one self-contained document, always)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions