oxigraph::sparql

Trait ServiceHandler

Source
pub trait ServiceHandler: Send + Sync {
    type Error: Error + Send + Sync + 'static;

    // Required method
    fn handle(
        &self,
        service_name: NamedNode,
        query: Query,
    ) -> Result<QueryResults, Self::Error>;
}
Expand description

Handler for SPARQL 1.1 Federated Query SERVICE.

Should be given to QueryOptions before evaluating a SPARQL query that uses SERVICE calls.

use oxigraph::model::*;
use oxigraph::sparql::{EvaluationError, Query, QueryOptions, QueryResults, ServiceHandler};
use oxigraph::store::Store;

struct TestServiceHandler {
    store: Store,
}

impl ServiceHandler for TestServiceHandler {
    type Error = EvaluationError;

    fn handle(
        &self,
        service_name: NamedNode,
        query: Query,
    ) -> Result<QueryResults, Self::Error> {
        if service_name == "http://example.com/service" {
            self.store.query(query)
        } else {
            panic!()
        }
    }
}

let store = Store::new()?;
let service = TestServiceHandler {
    store: Store::new()?,
};
let ex = NamedNodeRef::new("http://example.com")?;
service
    .store
    .insert(QuadRef::new(ex, ex, ex, GraphNameRef::DefaultGraph))?;

if let QueryResults::Solutions(mut solutions) = store.query_opt(
    "SELECT ?s WHERE { SERVICE <http://example.com/service> { ?s ?p ?o } }",
    QueryOptions::default().with_service_handler(service),
)? {
    assert_eq!(solutions.next().unwrap()?.get("s"), Some(&ex.into()));
}

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

The service evaluation error.

Required Methods§

Source

fn handle( &self, service_name: NamedNode, query: Query, ) -> Result<QueryResults, Self::Error>

Evaluates a Query against a given service identified by a NamedNode.

Implementors§