Repository navigation
Description
Summary
When a query @context defines an @vocab, the JSON-LD result formatter compacts @id node identifiers against that @vocab, producing a bare term. Per JSON-LD 1.1, @vocab governs only properties, @type values, and values of @type: @vocab terms — it must not be used to compact node identifiers. Only @base and explicit term/prefix/@id-term mappings apply to @id.
Example
Given a subject http://example.org/lists/summer and a query context:
{ "@context": { "@vocab": "http://example.org/lists/" }, ... }The formatter currently emits:
{ "@id": "summer" }summer round-trips only because it happens to match @vocab, but it is non-conformant: a compliant JSON-LD processor expanding summer as an @id would resolve it against @base (or leave it relative), not against @vocab. Expected output is the full IRI (or a compaction via an explicit prefix / @base-relative form):
{ "@id": "http://example.org/lists/summer" }Root cause
The codebase already distinguishes the two compaction modes:
IriCompactor::compact_id/IriCompactor::compact_id_iri— correct for@id(no@vocab).IriCompactor::compact_vocab/compact_vocab_iri/compact_iri/compact_sid— for predicates and@type(applies@vocab).
fluree-db-api/src/format/construct.rs already routes @id through the vocab=false path correctly. But the hydration / jsonld / typed formatters use the vocab-applying methods for @id positions:
fluree-db-api/src/format/hydration.rs— root@id(compact_iri/compact_sid) and bare-@idfallback (compact_iri).fluree-db-api/src/format/jsonld.rs—Binding::SidandBinding::IriMatch@idoutput (compact_sid/compact_iri).fluree-db-api/src/format/typed.rs—Binding::SidandBinding::IriMatch@idoutput.
These should route through compact_id (the @id-position method) instead, matching construct.rs.
Scope / impact
- Affects single-ledger and multi-ledger formatting equally; surfaced while reviewing the multi-ledger work in fix: multi-ledger JSON-LD queries through
/v1/fluree/query(dispatcher + formatter) #1267 but is independent of it. - Only manifests when the query
@contextsets@vocaband a result@idfalls under that vocab namespace. - Fix is localized (swap the compaction method at
@idcall sites) but needs care:compact_sidboth decodes the SID and compacts, so the@idpaths need a decode-then-compact_idvariant.
Suggested regression coverage
Add a formatter test asserting that with @vocab set, a result @id whose IRI falls under the vocab namespace is not reduced to a bare term (expect the full IRI, or an explicit-prefix / @base-relative compaction).
Activity
fix: do not compact JSON-LD @id against @vocab (#1280)