Repository navigation
Description
Summary
TriG is supported only through upsert. On insert, a TriG payload is refused, and how it's refused depends on which entry point you use. On most of them the error is a Turtle syntax error rather than "TriG isn't supported here".
Probed on main + #1832 (e4e4ecc25), payload @prefix ex: <http://example.org/> . GRAPH <http://example.org/g> { ex:alice ex:knows ex:bob . }:
| Entry point | Result |
|---|---|
Fluree::insert_turtle(ledger, trig) |
Turtle parse error: … expected subject, found 'GRAPH' |
fluree.graph(id).transact().insert_turtle(trig).commit() |
same |
same, compact form <g> { … } |
Turtle parse error: … expected predicate, found '{' |
fluree.graph(id).transact().insert_turtle(trig).stage() |
parses the TriG, then fails Insert must contain at least one predicate or @type … on the empty default graph |
Server POST /insert, Content-Type: application/trig |
clean 400: "TriG format … is not supported on the insert endpoint" (routes/transact.rs, deliberate) |
Server POST /insert, TriG body sent as text/turtle |
Turtle parse error, as in the first row |
CLI fluree insert -f data.trig |
Turtle parse error (documented in docs/transactions/turtle.md) |
Why
InsertTurtle has a direct flake fast path that streams the body through fluree-graph-turtle, which has no GRAPH production:
tx_builder.rs:OwnedTransactBuilder::executeand::stage(// Direct flake path for InsertTurtle)tx_builder.rs:stage_under_lockandstage_plan(OpPlan::InsertTurtle), the ledger-handle commit lanes
TransactOperation::to_json_with_trig_meta does have an InsertTurtle arm that runs parse_trig_phase1, and it looks like TriG-on-insert was meant to work. But every lane except GraphTransactBuilder::stage short-circuits before reaching it. That lane reaches it and then trips on the JSON-LD insert validation, so stage() and commit() disagree for the same payload.
The same gap covers GRAPH <#txn-meta> { } commit metadata, which only works on upsert.
Options
- Support TriG on insert. Keep the streaming fast path for plain Turtle. When the payload has graph blocks, route it through the existing TriG phase-1 + IR path with
TxnType::Insert, asupsertdoes. Detection needs to stay cheap: the content type or file extension where there is one, otherwise a lexer pre-scan forGRAPH/<iri> {/<#txn-meta>. The empty-default-graph validation failure onstage()would need fixing too. - Refuse consistently. Detect graph blocks on every
insert_turtlelane and return the same "TriG requires upsert" error the server gives forapplication/trig, including when the body comes astext/turtleand in the CLI.
Option 1 is what the edge-annotation docs originally implied (insert was listed as a TriG path until #1832 corrected it). Option 2 is the smaller change. Either way, the dead-looking InsertTurtle arm in to_json_with_trig_meta should end up either reachable or removed.
Done when
- All entry points above behave the same for a TriG payload on insert: either all accept it, or all refuse it with one TriG-specific message.
docs/transactions/turtle.md(endpoint table and "TriG goes throughupsert, notinsert"),docs/concepts/edge-annotations.mdanddocs/guides/cookbook-edge-annotations.mdmatch.- A test covers each builder lane (
Fluree::insert_turtle, graph buildercommitandstage).
Follow-up from #1832 (listed under "Noted, not fixed here").
Activity
bplatz commentedon Sep 15, 2026
Decision: support TriG on insert (option 1), as a flake-level fast path, not by sending insert through the upsert template/IR lane. Proposed shape below, from reading the existing pieces; nothing is implemented yet.
Pieces that already exist
stage_flakes(fluree-db-transact/src/stage.rs) already stages named-graph flakes (Flake.g = Some) whenStageOptions.graph_sidsis provided, and runsenforce_single_target_reifiersover them.StageResultalready carriesgraph_deltaandtxn_meta.stage_turtle_insertjust returns them empty.import_trig_commit(fluree-db-transact/src/import.rs) is the model to follow. It runsparse_trig_phase1, streams the default-graph Turtle through a sink, and turns eachNamedGraphBlockstraight into flakes:expand_term/expand_object, per-blockgraph_sid, andreified_triple_bundle(Some(graph_sid), …)for TriG-star.resolve_trig_metahandles<#txn-meta>.Proposed
stage_trig_insertparse_trig_phase1(input), giving default-graph Turtle, named-graph blocks and raw txn-meta.FlakeSink, asstage_turtle_insertdoes today.txn_idscheme, so a_:bused in the default graph and inside a block is the same node, which is TriG's document scope.graph_deltaandgraph_sids. Refuse reserved system graphs by full IRI. That guard currently sits in the templatestage()path (fix: @json opacity, var-length edge identity, commit-id spelling, reserved-graph contract #1838), andstage_flakesdoesn't go through it.resolve_trig_metagivesStageResult.txn_meta.stage_flakeswithgraph_sids, policy and tracker, and passgraph_delta/graph_sidsto SHACL instead ofNone.This also takes care of the insert half of #1848: TriG-star bundles on insert would come from the shared
reified_triple_bundleinstead of the hand-built templates intx.rs. Upsert keeps its template path.Routing, so plain Turtle stays on today's path
TransactOperation::InsertTurtle: try the streaming parse first. If it fails at a TriG-only construct (GRAPH,<iri> {), rebuild the namespace registry and rerun throughstage_trig_insert. Plain Turtle pays nothing; a TriG payload pays one partial parse.Content-Type: application/trig, CLI.trig): go straight tostage_trig_insert. Drop the server's 400 for TriG on/insert.tx_builder.rs(OwnedTransactBuilder::execute/::stage,stage_under_lock/stage_plan) andGraphTransactBuilder::stageshould end at the same function, sostage()andcommit()agree.Tests
insertandupserton fresh ledgers gives the same named-graph contents, annotations included.<#txn-meta>on insert.MustFire-style routing check that plain Turtle never takes the TriG path.insert_formatsbench case for TriG next to the existing Turtle one.[-]insert refuses TriG inconsistently: parse error on most lanes, 400 on the server, a different error on stage()[/-][+]Support TriG on insert via a flake-level fast path[/+]