This is a sample application to demonstrate the following key features
- Queries
- Mutations
The project is composed of two sub-projects
- graphql-service: GraphQL service with GraphiQL for interacting with GraphQL
- rest-service: Backend service provider
- JDK 8 or above
- Ensure port 2020 and 8080 are free to use
- Docker with Docker Compose for your OS
Execute following commands to start the apps from root folder (order isn't important)
./gradlew :graphql-service:clean :graphql-service:build :graphql-service:bootRun
./gradlew :rest-service:clean :rest-service:build :rest-service:bootRun
Execute the following command
./gradlew clean build composeUp
If the above command executes successfully then you should see two containers running.
If you managed to run the application following either of the approaches mentioned above you can now access the GraphQL service using GraphiQL interface at the following address
http://localhost:2020/graphiql
- Query for all products
{
products{
id,
name,
prices {
priceRows {
price,
currency
}
}
stock
}
}
- Query for a product
query($productId : String)
{
product(productId : $productId) {
name,
id,
status,
prices {
priceRows {
price,
currency
}
},
stock
}
}
// variable definition, copy to Query Variables in GraphiQL
{
"productId": "BT056446"
}
- Mutation operation
mutation product($productInput: ProductInput) {
updateProduct(productInput: $productInput) {
id,
name,
status
stock,
prices {
id,
priceRows {
price,
currency
}
}
}
}
// variable definition, copy to Query Variables in GraphiQL
{
"productInput": {
"id": "BT056446",
"name": "12 pce White Scratches Dinner Set",
"status": "online",
"price": {
"id": "BT056446",
"priceRows": [
{
"currency": "GBP",
"price": 49.5
},
{
"currency": "EUR",
"price": 55.6
}
]
},
"stock": {
"id": "BT056446",
"warehouses": [
{
"name": "north",
"stockOnHand": 14
},
{
"name": "north",
"stockOnHand": 24
}
]
}
}
}