Open grtjn opened 6 years ago
I have been using:
import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";
let $query := "$QUERY_STRING"
let $vars := ()
let $options := $OPTIONS
return try {
let $ret := $FUNCTION
let $triples := for $item in $ret where $item instance of sem:triple return $item
let $other := for $item in $ret where not($item instance of sem:triple) return $item
return if (count($triples) > 0) then
let $fmt := sem:rdf-serialize($triples, "$TRIPLE_FORMAT")
let $_ := xdmp:add-response-header("X-Content-Type", "$CONTENT_TYPE")
return ($fmt, $other)
else
$ret
} catch ($e) { $e }
to run SPARQL queries in a plugin of mine, replacing $FUNCTION
, etc. with string replacement logic.
X-Content-Type
is used because setting Content-Type
changes the multipart content type and breaks things. This could be removed for the roxy version. $FUNCTION
is the appropriate invoke/eval function, allowing support for profiling and debugging.
I had in mind using /v1/graph/sparql. Would sending your code to /v1/eval provide more possibilities?
Using /v1/graph/sparql
is probably better for roxy. I'm using eval to make use of things like better exception reporting, profiling, and debugging if available.
Thanks for sharing though, appreciated!
See also #821