store-springboot is a multi-module GraphQL API Spring Boot application that manage our 3 entities through CRUD operations:
- User
- Product
- Order
- spring-boot-starter-data-jpa
- spring-boot-starter-web
- spring-boot-devtools
- mysql-connector-java
- graphql-java-tools
- graphiql-spring-boot-starter
- JDK 11
- Maven
Clone this repository to your local machine https://github.com/javato/storeAssignment
.
Import as a maven project.
As it is a Spring Boot Application, a way is to execute the main method in the org.jroldan.store.launcher.ControllerLauncher
class from your IDE.
Instead of download the source code and run it locally, we have the possibility to deploy it directly using a Docker image.
In order to run this image you will need docker installed.
We can pull it to our computer from our public repository:
docker pull dozze/store-springboot-jroldan:onlyjre
And then run it:
docker run --name store-springboot-jroldan -p 8080:8080 dozze/store-springboot-jroldan:onlyjre
- Our server is listening for GraphQL requests at
http://localhost:8080/graphql
- We can make requests through GraphiQL at
http://localhost:8080/graphiql
Our main schema file is schema.graphqls
, and it is extended by:
user.graphqls
product.graphqls
order.graphqls
Collection file of requests to import in Postman: StoreAssignment.postman_collection.json
- Create User
mutation{
saveUser(user: {
name: "New Name"
email: "New Email"
password:"New Password"
}) {
idUser
name
email
password
}
}
- Read User
query{
getUser(idUser: 5) {
idUser
name
email
password
}
}
- Read all Users
query{
getAllUsers{
idUser
name
email
password
}
}
- Update User
mutation{
saveUser(user: {
idUser: 8
name: "Updated Name"
email: "New Email"
password:"New Password"
}) {
idUser
name
email
password
}
}
- Delete User
mutation{
deleteUser(id: 7)
}
- Create Product
mutation{
saveProduct(product: {
name: "New Product"
stock: 100
price: 25.99
}) {
idProduct
name
stock
price
}
}
- Read Product
query{
getProduct(idProduct: 5) {
idProduct
name
stock
price
}
}
- Read all Products
query{
getAllProducts{
idProduct
name
stock
price
}
}
- Update Product
mutation{
saveProduct(product: {
idProduct: 7
name: "Updated Product"
stock: 100
price: 25.99
}) {
idProduct
name
stock
price
}
}
- Update Stock
mutation{
updateStock(idProduct: 5, stock: 100) {
idProduct
name
stock
price
}
}
- Delete Product
mutation{
deleteProduct(idProduct: 12)
}
- Create Order
mutation {
newOrder(order :{
productLines: [
{
quantity: 1
product:{
idProduct: 4
}
}
{
quantity: 2
product: {
idProduct: 5
}
}
]
user:{
idUser: 5
}
}) {
idOrder
productLines{
product{
idProduct
name
stock
price
}
quantity
}
user{
idUser
name
email
}
}
}
query{
getOrdersByUser(user: {idUser: 1}) {
idOrder
productLines{
product{
idProduct
name
stock
price
}
}
}
}
query{
findProductsByIdOrder(idOrder: 1) {
idProduct
name
stock
price
}
}
Released under the Apache License 2.0. See the LICENSE file.