GraphQL API
Build flexible, type-safe GraphQL APIs with Apollo Server.
Quick Start
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
const typeDefs = `#graphql
type Query {
hello: String
}`;
const resolvers = { Query: { hello: () => 'Hello world' } };
const server = new ApolloServer({ typeDefs, resolvers });
const { url } = await startStandaloneServer(server, { listen: { port: 4000 } });
console.log(`Server ready at ${url}`);
When to Use
- ✅ Flexible APIs with custom queries
- ✅ Multiple data sources (REST, DB, gRPC)
- ❌ Not for simple CRUD (better REST)
Step-by-Step Instructions
- Install:
npm install @apollo/server graphql - Define schema with typeDefs
- Write resolvers
- Run:
npx ts-node index.ts
Dependencies
npm install @apollo/server graphql
Examples
Input: { users { id name } } → Output: JSON with user data
Resources
Validation
- Server starts on port 4000
- GraphQL Playground accessible
- Queries return expected data
Source: ssrjkk/claude-skills — distributed by TomeVault.