A full-stack book management application built with Next.js, Apollo Server, and Apollo Client. It demonstrates a complete GraphQL CRUD workflow; querying, filtering, paginating, and mutating data, all within a single Next.js project using the Pages Router.
- Browse books - Responsive card grid with pagination and genre filtering
- Add books - Create new entries via a modal form
- Edit books - Update any field of an existing book inline
- Delete books - Remove books with instant UI refresh
- GraphQL API - Apollo Server 4 served directly from a Next.js API route
- Type-safe - End-to-end TypeScript with shared interfaces
| Layer | Technology |
|---|---|
| Framework | Next.js 15 (Pages Router, Turbopack) |
| Language | TypeScript 5 |
| GraphQL Server | Apollo Server 4 + @as-integrations/next |
| GraphQL Client | Apollo Client 3 |
| Styling | Tailwind CSS v3 + DaisyUI v4 |
| Package Manager | pnpm |
src/
├── datas/
│ └── books.ts # In-memory seed data
├── lib/
│ └── graphql.tsx # Apollo Client instance
├── pages/
│ ├── index.tsx # Main UI — book list + CRUD forms
│ └── api/
│ └── books.ts # GraphQL API route (Apollo Server)
└── styles/
└── globals.css
The GraphQL endpoint is available at POST /api/books.
# Fetch books with optional pagination and genre filter
query Books($limit: Int, $offset: Int, $genre: String) {
books(limit: $limit, offset: $offset, genre: $genre) {
id
title
author
publishedYear
genre
price
}
}
# Fetch a single book by ID
query Book($id: Int) {
book(id: $id) {
id
title
author
publishedYear
genre
price
}
}mutation AddBook($title: String!, $author: String!, $price: Float!, $genre: String!, $publishedYear: Int!) {
addBook(title: $title, author: $author, price: $price, genre: $genre, publishedYear: $publishedYear) {
id
title
}
}
mutation UpdateBook($id: Float!, $title: String, $author: String, $price: Float, $genre: String, $publishedYear: Int) {
updateBook(id: $id, title: $title, author: $author, price: $price, genre: $genre, publishedYear: $publishedYear) {
id
title
}
}
mutation DeleteBook($id: Float!) {
deleteBook(id: $id)
}# Clone the repository
git clone https://github.com/SeanardK/graphql-book_library
cd graphql-book_library
# Install dependencies
pnpm installpnpm devOpen http://localhost:3000 in your browser.
pnpm build
pnpm startpnpm lint- Apollo Server is initialized in
src/pages/api/books.tsusingstartServerAndCreateNextHandlerfrom@as-integrations/next, which wraps it as a standard Next.js API route handler. - Schema & Resolvers are defined in the same file. The resolver layer operates on an in-memory
booksarray imported fromsrc/datas/books.ts. - Apollo Client (
src/lib/graphql.tsx) points to the local/api/booksendpoint and uses anInMemoryCachefor client-side caching. - The front-end page (
src/pages/index.tsx) usesuseQueryto fetch and display books, anduseMutationto add, update, and delete them — callingrefetch()after each mutation to keep the UI in sync.