A modern GraphQL API for employee recognition and appreciation systems, built with Apollo Server, TypeScript, and WebSocket subscriptions for real-time updates.
- GraphQL API with Apollo Server v4
- Real-time subscriptions using WebSocket
- Employee recognition system with reactions and comments
- Role-based access control (Employee, Manager, HR)
- Custom GraphQL interface for easy testing
- TypeScript for type safety
- In-memory data storage (ready for database integration)
- Node.js >= 16.0.0
- npm or yarn
-
Clone the repository
git clone <repository-url> cd employee-recognition-api
-
Install dependencies
npm install
-
Start the development server
npm start
Or for development with auto-restart:
npm run dev
- Main Server: http://localhost:4000
- Custom GraphQL Interface: http://localhost:4000
- Apollo Studio: http://localhost:4000/graphql
- WebSocket Subscriptions: ws://localhost:4000/graphql
- Users: Employees, Managers, and HR personnel
- Recognitions: Appreciation messages between employees
- Reactions: Emoji reactions on recognitions
- Comments: Text comments on recognitions
Currently uses a simple token-based system:
- Format:
Bearer token_<userId>
- Example:
Bearer token_1
for user with ID "1"
The system comes with pre-configured users:
ID | Name | Role | Team | Department | |
---|---|---|---|---|---|
1 | John Doe | [email protected] | EMPLOYEE | Engineering | Technology |
2 | Jane Smith | [email protected] | MANAGER | Engineering | Technology |
3 | Bob Wilson | [email protected] | HR | HR | Human Resources |
4 | Sarah Johnson | [email protected] | EMPLOYEE | Design | Product |
5 | Mike Chen | [email protected] | MANAGER | Design | Product |
6 | Emily Davis | [email protected] | EMPLOYEE | Marketing | Sales |
7 | David Rodriguez | [email protected] | MANAGER | Marketing | Sales |
query {
users {
id
name
email
role
team
department
recognitionsReceivedCount
recognitionsGivenCount
}
}
query {
recognitions {
id
message
emoji
from {
id
name
}
to {
id
name
}
reactions {
emoji
user {
name
}
}
comments {
message
user {
name
}
}
createdAt
}
}
query {
user(id: "1") {
id
name
email
role
recognitionsReceived {
id
message
from {
name
}
}
recognitionsGiven {
id
message
to {
name
}
}
}
}
mutation {
createRecognition(input: {
fromId: "1"
toId: "2"
message: "Great work on the project!"
emoji: "π"
}) {
id
message
emoji
from {
name
}
to {
name
}
}
}
mutation {
addReaction(input: {
recognitionId: "1"
userId: "3"
emoji: "π"
}) {
id
emoji
user {
name
}
}
}
mutation {
addComment(input: {
recognitionId: "1"
userId: "4"
message: "I agree! Well done!"
}) {
id
message
user {
name
}
}
}
subscription {
recognitionCreated {
id
message
emoji
from {
name
}
to {
name
}
createdAt
}
}
subscription {
reactionAdded {
id
emoji
recognition {
id
message
}
user {
name
}
}
}
The project includes test files in the tests/
directory:
queries.graphql
- Sample queries for testingmutations.graphql
- Sample mutations for testingsubscriptions.graphql
- Sample subscriptions for testing
employee-recognition-api/
βββ server.ts # Main server file with GraphQL setup
βββ schema.graphql # GraphQL schema definitions
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ public/ # Static files (custom UI)
β βββ index.html # Custom GraphQL interface
βββ tests/ # Test files
β βββ queries.graphql
β βββ mutations.graphql
β βββ subscriptions.graphql
βββ README.md # This file
npm start
- Start the server with ts-nodenpm run dev
- Start with nodemon for developmentnpm run build
- Build TypeScript to JavaScriptnpm test
- Run Jest tests
- Schema Changes: Update
schema.graphql
- Resolvers: Add to the resolvers object in
server.ts
- Validation: Add validation functions as needed
- Testing: Add test queries/mutations to the
tests/
directory
PORT
- Server port (default: 4000)NODE_ENV
- Environment (development/production)
The current implementation uses in-memory storage. For production:
- Replace the in-memory arrays with database calls
- Add proper authentication (JWT, OAuth, etc.)
- Implement proper error handling and logging
- Add rate limiting and security measures
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details
For issues and questions:
- Check the existing issues
- Create a new issue with detailed information
- Include error messages and steps to reproduce
Happy Coding! π