https://github.com/rodrigobalazs/springboot-graphql
https://github.com/rodrigobalazs/springboot-graphql
docker graphql graphql-api java maven springboot springdata
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rodrigobalazs/springboot-graphql
- Owner: rodrigobalazs
- License: mit
- Created: 2025-04-04T22:29:35.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-04-07T17:23:05.000Z (9 months ago)
- Last Synced: 2025-04-09T20:17:30.324Z (9 months ago)
- Topics: docker, graphql, graphql-api, java, maven, springboot, springdata
- Language: Java
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# springboot-graphql
## Spring Boot GraphQL API
This repository contains an Spring Boot 'Store Application' which expose a GraphQL API with Queries and Mutations
used to manage operations related to the Store´s Products.
### 🔧 Technology Stack
```
Java 17
Spring Boot 3
Spring for GraphQL ( GraphQL API )
Spring Data ( MySQL )
Misc Libraries ( Maven / Docker / Lombok / Apache Commons )
```
### ⚒️ Getting Started
```bash
# clone the project
git clone https://github.com/rodrigobalazs/springboot-graphql.git;
cd springboot-graphql;
# start a mysql docker container
docker run --name store_db -e MYSQL_DATABASE=store_db -e MYSQL_USER= \
-e MYSQL_PASSWORD= -e MYSQL_ROOT_PASSWORD= \
-p 3306:3306 -d mysql:latest;
# make sure to update application.properties with the
# MYSQL_USER and MYSQL_PASSWORD values defined in the previous point
spring.datasource.username=
spring.datasource.password=
# compile and start the spring boot server
mvn clean install;
mvn spring-boot:run;
```
### 💡 GraphQL API Examples
#### 1. Get all the available Products =>
```
curl -X POST http://localhost:8080/graphql \
-H 'accept: application/json' \
-H 'Content-Type: application/json' -d \
'{
"query": "{ allProducts { id name price } }"
}';
```
#### 2. Get all the available Products ( via HTTPie ) =>
```
http POST http://localhost:8080/graphql query="{ allProducts { id name price } }";
```
#### 3. Retrieves a Product by Product Name (e.g 'Rustic Sofa') and only fetch in particular the product´s price =>
```
curl -X POST http://localhost:8080/graphql \
-H 'accept: application/json' \
-H 'Content-Type: application/json' -d \
'{
"query": "{ productByName(name:\"Rustic Sofa\") { price } }"
}';
```
#### 4. Creates a new 'Triathlon Suit' Product =>
```
curl -X POST http://localhost:8080/graphql \
-H 'accept: application/json' \
-H 'Content-Type: application/json' -d \
'{
"query":"mutation { addProduct(name:\"Triathlon Suit\", price:250.1) { id name price } }"
}';
```