A modern, interactive web application for exploring and querying RDF data using SPARQL. Built with Next.js 16, TypeScript, and TanStack Query (React Query), this app provides a clean interface to execute SPARQL queries against DBpedia and visualize results in a responsive table format.
- Features
- Demo
- Tech Stack
- Project Structure
- Getting Started
- Usage
- Example Queries
- Architecture
- API Reference
- Contributing
- License
- Interactive Query Editor: Write and execute SPARQL queries with a user-friendly textarea interface
- Real-time Results: Instant query execution with loading states and error handling
- Responsive Table View: Clean, tabular display of query results with alternating row colors
- DBpedia Integration: Pre-configured to query the DBpedia SPARQL endpoint
- Modern UI/UX: Built with Tailwind CSS for a sleek, responsive design
- Type-Safe: Full TypeScript support for better development experience
- Optimized Performance: Leverages TanStack Query for efficient data fetching and caching
- Form Validation: Uses React Hook Form for robust form handling
- Enter a SPARQL query in the text area
- Click "Run Query" to execute
- View results in an organized table format
- Experience smooth loading states and error handling
- Next.js 16 - React framework with App Router
- React 19.2 - UI library
- TypeScript - Type safety
- @tanstack/react-query - Async state management
- react-hook-form - Form validation and handling
- Tailwind CSS 4 - Utility-first CSS framework
sparql-query-app/
βββ app/
β βββ components/
β β βββ QueryForm.tsx # SPARQL query input form
β β βββ ResultsTable.tsx # Results display table
β βββ lib/
β β βββ fetchSparql.ts # SPARQL API client
β βββ favicon.ico
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Main page component
β βββ providers.tsx # React Query provider setup
βββ public/ # Static assets
βββ eslint.config.mjs # ESLint configuration
βββ next.config.ts # Next.js configuration
βββ package.json # Dependencies and scripts
βββ postcss.config.mjs # PostCSS configuration
βββ tsconfig.json # TypeScript configuration
βββ README.md # This file
- Node.js: Version 18.x or higher
- npm, yarn, pnpm, or bun: Package manager
-
Clone the repository (or navigate to your project directory):
cd sparql-query-app -
Install dependencies:
npm install # or yarn install # or pnpm install
-
Install required peer dependencies (if not already installed):
npm install @tanstack/react-query react-hook-form
npm run dev
# or
yarn dev
# or
pnpm devOpen http://localhost:3000 in your browser to see the application.
npm run build
npm run startThis creates an optimized production build and starts the production server.
- Enter a SPARQL Query: Type or paste your SPARQL query into the textarea
- Execute: Click the "Run Query" button
- View Results: Results appear in a formatted table below the form
- Iterate: Modify your query and re-run as needed
The query form accepts standard SPARQL 1.1 queries. Results are automatically parsed and displayed in a table format with:
- Column headers from query variables
- Row data from result bindings
- Clean styling with hover effects
- Responsive design for all screen sizes
SELECT ?actor ?name WHERE {
dbr:Inception dbo:starring ?actor.
?actor rdfs:label ?name.
FILTER (lang(?name) = 'en')
}SELECT ?language ?name
WHERE {
?language rdf:type dbo:ProgrammingLanguage .
?language rdfs:label ?name .
FILTER (LANG(?name) = 'en')
}
LIMIT 10SELECT ?city ?name ?population
WHERE {
?city rdf:type dbo:City .
?city rdfs:label ?name .
?city dbo:populationTotal ?population .
FILTER (LANG(?name) = 'en')
FILTER (?population > 1000000)
}
ORDER BY DESC(?population)
LIMIT 20SELECT ?musician ?name ?birthDate
WHERE {
?musician rdf:type dbo:MusicalArtist .
?musician rdfs:label ?name .
?musician dbo:birthDate ?birthDate .
FILTER (LANG(?name) = 'en')
}
ORDER BY DESC(?birthDate)
LIMIT 15HomePage (page.tsx)
βββ QueryForm (QueryForm.tsx)
β βββ React Hook Form integration
βββ Loading Spinner (conditional)
βββ Error Message (conditional)
βββ ResultsTable (ResultsTable.tsx)
βββ Dynamic table rendering
- User Input: Query entered in
QueryForm - State Update: Query state updated in
HomePage - Query Trigger: TanStack Query enabled, triggers fetch
- API Call:
fetchSparqlfunction makes HTTP request to DBpedia - Response Handling: Results parsed and passed to
ResultsTable - UI Update: Table renders with formatted data
- Client-side Rendering: Uses
"use client"for interactive components - Controlled Fetching: Query execution triggered by user action, not automatic
- Optimistic UI: Loading and error states for better UX
- Type Safety: TypeScript interfaces ensure data integrity
- Separation of Concerns: Clear separation between UI, logic, and data fetching
Executes a SPARQL query against the DBpedia endpoint.
Parameters:
query(string): SPARQL query string
Returns:
- Promise resolving to JSON response with
headandresultsobjects
Example:
const data = await fetchSparql(`
SELECT ?name WHERE {
?person rdfs:label "Albert Einstein"@en .
?person rdfs:label ?name .
} LIMIT 5
`);- URL:
https://dbpedia.org/sparql - Format: JSON
- Documentation: DBpedia SPARQL
Edit app/lib/fetchSparql.ts:
const endpoint = "https://your-sparql-endpoint.com/sparql";The app uses Tailwind CSS. Customize colors, spacing, and components in:
app/globals.css- Global styles- Component files - Inline Tailwind classes
Consider adding:
- Query history
- Saved queries/favorites
- Multiple endpoint support
- Export results (CSV, JSON)
- Query syntax highlighting
- Auto-complete for SPARQL keywords
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is open source and available under the MIT License.
- DBpedia - For providing the SPARQL endpoint
- Next.js Team - For the amazing React framework
- TanStack - For React Query
- Tailwind CSS - For the utility-first CSS framework
For issues, questions, or suggestions:
- Open an issue in the repository
- Check existing issues for solutions
- Refer to Next.js Documentation
- Visit SPARQL 1.1 Specification
Happy Querying! π