This project is a simple CRUD application built with Spring Boot and GraphQL, showcasing how to manage products using modern GraphQL queries and mutations. The project adheres to clean code principles and uses H2 database for development.
- GraphQL Queries and Mutations for CRUD operations:
- Create, Read, Update, Delete products.
- Integrated GraphiQL interface for testing.
- H2 in-memory database for easy development and testing.
- Follows clean code and best practices.
- Spring Boot (v3.x)
- Spring Data JPA
- GraphQL Java
- H2 Database
- Lombok
- Maven
- Java 17 or higher installed on your system.
- Maven (v3.x or higher) installed.
- Recommended IDE: IntelliJ IDEA.
-
Clone the repository:
git clone https://github.com/charlybutar21/springboot-graphQL.git cd springboot-graphQL
-
Build the project:
mvn clean install
-
Run the application:
mvn spring-boot:run
-
Access the application:
- GraphQL endpoint: http://localhost:8080/graphql
- GraphiQL interface: http://localhost:8080/graphiql?path=/graphql
-
Get All Products
query { getAllProducts { id name description price } }
-
Get Product By ID
query { getProductById(id: "1") { id name description price } }
-
Create Product
mutation { createProduct(input: { name: "New Product", description: "Product description", price: 100.0 }) { id name description price } }
-
Update Product
mutation { updateProduct(id: "1", input: { name: "Updated Product", description: "Updated description", price: 150.0 }) { id name description price } }
-
Delete Product
mutation { deleteProduct(id: "1") }
- Import the postman-collection.json.
- Use the pre-defined queries and mutations for testing.
- Open http://localhost:8080/graphiql?path=/graphql.
- Use the interactive UI to test queries and mutations.