Repository navigation
Description
Versions
fluree-serverbuilt frommain@ commite40f5560c(PR rollup: Cumulative work from #1258, #1260, #1261, #1262, #1263 (mis-merged to solo/latest) #1264, merged 2026-06-01)- Linux x86_64, local single-node, default file storage
Summary
The TriG parser used by /v1/fluree/upsert/{ledger} accepts only the SPARQL-style graph block header (GRAPH <iri> { ... }). The W3C TriG 1.1 recommendation specifies that the GRAPH keyword is optional — <iri> { ... } alone is a valid named-graph block. Major tooling (rdflib, Apache Jena, RDF4J's TriGWriter) emits the compact form by default, so any client using a stock library to produce TriG hits a 400.
Spec reference: https://www.w3.org/TR/trig/#sec-graph
Block ::= Labeled_or_Subject Wrapped_or_Empty_Graph
Labeled_or_Subject ::= ( 'GRAPH' )? Labeled_or_Subject_Inner
(The GRAPH token is wrapped in optional brackets in the grammar.)
Reproducer
# 1. Create a ledger
curl -X POST http://localhost:8090/v1/fluree/create \
-H 'Content-Type: application/json' \
-d '{"ledger":"trigbug:main"}'
# 2. POST a compact-form TriG payload (this is what rdflib emits)
curl -i -X POST http://localhost:8090/v1/fluree/upsert/trigbug:main \
-H 'Content-Type: application/trig' \
--data-binary @- <<'EOF'
@prefix ex: <http://example.org/> .
<urn:graph:test> {
ex:alice ex:knows ex:bob .
}
EOF
# 3. The same payload with the explicit GRAPH keyword — works
curl -i -X POST http://localhost:8090/v1/fluree/upsert/trigbug:main \
-H 'Content-Type: application/trig' \
--data-binary @- <<'EOF'
@prefix ex: <http://example.org/> .
GRAPH <urn:graph:test> {
ex:alice ex:knows ex:bob .
}
EOFExpected
Both requests succeed (W3C TriG treats them as equivalent).
Actual
The first (compact form) returns:
HTTP/1.1 400 Bad Request
{
"error": "Turtle parse error: Parse error at position <N>: expected predicate, found LBrace",
"status": 400,
"@type": "err:parse/TurtleParse"
}The parser took <urn:graph:test> as the subject of a Turtle triple, expected a predicate, then found {.
The second (keyword form) returns 200.
Real-world impact
Stock tooling defaults to the compact form:
- rdflib (Python) —
ConjunctiveGraph.serialize(format="trig")/Dataset.serialize(format="trig")emit<iri> { ... }. - Apache Jena —
RDFDataMgr.write(out, dataset, Lang.TRIG)emits<iri> { ... }in default mode. - RDF4J TriGWriter — emits
<iri> { ... }.
Any caller that generates TriG via a library has to post-process the output to insert the GRAPH keyword (regex on top-level lines matching ^<[^>]+>\s*\{). Workable but adds an annoying step and isn't discoverable from the error message.
Suspected area / suggested fix
fluree-db-transact/src/parse/trig_meta.rs, parse_statement() around line 480:
TokenKind::KwGraph => {
self.parse_graph_block()?;
}
TokenKind::Eof => {}
_ => {
// Default graph triple
self.parse_default_triple(start_pos)?;
}The parser dispatches on the GRAPH keyword. When it sees an IRI or prefixed name followed by {, it should look ahead and route to parse_graph_block() as well (treating GRAPH as optional). Roughly:
TokenKind::KwGraph => {
self.advance(); // consume GRAPH
self.parse_graph_block()?;
}
TokenKind::Iri | TokenKind::IriEscaped(_) | TokenKind::PrefixedName | TokenKind::PrefixedNameNs
if matches!(self.peek_next_significant().kind, TokenKind::LBrace) =>
{
// Compact W3C TriG form: <iri> { ... }
self.parse_graph_block()?;
}
TokenKind::Eof => {}
_ => {
self.parse_default_triple(start_pos)?;
}Lookahead is needed because a bare <iri> could also be the subject of a default-graph triple — the { disambiguates.
Workaround used downstream
Until fixed, clients post-process the TriG body with a regex:
body = re.sub(r'(?m)^(<[^>]+>)\s*\{', r'GRAPH \1 {', body)before sending. Robust because <…> { at the start of a line cannot appear as part of a regular triple — only as a graph block header.
Activity
fix: accept the compact W3C TriG graph-block form `<iri> { ... }`