A .NET 8 GraphQL API service built with Hot Chocolate and Entity Framework Core.
- GraphQL queries with filtering, sorting, and projections
- GraphQL mutations for CRUD operations
- Entity Framework Core with in-memory database
- Seeded sample data (Books and Authors)
- Integration tests
# Run the API
cd src/DotnetGraphQL.Api
dotnet runNavigate to https://localhost:5001/graphql to access the Banana Cake Pop GraphQL IDE.
# Get all books
{
books {
id
title
genre
publishedYear
author {
name
}
}
}
# Get a specific author with their books
{
authorById(id: 1) {
name
bio
books {
title
publishedYear
}
}
}
# Add a new book
mutation {
addBook(title: "New Book", genre: "Fiction", publishedYear: 2024, authorId: 1) {
id
title
}
}dotnet testDotnetGraphQL/
├── src/DotnetGraphQL.Api/
│ ├── Models/ # Entity models (Book, Author)
│ ├── Data/ # EF Core DbContext with seed data
│ ├── GraphQL/
│ │ ├── Types/ # GraphQL type definitions
│ │ ├── Queries/ # GraphQL query resolvers
│ │ └── Mutations/ # GraphQL mutation resolvers
│ └── Program.cs # App configuration
└── tests/DotnetGraphQL.Tests/
└── GraphQLTests.cs # Integration tests