Passing a filter to a stored query via HTTP API

Is it possible to pass a set of filter clauses - even a simple list of restrictions (predicate,operator,value) to a stored SPARQL query?

It looks like it may be possible with a GraphQL query if the client constructs the query, but this loses the advantage of stored queries encapsulating the data model and puts a big burden on a client - and stops you reorganising data later if you need to.

I did search forums, API and general documentation - apologies if i missed something!

Hi Rob,

not directly, but SPARQL is expressive so maybe a trick along the following lines could help:

The idea is to encode the filter clauses in the query itself but have extra variables to trigger them when needed (by passing values to those variables as query parameters). I haven't tested but something like:

prefix : <urn:>

select * {
   bind(?x as ?y)
   values (?s ?o) { ( :a 1 ) ( :b 2 ) ( :c 3 ) }
   filter(!bound(?x) || bound(?y) && ?o > 2)
}

if you run this as-is, ?x and ?y aren't bound so the filter is a no-op. But if you pass a value to the "sleeper agent" ?x:

stardog query -b x="\"anything\"" -- {db} query.rq

?x and ?y both become bound, and so the filter should become equivalent to ?o > 2.

Cheers,
Pavel