Skip to content

JSON-LD where: a compact IRI in ["graph", …] is not expanded, so the pattern silently matches nothing #1993

Closed

Description

@bplatz

Summary

In a JSON-LD query or update where, the graph name in ["graph", "<name>", …] is not expanded against @context. A compact IRI such as "ex:g" is looked up as the literal string ex:g, matches no graph, and the pattern silently returns nothing.

In the same update request, the same compact IRI in an insert / delete ["graph", …] template is expanded (documented in docs/transactions/update-where-delete-insert.md, "a compact IRI/term that expands via @context"). So a copy-within-a-graph update commits 0 flakes without an error:

{
  "@context": { "ex": "http://example.org/" },
  "where":  [["graph", "ex:g", { "@id": "ex:alice", "ex:name": "?n" }]],
  "insert": [["graph", "ex:g", { "@id": "ex:alice", "ex:copied": "?n" }]]
}

SPARQL GRAPH ex:g { … } resolves the prefixed name, so the two surfaces disagree.

Reproduced on v4.2.2 (ba984c7f5, current main).

Reproduction

fluree init && fluree create g
printf '@prefix ex: <http://example.org/> .\nGRAPH ex:g { ex:alice ex:name "Alice" . }\n' > g.trig
fluree insert g -f g.trig

C='"@context": {"ex": "http://example.org/"}'
fluree query g "{ $C, \"select\": [\"?n\"], \"where\": [[\"graph\", \"http://example.org/g\", {\"@id\": \"ex:alice\", \"ex:name\": \"?n\"}]] }"
                                        # [["Alice"]]
fluree query g "{ $C, \"select\": [\"?n\"], \"where\": [[\"graph\", \"ex:g\", {\"@id\": \"ex:alice\", \"ex:name\": \"?n\"}]] }"
                                        # []
fluree update g "{ $C, \"where\": [[\"graph\", \"ex:g\", {\"@id\": \"ex:alice\", \"ex:name\": \"?n\"}]],
                       \"insert\": [[\"graph\", \"ex:g\", {\"@id\": \"ex:alice\", \"ex:copied\": \"?n\"}]] }"
                                        # Committed … 0 flakes
fluree update g "{ $C, \"insert\": [[\"graph\", \"ex:g\", {\"@id\": \"ex:alice\", \"ex:tag\": \"t\"}]] }"
                                        # lands in http://example.org/g

Where it goes wrong

fluree-db-query/src/parse/where_clause.rs:586-608 takes the graph name straight from the JSON (arr[1].as_str()) into UnresolvedPattern::graph(graph_name, …). The parse context, including @context, is in scope there (ctx) but isn't consulted. The name is later matched against fromNamed aliases and registered graph IRIs only.

docs/query/jsonld-query.md says the second element "can be a dataset-local alias (recommended) or a graph IRI", so a compact IRI isn't promised in where. But templates in the same request accept one, and the failure mode is a silent empty match.

Possible fixes

  • Resolve the name in this order: variable, then fromNamed alias, then @context expansion, falling back to the raw string. The alias check has to come first so an alias spelled like a CURIE keeps working.
  • Otherwise, reject an unexpanded CURIE-shaped name whose prefix is defined in @context, rather than matching nothing.

Activity

  1. added
    bug
    P3
    area:query
    on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area:querybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions