A full-stack GraphQL application for managing books and authors, built with TypeScript, Express, and a responsive frontend.
- GraphQL API with queries and mutations
- TypeScript for type safety
- Responsive Frontend with vanilla HTML/CSS/JavaScript
- CRUD Operations for books and authors
- GraphiQL Playground for API exploration
- CORS enabled for cross-origin requests
graphql-basic/
├── src/
│ └── server.ts # Main server file with GraphQL schema
├── public/
│ └── index.html # Frontend interface
├── dist/ # Compiled JavaScript output
├── package.json
├── tsconfig.json
└── README.md
-
Clone or download the project
-
Install dependencies:
npm install
-
Build the TypeScript project:
npm run build
-
Start the server:
npm start
For development with auto-reload on file changes:
npm run dev
- Build the project:
npm run build
- Start the server:
npm start
To automatically compile TypeScript on changes:
npm run watch
- Frontend Interface: http://localhost:4000
- GraphQL API: http://localhost:4000/graphql
- GraphiQL Playground: http://localhost:4000/graphql
query {
books {
id
name
author {
id
name
}
}
}
query {
authors {
id
name
books {
id
name
}
}
}
query {
book(id: 1) {
id
name
author {
id
name
}
}
}
mutation {
addBook(name: "New Book Title", authorId: 1) {
id
name
author {
id
name
}
}
}
mutation {
addAuthor(name: "New Author Name") {
id
name
books {
id
name
}
}
}
The web interface provides:
- View Books: Display all books with their authors
- Add Books: Form to add new books with author selection
- View Authors: Display all authors with their book counts
- Add Authors: Form to add new authors
- Real-time Updates: Automatic refresh after adding items
- Error Handling: User-friendly error messages
- Backend: Node.js, Express, GraphQL
- Frontend: HTML5, CSS3, Vanilla JavaScript
- Language: TypeScript
- Development: ts-node-dev for hot reload
express
- Web frameworkexpress-graphql
- GraphQL middleware for Expressgraphql
- GraphQL implementation
typescript
- TypeScript compiler@types/express
- Type definitions for Express@types/node
- Type definitions for Node.jsts-node-dev
- Development server with auto-reloadnodemon
- File watcher for development
-
Start the server:
npm run dev
-
Open your browser:
- Frontend: http://localhost:4000
- GraphQL Playground: http://localhost:4000/graphql
-
Try the API:
- Use the frontend to add books and authors
- Explore the API in GraphiQL playground
- Test queries and mutations
The application comes with sample data:
Authors:
- J. K. Rowling
- J. R. R. Tolkien
- Brent Weeks
Books:
- Harry Potter series (by J. K. Rowling)
- Lord of the Rings trilogy (by J. R. R. Tolkien)
- Night Angel series (by Brent Weeks)
- Fork the project
- Create a feature branch
- Make your changes
- Test your changes
- Submit a pull request
This project is licensed under the ISC License.
Happy coding! 🚀