use anyhow::Result;
use oxirs_gql::{GraphQLConfig, GraphQLServer, RdfStore};
use std::sync::Arc;
use tracing::{info, Level};
use tracing_subscriber;
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_max_level(Level::INFO)
.init();
info!("Starting OxiRS GraphQL Basic Server Example");
let store = Arc::new(RdfStore::new()?);
load_sample_data(&store).await?;
let config = GraphQLConfig {
enable_introspection: true,
enable_playground: true,
max_query_depth: Some(10),
max_query_complexity: Some(1000),
enable_query_validation: true,
..Default::default()
};
let server = GraphQLServer::new(store.clone())
.with_config(config);
info!("GraphQL server configured");
info!("GraphQL Playground will be available at http://127.0.0.1:4000/playground");
info!("GraphQL endpoint available at http://127.0.0.1:4000/graphql");
server.start("127.0.0.1:4000").await?;
Ok(())
}
async fn load_sample_data(store: &Arc<RdfStore>) -> Result<()> {
info!("Loading sample RDF data");
let mut store_mut = RdfStore::new()?;
store_mut.insert_triple(
"http://example.org/person/1",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"http://example.org/Person",
)?;
store_mut.insert_triple(
"http://example.org/person/1",
"http://example.org/name",
"\"John Doe\"",
)?;
store_mut.insert_triple(
"http://example.org/person/1",
"http://example.org/age",
"\"30\"",
)?;
store_mut.insert_triple(
"http://example.org/person/2",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"http://example.org/Person",
)?;
store_mut.insert_triple(
"http://example.org/person/2",
"http://example.org/name",
"\"Jane Smith\"",
)?;
store_mut.insert_triple(
"http://example.org/person/2",
"http://example.org/age",
"\"28\"",
)?;
info!("Sample data loaded successfully");
Ok(())
}