A .NET Core GraphQL application built with HotChocolate for a carpooling service.
- GraphQL API with HotChocolate
- Entity Framework Core with SQL Server
- Real-time subscriptions for live updates
- Comprehensive data model for carpooling services
- Filtering, sorting, and projections support
- .NET 8.0 SDK
- SQL Server (LocalDB or full instance)
- Visual Studio 2022 or VS Code
-
Create the database using the provided SQL script:
- Open
SQL/CarpoolingSchema.txt - Execute the script in SQL Server Management Studio or Azure Data Studio
- Or use the Entity Framework migrations (see below)
- Open
-
Update connection string in
appsettings.jsonif needed:{ "ConnectionStrings": { "DefaultConnection": "Server=(LocalDB)\\MSSQLLocalDB;Database=CarpoolingDB;Trusted_Connection=True;MultipleActiveResultSets=true;" } }
If you want to use EF migrations instead of the SQL script:
# Add initial migration
dotnet ef migrations add InitialCreate
# Update database
dotnet ef database update-
Restore packages:
dotnet restore
-
Run the application:
dotnet run
-
Access the application:
- GraphQL endpoint:
https://localhost:7000/graphql - GraphQL Playground:
https://localhost:7000/graphql-voyager - Swagger UI:
https://localhost:7000/swagger
- GraphQL endpoint:
users- Get all usersuser(userId: Int!)- Get user by IDdrivers- Get all driversdriver(driverId: Int!)- Get driver by IDriders- Get all ridersrider(riderId: Int!)- Get rider by IDbookings- Get all bookingsbooking(bookingId: UUID!)- Get booking by IDpackages- Get all packagespackage(packageId: Int!)- Get package by IDpackageCategories- Get all package categoriespayments- Get all paymentstransactions- Get all transactions
createUser(input: CreateUserInput!)- Create a new usercreateDriver(input: CreateDriverInput!)- Create a new drivercreateRider(input: CreateRiderInput!)- Create a new ridercreateBooking(input: CreateBookingInput!)- Create a new bookingcreatePackage(input: CreatePackageInput!)- Create a new packagecreatePayment(input: CreatePaymentInput!)- Create a new paymentupdateBookingStatus(bookingId: UUID!, status: String!)- Update booking status
onBookingStatusChanged- Subscribe to booking status changesonDriverLocationUpdated- Subscribe to driver location updatesonPaymentReceived- Subscribe to payment notificationsonRideCompleted- Subscribe to ride completion events
query {
users {
userId
firstName
lastName
email
role {
roleName
}
}
}mutation {
createUser(input: {
firstName: "John"
lastName: "Doe"
email: "john.doe@example.com"
passwordHash: "hashedpassword"
phoneNumber: "+1234567890"
roleId: 1
}) {
userId
firstName
lastName
email
}
}query {
booking(bookingId: "123e4567-e89b-12d3-a456-426614174000") {
bookingId
pickupLocation
dropoffLocation
bookingStatus
requestedTime
rider {
user {
firstName
lastName
}
}
driver {
user {
firstName
lastName
}
vehicleType
vehiclePlateNumber
}
package {
packageName
price
}
}
}CarpoolingGraphQL/
├── Models/ # Entity models
├── Data/ # DbContext and data access
├── GraphQL/ # GraphQL types (Query, Mutation, Subscription)
├── SQL/ # Database schema script
├── appsettings.json # Configuration
├── Program.cs # Application entry point
└── README.md # This file
- .NET 8.0 - Framework
- HotChocolate 13.7.0 - GraphQL server
- Entity Framework Core 8.0 - ORM
- SQL Server - Database
- ASP.NET Core - Web framework
- Create new model in
Models/folder - Add DbSet to
CarpoolingDbContext - Add queries/mutations in
GraphQL/Query.csorGraphQL/Mutation.cs - Configure relationships in
OnModelCreatingmethod
- Modify entity models
- Create new migration:
dotnet ef migrations add MigrationName - Update database:
dotnet ef database update
-
Database connection failed
- Verify SQL Server is running
- Check connection string in
appsettings.json - Ensure database exists
-
GraphQL schema errors
- Check for missing using statements
- Verify entity relationships are properly configured
- Ensure all required packages are installed
-
Migration errors
- Delete existing migrations folder
- Drop and recreate database
- Run
dotnet ef database updateagain
This project is for educational and development purposes.