UserLookup is a robust Spring Boot application showcasing the power and flexibility of GraphQL for managing user and post information. This project demonstrates how to build an efficient API where clients can query precisely the data they need — no more, no less — and mutate data with ease.
Designed for simplicity yet extensibility, UserLookup includes features like user retrieval, paginated queries, post creation, and relationship management between users and their posts.
- GraphQL API with clearly defined types, queries, mutations, and input types.
- Layered architecture: Model, Repository, Service, Resolver
- Custom exception handling
- Input validation
- Pagination and filtering support
- Retrieve individual users or all users.
- Fetch posts authored by a specific user.
- Create new users and posts via mutations.
- Relationship handling: users have multiple posts, and posts reference their author.
- Clean and extendable GraphQL schema for easy enhancements.
- In-memory H2 database for quick setup and testing.
- Java 17
- Spring Boot 3
- Spring GraphQL
- Spring Data JPA
- H2 Database
-
Clone the repository:
git clone https://github.com/PritiAryal/UserLookup.git cd UserLookup -
Build the project using Maven:
mvn clean install
-
Access the GraphQL endpoint at http://localhost:8080/graphql.
query {
getUser(id: "1") {
id
name
email
posts {
id
title
}
}
}query {
getAllUsers {
id
name
email
}
}query {
getUsersPaged(page: 0, size: 2) {
id
name
email
}
}query {
getPostsByUser(userId: "1") {
id
title
content
}
}mutation {
createUser(input: { name: "Alice Johnson", email: "alice@example.com" }) {
id
name
email
}
}mutation {
createPost(input: { title: "GraphQL with Spring", content: "Content goes here", authorId: "1" }) {
id
title
author {
id
name
}
}
}You can test the UserLookup GraphQL API using Postman either by sending raw JSON requests or using Postman’s native GraphQL support.
-
Step 1: Open Postman and create a new POST request.
-
Step 2: Set the request URL to:
http://localhost:8080/graphql
Step 3: Go to the Headers tab and ensure you have:
| Key | Value |
|---|---|
| Content-Type | application/json |
Step 4: Go to the Body tab, select raw, and choose JSON as the format.
Step 5: Paste your GraphQL query or mutation inside a JSON object with the query key.
Example Query:
{
"query": "query { getUser(id: \"1\") { id name email posts { id title } } }"
}Example Mutation:
{
"query": "mutation { createUser(input: { name: \"Alice\", email: \"alice@example.com\" }) { id name email } }"
}Step 6: Click Send. You should receive a JSON response with data.
Step 1: Create a new request in Postman.
Step 2: Set the HTTP method to POST and the URL to:
http://localhost:8080/graphqlGo to the Headers tab and ensure you have:
| Key | Value |
|---|---|
| Content-Type | application/json |
Step 3: Instead of selecting raw body, switch to the GraphQL tab (next to Body). Step 4: In the QUERY section, write your GraphQL query or mutation, for example:
query {
getUser(id: "1") {
id
name
email
posts {
id
title
}
}
}Step 5: If your query requires variables, add them in the VARIABLES section in JSON format. For example:
{
"id": "1"
}Step 6: Click Send to execute the query and view the response.
Step 1: Open Postman and create a new request. Step 2: No need to set the request method, just add the URL:
http://localhost:8080/graphqlGo to the Headers tab and ensure you have:
| Key | Value |
|---|---|
| Content-Type | application/json |
| Step 3: Import the GraphQL schema by clicking on the Query tab and then Import Schema. This will allow Postman to understand the types and queries available in your GraphQL API. |
Step 4: You can just select the query or mutation you want to execute from the list of available operations. And add any required variables in the VARIABLES section.
Step 5: Click Send to execute the query or mutation and view the response.

Once your Spring Boot application is running with the H2 database enabled, you can access the H2 web console to view and interact with the database.
-
Run your application.
Make sure the app is running locally (e.g., on port 8080). -
Open your web browser.
-
Navigate to the H2 console URL:
http://localhost:8080/h2-console- Configure the connection settings:
- JDBC URL:
jdbc:h2:mem:testdb(according toapplication.properties) - User Name:
sa - Password: (leave blank)
- JDBC URL:
- Click on the "Connect" button. You should now be able to see the H2 console where you can run SQL queries, view tables, and manage your in-memory database.
Important: Since the database is in-memory, all data will be lost when the application stops. This console is mainly for development and debugging purposes.




