A GraphQL API for managing products and categories built with .NET 8 and Hot Chocolate.
- GraphQL API with Hot Chocolate
- Entity Framework Core with SQLite
- Clean Architecture
- CRUD operations for Products and Categories
- Error handling and logging
- .NET 8 SDK
- SQLite (included in the project)
- Your favorite IDE (VS Code, Visual Studio, Rider, etc.)
- Clone the repository:
git clone https://github.com/giovanoh/products-graphql
cd products-graphql- Restore dependencies:
dotnet restore- Run the application:
dotnet run --project src/Products.APIThe API will be available at http://localhost:5000/graphql
The GraphQL endpoint is available at /graphql. You can use tools like Banana or GraphQL Playground to interact with the API.
Products:
getProducts: List all productsgetProductById(id: Int!): Get a specific product by ID
Categories:
getCategories: List all categoriesgetCategoryById(id: Int!): Get a specific category by ID
Products:
createProduct(input: ProductInput!): Create a new productinput ProductInput { name: String! price: Decimal! description: String! categoryId: Int! }
updateProduct(id: Int!, input: UpdateProductInput!): Update an existing productinput UpdateProductInput { name: String price: Decimal description: String categoryId: Int }
deleteProduct(id: Int!): Delete a product
Categories:
createCategory(input: CategoryInput!): Create a new categoryinput CategoryInput { name: String! }
updateCategory(id: Int!, input: UpdateCategoryInput!): Update an existing categoryinput UpdateCategoryInput { name: String }
deleteCategory(id: Int!): Delete a category
src/
├── Products.API/
│ ├── Domain/ # Domain models and interfaces
│ ├── GraphQL/ # GraphQL types, queries, and mutations
│ ├── Infrastructure/ # Data access and external services
│ └── Program.cs # Application entry point
This project is licensed under the MIT License - see the LICENSE file for details.