This project is a simple GraphQL API built using Apollo Server and Express. The API manages donations and metrics for a charity organization.
The Charity API allows users to:
- Query donations: Retrieve a list of donation records.
- Query metrics: View charity metrics such as "Lives Impacted" and "Projects Funded."
- Add donations: Add new donations via GraphQL mutations.
This project follows Clean Architecture principles, which ensure a clean separation of concerns.
- Node.js (v18+)
- TypeScript
- Apollo Server (GraphQL)
- Express.js
- Clean Architecture Principles
Follow these steps to set up and run the API locally:
- Node.js (v18+)
- npm or yarn package manager
-
Clone the repository:
git clone https://github.com/your-repo/charity-api.git cd charity-api
-
Install dependencies:
npm install
-
Start the server:
npm run dev
-
Open the GraphQL Playground at:
http://localhost:4000/graphql
The API exposes the following endpoints:
-
Query:
donations
: Retrieve all donations.metrics
: Retrieve charity metrics.
-
Mutation:
addDonation
: Add a new donation record.
query {
donations {
id
month
amount
donorName
category
}
}
query {
metrics {
label
type
value
}
}
mutation {
addDonation(
amount: 5000
donorName: "John Doe"
month: "Jan"
category: "education"
) {
id
amount
donorName
month
category
}
}
src/
├── application/ # Business logic and use cases
├── domain/ # Entities and business rules
│ └── Metric.ts
├── infrastructure/ # GraphQL setup and server config
│ ├── graphql/
│ │ ├── resolvers.ts # GraphQL resolvers
│ │ └── schema.ts # GraphQL schema
│ └── server/
│ └── index.ts # Apollo Server initialization
├── interfaceAdapters/ # Repositories and controllers
└── shared/ # Shared types and utilities
- Get Data:
curl --request POST \
--url https://charity-8ba6095og-angels-projects-1a4dcd1f.vercel.app/graphql \
--header 'Content-Type: application/json' \
--data '{"query":"query Query { metrics { label type value } donations { amount category donorName id month } }"}'
- Create Data:
curl --request POST \
--url https://charity-8ba6095og-angels-projects-1a4dcd1f.vercel.app/graphql \
--header 'Content-Type: application/json' \
--data '{
"query": "mutation AddDonation($amount: Float!, $donorName: String!, $month: String!, $category: String!) { addDonation(amount: $amount, donorName: $donorName, month: $month, category: $category) { id amount donorName month category } }",
"variables": {
"amount": 10000,
"donorName": "John Doe",
"month": "March",
"category": "Education"
}
}'
This project is licensed under the MIT License. See the LICENSE file for details.
Your Name
Angel Prieto