home / skills / jeremylongshore / claude-code-plugins-plus-skills / apollo-local-dev-loop

This skill helps you set up a reusable Apollo local dev workflow with environment management, logging, mocks, and testing scripts.

npx playbooks add skill jeremylongshore/claude-code-plugins-plus-skills --skill apollo-local-dev-loop

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
5.1 KB
---
name: apollo-local-dev-loop
description: |
  Configure Apollo.io local development workflow.
  Use when setting up development environment, testing API calls locally,
  or establishing team development practices.
  Trigger with phrases like "apollo local dev", "apollo development setup",
  "apollo dev environment", "apollo testing locally".
allowed-tools: Read, Write, Edit, Bash(npm:*), Bash(pip:*), Grep
version: 1.0.0
license: MIT
author: Jeremy Longshore <[email protected]>
---

# 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: '[email protected]' },
        ],
        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.

Overview

This skill configures a robust local development workflow for Apollo.io integrations, focusing on environment management, local testing, and debugging. It provides a development HTTP client with logging, a mock server for offline tests, npm scripts for common tasks, and a simple quota-check utility to catch rate limits early.

How this skill works

Set up environment files (.env, .env.example, .env.test) and a development client that injects the Apollo API key and logs requests/responses when NODE_ENV is not production. Use MSW-based mock handlers to intercept Apollo endpoints during tests and dev runs. Npm scripts run a watch/dev server, toggle mocks, run Apollo-specific tests, and run quota checks that detect rate limiting.

When to use it

  • When initializing a new local project that talks to Apollo APIs
  • When running automated tests without hitting the real Apollo API
  • When debugging request/response issues during development
  • When you need early detection of rate limits or auth problems
  • When onboarding teammates who need a reproducible dev setup

Best practices

  • Commit .env.example but never commit .env; add .env and .env.local to .gitignore
  • Wrap API calls with a dev client that logs only in non-production to avoid leaking secrets
  • Use MSW handlers for deterministic tests and to reduce API usage in CI
  • Run the quota check script in CI or locally before heavy test batches to catch 429s
  • Rotate keys in .env promptly and update teammates via secure channels

Example use cases

  • Run npm run dev for live development with request/response logs to trace issues
  • Start the mock-enabled dev run (npm run dev:mock) to develop features without consuming API quota
  • Execute vitest tests that use MSW handlers to validate search and enrich flows locally
  • Use the check-apollo-quota script in a scheduled job to monitor API health and rate limits
  • Use .env.example as the onboarding template so new developers can configure keys and rate limits

FAQ

What if the API key is missing in development?

Load .env locally (or export variables) and ensure .env is present; commit only .env.example and keep keys out of version control.

How do I avoid hitting Apollo rate limits during CI or large test runs?

Use MSW mocks for tests, limit parallelism, and run the quota-check script to detect 429s so you can throttle or switch to mocks.