graphlife Docs graphlife.app

Integration API

The change feed

GET /v1/graphs/{id}/changes?order=asc is every change to a graph after a sync token, oldest first, with nothing skipped. It takes a session, or a key holding changes.

Parameter Meaning
order must be asc. Without it the route is the app's own history view, which is not for integrations
since a sync token: a listing's syncToken, or a previous page's next
limit 1 to 500, default 100
wait 0 to 25 seconds: when there is nothing to read, hold the request until the next change
{"events": [{"seq": 41, "type": "node.updated", "id": "...", "revision": 17,
             "at": 1790000000, "via": "key", "own": false},
            {"seq": 42, "type": "edge.created", "id": "...", "src": "...",
             "dst": "...", "revision": 18, "at": 1790000004, "via": "app",
             "own": false}],
 "next": "s1.57.ab12cd34ef56", "hasMore": false, "reset": false}
  • type is node. or edge. followed by created, updated, deleted or restored, or it is graph.reset. An edge event also has src and dst.
  • via is key, app (a signed-in person) or system (a background job or a device sending the whole graph). own is true for a change the calling key made itself.
  • An event carries ids only: no label, no attribute. Fetch what changed with get_nodes, or list_edges with ids.
  • Read on from next while hasMore is true. A page can be empty and still move next: the changes in it were not yours to see.
  • Without since the answer is empty, with next at the current position. The feed never replays history to a first-time reader.

How to follow a graph#

  1. List it (list_nodes, and list_edges if you keep relationships). Keep the syncToken of the first page.
  2. Read the feed from that token. Store next after each page you have applied.
  3. Treat node.created and node.updated alike: fetch the node and store it. node.updated can be the first event you see for a node, because it moved into your groups.
  4. When a node event names an id you do not hold yet, also list its edges with list_edges {"node": "<id>"}. The edges it brings into your reach were created before you could see both ends, and no edge event announces them. Do the same after node.deleted and node.restored: a node takes its edges with it and brings them back, without an event for each.
  5. Treat node.deleted for an id you do not hold as nothing.
  6. On reset: true, list again from the start and carry on from the new syncToken (or the next of the reset answer).
  7. Delivery is at least once and in order. Tell events apart by seq.
token = sync_token                       # from the first page of the listing
while True:
    page = get(f"/v1/graphs/{GRAPH}/changes?order=asc&since={token}&wait=25")
    if page["reset"]:
        relist()                         # step 1 again
        token = page["next"]
        continue
    for event in page["events"]:
        apply(event)
    token = page["next"]                 # persist it once the page is applied

Reset#

reset is true in two cases, and both mean "list again":

  • The token cannot be followed. The answer has no events and next is the current position. This happens when your reach changed (a group gained or lost, a tool added to the key), when the change log was pruned past the token, when the graph was unpublished and published again or moved into an organisation, and for a token the server did not hand to your scope.
  • The page holds a graph.reset event: the whole graph was replaced at once (a first publish, or a publish too large to list change by change).

What you are shown#

Visibility is decided when you read, on your scope as it is then.

  • A node's event, when you read the node in full now.
  • A node that has left your reach (moved out of your groups, or removed) is shown once more as node.deleted. A node that was never in your reach is not shown at all.
  • An edge's event, when you read both its ends in full.
  • A key that sees nodes as existing only (level: listed) receives no node events.
  • Links the server derives from a node's text are never in the feed; the node's own event covers them.

After a wait, the server checks the caller again. A key revoked or expired while it waited is told so (403 revoked, 401 key_expired) and is not handed events.