Home > Querying specific named graphs

Query specific named graphs

Use-case

Sometimes you need to restrict your query to one or more specific named graphs in your triplestore.

How it works

This is supported through the SPARQL protocol itself, inside the SPARQL endpoint URL, by adding one or more ?default-graph-uri=... parameters to the endpoint URL you provide to Sparnatural. (see the query section of the SPARQL protocol). The URI of the named graph(s) needs to be URL-encoded.

If you need to switch or select different named graphs, it is the responsibility of the calling page in which Sparnatural is integrated to provide this selector and update the endpoint attribute accordingly.

Configuring Sparnatural

To configure Sparnatural to query only specific named graphs

  1. Build the URL of the SPARQL endpoint by appending one or more ?default-graph-uri=... parameters to it
  2. Provide this URL to the endpoint attribute of the <spar-natural component

Here is an example querying https://data.myDomain.com/graph/1 and https://data.myDomain.com/graph/2

<spar-natural 
            src="..."
            endpoint="https://localhost:7200/repositories/myRepo?default-graph-uri=https%3A%2F%2Fdata.myDomain.com%2Fgraph%2F1&default-graph-uri=https%3A%2F%2Fdata.myDomain.com%2Fgraph%2F2"
            ... other attributes ...
></spar-natural>