Get started with SharpGraph in 5 minutes using the Star Wars database: seed data and start querying!
All examples in this guide use the Star Wars GraphQL Database with 30+ characters, 8 films, planets, species, starships, and vehicles.
- .NET 9.0 SDK or later (download)
- Git for cloning the repository
- Postman or curl for testing GraphQL queries (optional)
Verify your setup:
dotnet --version# Clone the repository
git clone https://github.com/sjefvanleeuwen/sharpgraph.git
cd sharpgraph
# Verify structure
ls examples/StarWars/# Build all projects (server + examples)
dotnet build
# You should see:
# Build succeeded. (X errors, Y warnings)The SharpGraph server automatically loads the Star Wars schema and seeds the database with 30+ characters, 8 films, planets, species, starships, and vehicles.
When you start the server:
- Schema Load - Reads
graphql_db/schema.graphql - Type Generation - Generates connection types, filter types, CRUD mutations
- Seed Data - Populates tables from
examples/StarWars/seed_data.json - Index Creation - Creates indexes for fast lookups
- Server Ready - Listens on
http://localhost:8080
All seed data is stored in binary format in the graphql_db/ folder and persists between restarts.
# From the root directory
.\start-server.ps1
# You should see:
# 🚀 SharpGraph Server starting...
# ✅ Schema loaded from graphql_db/schema.graphql
# ✅ Seeding database with Star Wars data...
# ✅ Character table: 30+ characters loaded
# ✅ Film table: 8 films loaded
# ✅ Server is ready at http://127.0.0.1:8080
# 📊 Introspection available at http://127.0.0.1:8080/__schema# From the root directory
dotnet run --project src/SharpGraph.Server/SharpGraph.Server.csproj
# Or with watch mode (auto-rebuilds on file changes)
dotnet watch run --project src/SharpGraph.Server/SharpGraph.Server.csprojThe server will:
✅ Load graphql_db/schema.graphql with Star Wars types
✅ Seed database with 30+ characters from seed_data.json
✅ Generate connection types (CharacterConnection, FilmConnection, etc.)
✅ Auto-generate CRUD mutations (create, update, delete)
✅ Create indexes for fast lookups
✅ Make schema available for introspection
Keep this terminal open - your server is now running with Star Wars data ready to query!
Open a new terminal and run this query:
$query = @'
query {
characters {
items(first: 3) {
id
name
characterType
}
}
}
'@
$body = @{query=$query} | ConvertTo-Json
Invoke-WebRequest -Uri "http://localhost:8080/graphql" -Method POST `
-ContentType "application/json" -Body $body | Select-Object -ExpandProperty ContentExpected response:
{
"data": {
"characters": {
"items": [
{"id": "luke", "name": "Luke Skywalker", "characterType": "Human"},
{"id": "r2d2", "name": "R2-D2", "characterType": "Droid"},
{"id": "han", "name": "Han Solo", "characterType": "Human"}
]
}
}
}- Open Postman
- Create a new POST request:
- URL:
http://localhost:8080/graphql - Body type:
raw+JSON
- URL:
Paste in Postman Body:
query {
characters {
items(
where: {characterType: {equals: "Human"}}
orderBy: [{name: asc}]
first: 5
) {
id
name
characterType
height
eyeColor
}
}
}Click Send → You'll see all Human characters sorted by name!
query {
character(id: "luke") {
name
characterType
height
mass
birthYear
friends {
name
}
}
}query {
characters {
items(where: {characterType: {equals: "Droid"}}) {
name
primaryFunction
height
}
}
}query {
films {
items {
title
episodeId
director
releaseDate
}
}
}query {
planet(id: "tatooine") {
name
climate
terrain
population
}
}query {
starships {
items(first: 3) {
name
model
starshipClass
pilots {
name
}
}
}
}mutation {
createCharacter(input: {
name: "Rey"
characterType: "Human"
height: 170
mass: 54
hairColor: "brown"
eyeColor: "hazel"
birthYear: "15ABY"
}) {
id
name
characterType
}
}mutation {
updateCharacter(id: "luke", input: {
mass: 80
height: 175
}) {
id
name
mass
height
}
}mutation {
deleteCharacter(id: "custom_char_id") {
id
name
}
}SharpGraph supports Prisma-style filtering and sorting!
query {
characters {
items(where: {
AND: [
{characterType: {equals: "Human"}}
{height: {gte: 170}}
]
}) {
name
characterType
height
}
}
}query {
characters {
items(orderBy: [
{characterType: asc}
{name: asc}
]) {
name
characterType
}
}
}query {
characters {
items(
skip: 0
take: 10
orderBy: [{name: asc}]
) {
name
characterType
}
}
}To see all available types, queries, and mutations:
Open: http://localhost:8080/__schema
{
__schema {
types {
name
kind
description
}
}
}After running the server, seed data is stored in:
graphql_db/
├── Character.tbl # Character table (30+ records)
├── Film.tbl # Film table (3 records)
├── Planet.tbl # Planet table (9 records)
├── Species.tbl # Species table (8 records)
├── Starship.tbl # Starship table (7 records)
├── Vehicle.tbl # Vehicle table (5 records)
├── schema.graphql # GraphQL schema definition
└── Character_indexes/
├── id.idx # ID indexes for fast lookup
└── homePlanetId.idx # Foreign key indexes
# Check if port 8080 is already in use
netstat -ano | Select-String ":8080"
# Kill the process if needed (replace 12345 with PID)
Stop-Process -Id 12345 -Force
# Then try again
.\start-server.ps1# Check GraphQL syntax
# Make sure field names match the schema exactly
# Common mistakes:
# ❌ {characterId: "luke"} → Should be {character(id: "luke")}
# ❌ name: asc → Should be name: asc (orderBy: [{name: asc}])
# ❌ {character} → Should specify which fields {character {name}}# Run this query to verify schema loaded correctly
$query = @'
{
__type(name: "CharacterConnection") {
name
fields {
name
}
}
}
'@- filtering-guide.md - Complete filtering and sorting reference with Star Wars queries
- README.md - Architecture and features overview
- README.md - Star Wars schema details
- SCHEMA_DRIVEN_FEATURE.md - Schema-driven development
- INDEXING-TESTS-SUMMARY.md - Indexing strategy
- OPTIMIZATIONS.md - Performance tips
- Create
my_schema.graphql:
type User {
id: ID!
name: String!
email: String!
age: Int!
}
type Query {
users: [User]
user(id: ID!): User
}
type Mutation {
createUser(input: UserInput!): User
}
input UserInput {
name: String!
email: String!
age: Int!
}- Place in
graphql_db/schema.graphql - Restart server - it'll auto-generate mutations and connections!
- 📝 Check the documentation
- 🐛 Review troubleshooting guide
- 💬 Check GitHub issues or create a new one
For best results with SharpGraph:
✅ Use Indexes - Automatically created for ID fields
✅ Filter Early - Use where on the connection items
✅ Limit Results - Always use first/take for large datasets
✅ Specify Fields - Only request fields you need
✅ Use Pagination - Skip/take for browsing large result sets
✅ Built and started SharpGraph server
✅ Queried the Star Wars database
✅ Used Prisma-style filtering and sorting
✅ Created and updated data with mutations
✅ Explored the GraphQL schema
🎉 You're ready to start building with SharpGraph!
# Start server
.\start-server.ps1
# Build project
dotnet build
# Run tests
dotnet test
# Query the schema
$query = 'query { characters { items { name } } }'
$body = @{query=$query} | ConvertTo-Json
Invoke-WebRequest -Uri "http://localhost:8080/graphql" `
-Method POST -ContentType "application/json" -Body $bodyHappy querying! 🚀