Skip to content

Commit d9ebe44

Browse files
authored
Merge pull request #61 from Rentox98/sample_spring_postgres_graphql
Sample spring postgres graphql
2 parents 4043ab2 + 0c5f141 commit d9ebe44

File tree

18 files changed

+1033
-0
lines changed

18 files changed

+1033
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This repo contains the sample for [Keploy's](https://keploy.io) Java Application
2121
1. [employee-manager](https://github.com/keploy/samples-java/tree/main/employee-manager)
2222
2. [spring-boot-mongo](https://github.com/keploy/samples-java/tree/main/spring-boot-mongo)
2323
3. [user-manager](https://github.com/keploy/samples-java/tree/main/user-manager)
24+
4. [spring-boot-postgres-graphql](https://github.com/keploy/samples-java/tree/main/spring-boot-postgres-graphql)
2425

2526
## Community Support ❤️
2627

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.mvn/
2+
.idea/
3+
target/
4+
!.mvn/wrapper/maven-wrapper.jar
5+
!**/src/main/**/target/
6+
!**/src/test/**/target/
7+
8+
### STS ###
9+
.apt_generated
10+
.classpath
11+
.factorypath
12+
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
17+
### IntelliJ IDEA ###
18+
.idea
19+
*.iws
20+
*.iml
21+
*.ipr
22+
23+
### NetBeans ###
24+
/nbproject/private/
25+
/nbbuild/
26+
/dist/
27+
/nbdist/
28+
/.nb-gradle/
29+
build/
30+
!**/src/main/**/build/
31+
!**/src/test/**/build/
32+
33+
### VS Code ###
34+
.vscode/
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Library DEMO
2+
3+
### Requirements
4+
5+
- JDK 17
6+
- Maven 3.9.5
7+
- Docker or PostgreSQL
8+
9+
### About the DEMO
10+
11+
This is a Spring Boot application implementing a GraphQL service to handle requests related to books and authors.
12+
13+
The controller provides four queries:
14+
15+
- `getBookByName`: Returns a book based on the specified name.
16+
- `getAllBooks`: Retrieves all books present in the repository.
17+
- `getAuthorById`: Fetches an author based on the provided ID.
18+
- `getAllAuthors`: Retrieves all authors available in the repository.
19+
20+
# Getting Started
21+
22+
Follow the steps to start the application:
23+
24+
## Clone
25+
- First, clone the repository:
26+
27+
```bash
28+
git clone https://github.com/keploy/samples-java
29+
```
30+
Navigate to the project folder:
31+
32+
```bash
33+
cd samples-java/spring-boot-postgres-graphql
34+
```
35+
36+
## Quick Keploy Installation
37+
38+
- Depending on your OS and preference (Docker/Native), you can set up Keploy using the one-click installation method:
39+
```bash
40+
curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh
41+
```
42+
43+
## Setup DB
44+
45+
### Use postgres docker image
46+
47+
If you have Docker installed and prefer a PostgreSQL instance in a container, follow these steps:
48+
1. Build the Docker image:
49+
50+
```bash
51+
docker build -t postgres_library:demo ./postgres_demo_docker
52+
```
53+
54+
2. Run a container from the generated image:
55+
56+
```bash
57+
docker run -d -p 5432:5432 --name postgres postgres_library:demo
58+
```
59+
60+
## Use of Keploy
61+
62+
1. Your application is ready to be executed!!
63+
To start Keploy in record mode, in the root directory, run:
64+
65+
```bash
66+
keploy record -c "mvn spring-boot:run"
67+
```
68+
69+
### Query from GraphQL GUI
70+
71+
Now, go to `localhost:8081/graphiql` and access the GraphQL interface to make requests to the application.
72+
- Make a `getAllBooks` query:
73+
74+
```graphql
75+
query {
76+
getAllBooks {
77+
name
78+
author {
79+
id
80+
firstName
81+
lastName
82+
}
83+
}
84+
}
85+
```
86+
87+
- Make a `getBookByName` query:
88+
89+
```graphql
90+
query {
91+
getBookByName(name: "The Secret of the Moon") {
92+
id
93+
name
94+
pageCount
95+
author {
96+
firstName
97+
lastName
98+
}
99+
}
100+
}
101+
```
102+
103+
- Make a `getAllAuthors` query:
104+
105+
```graphql
106+
query {
107+
getAllAuthors {
108+
id
109+
firstName
110+
lastName
111+
}
112+
}
113+
```
114+
115+
- Make a `getAuthorById` query:
116+
117+
```graphql
118+
query {
119+
getAuthorById(id: 2) {
120+
firstName
121+
}
122+
}
123+
```
124+
125+
You can experiment with the data you want to retrieve from the query by removing or rearranging fields.
126+
127+
The generated tests and mocks are stored in the `Keploy` directory in the current working directory.
128+
129+
130+
### Execute tests
131+
132+
To test the app, start Keploy in test mode. In the root directory, run:
133+
134+
```bash
135+
keploy test -c "mvn spring-boot:run" --delay 15
136+
```
137+
138+
This will run the tests and generate the report in the `Keploy/reports` directory in the current working directory.
139+

0 commit comments

Comments
 (0)