This project demonstrates how to implement a GraphQL API layer over an existing REST API using Apollo Server. It uses the JSONPlaceholder API as an example REST endpoint.
- GraphQL server using Apollo Server
- REST API integration using Axios
- Example queries for Users and Posts
- Nested resolvers for related data
- Install dependencies:
pnpm install
- Start the development server:
pnpm dev
The GraphQL server will be available at http://localhost:4000
query {
posts {
id
title
body
user {
id
name
email
}
}
}
query {
user(id: "1") {
name
email
posts {
id
title
body
}
}
}
src/index.js
- Main server file containing GraphQL schema and resolvers- REST API integration is handled in the resolvers
- Uses JSONPlaceholder API (
https://jsonplaceholder.typicode.com
) for demo data
- Node.js
- Apollo Server
- GraphQL
- Axios for HTTP requests
- PNPM for package management