Skill站外收录 @skilllib/skill-2117939930272411461
apollo-local-dev-loop
为 Apollo.io 本地开发提供完整闭环支持,涵盖环境变量配置、带请求响应日志的开发客户端搭建、基于 MSW 的 API 模拟服务、自动化测试脚本及配额监控能力,确保团队在无真实 API 依赖下高效迭代与调试。
开发运维 AI 技能
Skills.MD
# Apollo Local Dev Loop
## Overview
Set up efficient local development workflow for Apollo.io integrations with proper environment management, testing, and debugging.
## Prerequisites
- Completed `apollo-install-auth` setup
- Node.js 18+ or Python 3.10+
- Git repository initialized
## Instructions
### Step 1: Environment Setup
```bash
# Create environment files
touch .env .env.example .env.test
# Add to .gitignore
echo '.env' >> .gitignore
echo '.env.local' >> .gitignore
```
```bash
# .env.example (commit this)
APOLLO_API_KEY=your-api-key-here
APOLLO_RATE_LIMIT=100
APOLLO_ENV=development
```
### Step 2: Create Development Client
```typescript
// src/lib/apollo-dev.ts
import axios from 'axios';
const isDev = process.env.NODE_ENV !== 'production';
export const apolloClient = axios.create({
baseURL: 'https://api.apollo.io/v1',
params: { api_key: process.env.APOLLO_API_KEY },
});
// Add request logging in development
if (isDev) {
apolloClient.interceptors.request.use((config) => {
console.log(`[Apollo] ${config.method?.toUpperCase()} ${config.url}`);
return config;
});
apolloClient.interceptors.response.use(
(response) => {
console.log(`[Apollo] Response: ${response.status}`);
return response;
},
(error) => {
console.error(`[Apollo] Error: ${error.response?.status}`, error.message);
return Promise.reject(error);
}
);
}
```
### Step 3: Create Mock Server for Testing
```typescript
// src/mocks/apollo-mock.ts
import { rest } from 'msw';
export const apolloHandlers = [
rest.post('https://api.apollo.io/v1/people/search', (req, res, ctx) => {
return res(
ctx.json({
people: [
{ id: '1', name: 'Test User', title: 'Engineer', email: 'test@example.com' },
],
pagination: { page: 1, per_page: 10, total_entries: 1 },
})
);
}),
rest.get('https://api.apollo.io/v1/organizations/enrich', (req, res, ctx) => {
return res(
ctx.json({
organization: {
name: 'Test Company',
domain: 'test.com',
industry: 'Technology',
},
})
);
}),
];
```
### Step 4: Development Scripts
```json
{
"scripts": {
"dev": "NODE_ENV=development tsx watch src/index.ts",
"dev:mock": "MOCK_APOLLO=true npm run dev",
"test:apollo": "vitest run src/**/*.apollo.test.ts",
"apollo:quota": "tsx scripts/check-apollo-quota.ts"
}
}
```
### Step 5: Quota Monitoring Script
```typescript
// scripts/check-apollo-quota.ts
import { apolloClient } from '../src/lib/apollo-dev';
async function checkQuota() {
try {
const { data } = await apolloClient.get('/auth/health');
console.log('API Status:', data);
// Note: Apollo doesn't expose quota directly, track usage manually
} catch (error: any) {
if (error.response?.status === 429) {
console.error('Rate limited! Wait before making more requests.');
}
}
}
checkQuota();
```
## Output
- Environment file structure (.env, .env.example)
- Development client with logging interceptors
- Mock server for testing without API calls
- npm scripts for development workflow
- Quota monitoring utility
## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| Missing API Key | .env not loaded | Run `source .env` or use dotenv |
| Mock Not Working | MSW not configured | Ensure setupServer is called |
| Rate Limited in Dev | Too many test calls | Use mock server for tests |
| Stale Credentials | Key rotated | Update .env with new key |
## Examples
### Watch Mode Development
```bash
# Terminal 1: Run dev server with watch
npm run dev
# Terminal 2: Test API calls
curl -X POST http://localhost:3000/api/apollo/search \
-H "Content-Type: application/json" \
-d '{"domain": "stripe.com"}'
```
### Testing with Mocks
```typescript
// src/services/apollo.apollo.test.ts
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { setupServer } from 'msw/node';
import { apolloHandlers } from '../mocks/apollo-mock';
import { searchPeople } from './apollo';
const server = setupServer(...apolloHandlers);
beforeAll(() => server.listen());
afterAll(() => server.close());
describe('Apollo Service', () => {
it('searches for people', async () => {
const results = await searchPeople({ domain: 'test.com' });
expect(results.people).toHaveLength(1);
expect(results.people[0].name).toBe('Test User');
});
});
```
## Resources
- [MSW (Mock Service Worker)](https://mswjs.io/)
- [Vitest Testing Framework](https://vitest.dev/)
- [dotenv Documentation](https://github.com/motdotla/dotenv)
## Next Steps
Proceed to `apollo-sdk-patterns` for production-ready code patterns.
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「apollo-local-dev-loop」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次