@jackchuka/gql-ingest 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -31
- package/bin/cli.js +44 -41
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/graphql-client.d.ts +6 -2
- package/dist/graphql-client.d.ts.map +1 -1
- package/dist/mapper.d.ts +2 -2
- package/dist/mapper.d.ts.map +1 -1
- package/dist/metrics.d.ts +5 -0
- package/dist/metrics.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +6 -4
- package/src/config.test.ts +69 -1
- package/src/config.ts +35 -0
- package/src/graphql-client.test.ts +127 -1
- package/src/graphql-client.ts +132 -32
- package/src/mapper.test.ts +4 -4
- package/src/mapper.ts +13 -8
- package/src/metrics.ts +22 -0
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ A TypeScript CLI tool that reads CSV files and ingests data into GraphQL APIs th
|
|
|
12
12
|
- ✅ Configurable GraphQL endpoint and headers
|
|
13
13
|
- ✅ **Parallel processing** with dependency management
|
|
14
14
|
- ✅ Entity-level and row-level concurrency control
|
|
15
|
+
- ✅ **Retry capabilities** with exponential backoff and configurable error handling
|
|
15
16
|
- ✅ Comprehensive metrics and progress tracking
|
|
16
17
|
|
|
17
18
|
## Installation
|
|
@@ -78,7 +79,7 @@ GQL Ingest supports advanced parallel processing with dependency management for
|
|
|
78
79
|
### Key Capabilities
|
|
79
80
|
|
|
80
81
|
- **Entity-level parallelism**: Process multiple entities (users, products, orders) concurrently
|
|
81
|
-
- **Row-level parallelism**: Process multiple CSV rows within an entity concurrently
|
|
82
|
+
- **Row-level parallelism**: Process multiple CSV rows within an entity concurrently
|
|
82
83
|
- **Dependency management**: Ensure entities process in the correct order (e.g., users before orders)
|
|
83
84
|
- **Smart batching**: Control exactly how many entities/rows process simultaneously
|
|
84
85
|
- **Real-time metrics**: Track progress, success rates, and performance
|
|
@@ -88,20 +89,60 @@ GQL Ingest supports advanced parallel processing with dependency management for
|
|
|
88
89
|
```yaml
|
|
89
90
|
# config.yaml - Add to your configuration directory
|
|
90
91
|
parallelProcessing:
|
|
91
|
-
concurrency: 10
|
|
92
|
-
entityConcurrency: 3
|
|
93
|
-
preserveRowOrder: false
|
|
92
|
+
concurrency: 10 # Process up to 10 CSV rows per entity concurrently
|
|
93
|
+
entityConcurrency: 3 # Process up to 3 entities simultaneously
|
|
94
|
+
preserveRowOrder: false # Allow rows to complete out of order for speed
|
|
94
95
|
|
|
95
|
-
# Define dependencies between entities
|
|
96
|
+
# Define dependencies between entities
|
|
96
97
|
entityDependencies:
|
|
97
|
-
products: ["users"]
|
|
98
|
-
orders: ["products"]
|
|
98
|
+
products: ["users"] # Products must wait for users to complete
|
|
99
|
+
orders: ["products"] # Orders must wait for products to complete
|
|
99
100
|
```
|
|
100
101
|
|
|
101
102
|
**Performance Impact**: This configuration can process data **10-50x faster** than sequential processing, depending on your GraphQL API's capabilities.
|
|
102
103
|
|
|
103
104
|
👉 **[Full Parallel Processing Guide](PARALLEL_PROCESSING.md)** - Detailed configuration options, performance tuning, and examples.
|
|
104
105
|
|
|
106
|
+
## Retry Capabilities 🔄
|
|
107
|
+
|
|
108
|
+
GQL Ingest includes robust retry functionality to handle transient failures and improve reliability:
|
|
109
|
+
|
|
110
|
+
### Key Features
|
|
111
|
+
|
|
112
|
+
- **Automatic retries**: Failed GraphQL mutations are retried automatically
|
|
113
|
+
- **Exponential backoff**: Intelligent delay increases between retry attempts
|
|
114
|
+
- **Jitter**: Randomization prevents thundering herd problems
|
|
115
|
+
- **Configurable error codes**: Control which HTTP status codes trigger retries
|
|
116
|
+
- **Per-entity overrides**: Different retry settings for different entities
|
|
117
|
+
- **Metrics tracking**: Monitor retry success rates and attempt counts
|
|
118
|
+
|
|
119
|
+
### Quick Example
|
|
120
|
+
|
|
121
|
+
```yaml
|
|
122
|
+
# config.yaml - Add to your configuration directory
|
|
123
|
+
retry:
|
|
124
|
+
maxAttempts: 5 # Retry up to 5 times (default: 3)
|
|
125
|
+
baseDelay: 2000 # Start with 2s delay (default: 1000ms)
|
|
126
|
+
maxDelay: 60000 # Cap delays at 60s (default: 30000ms)
|
|
127
|
+
exponentialBackoff: true # Double delay each retry (default: true)
|
|
128
|
+
retryableStatusCodes: # Which HTTP errors to retry (defaults shown)
|
|
129
|
+
- 408 # Request Timeout
|
|
130
|
+
- 429 # Too Many Requests
|
|
131
|
+
- 500 # Internal Server Error
|
|
132
|
+
- 502 # Bad Gateway
|
|
133
|
+
- 503 # Service Unavailable
|
|
134
|
+
- 504 # Gateway Timeout
|
|
135
|
+
|
|
136
|
+
# Per-entity retry overrides
|
|
137
|
+
entityConfig:
|
|
138
|
+
critical-orders:
|
|
139
|
+
retry:
|
|
140
|
+
maxAttempts: 10 # More retries for critical data
|
|
141
|
+
baseDelay: 500 # Faster initial retry
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**Reliability Impact**: Retry capabilities can improve success rates from 95% to 99.9%+ for APIs with transient failures.
|
|
145
|
+
|
|
105
146
|
## Configuration
|
|
106
147
|
|
|
107
148
|
The `--config` flag points to a configuration directory containing three subdirectories:
|
|
@@ -109,7 +150,7 @@ The `--config` flag points to a configuration directory containing three subdire
|
|
|
109
150
|
- `data/` - CSV files with actual data
|
|
110
151
|
- `graphql/` - GraphQL mutation definitions
|
|
111
152
|
- `mappings/` - JSON files that map CSV columns to GraphQL variables
|
|
112
|
-
- `config.yaml` -
|
|
153
|
+
- `config.yaml` - _(Optional)_ Parallel processing and dependency configuration
|
|
113
154
|
|
|
114
155
|
Each entity has three corresponding files across these directories with matching names.
|
|
115
156
|
|
|
@@ -148,16 +189,32 @@ mutation CreateItem($name: String!, $sku: String!) {
|
|
|
148
189
|
}
|
|
149
190
|
```
|
|
150
191
|
|
|
151
|
-
**examples/demo/config.yaml**
|
|
192
|
+
**examples/demo/config.yaml** _(Optional - for parallel processing and retry configuration)_:
|
|
152
193
|
|
|
153
194
|
```yaml
|
|
195
|
+
# Parallel processing configuration
|
|
154
196
|
parallelProcessing:
|
|
155
|
-
concurrency: 5
|
|
156
|
-
entityConcurrency: 2
|
|
157
|
-
preserveRowOrder: false
|
|
197
|
+
concurrency: 5 # Process 5 rows per entity concurrently
|
|
198
|
+
entityConcurrency: 2 # Process 2 entities simultaneously
|
|
199
|
+
preserveRowOrder: false # Allow faster out-of-order completion
|
|
158
200
|
|
|
201
|
+
# Global retry configuration
|
|
202
|
+
retry:
|
|
203
|
+
maxAttempts: 3 # Retry failed requests up to 3 times
|
|
204
|
+
baseDelay: 1000 # Start with 1s delay between retries
|
|
205
|
+
exponentialBackoff: true # Double delay each retry
|
|
206
|
+
|
|
207
|
+
# Entity dependencies
|
|
159
208
|
entityDependencies:
|
|
160
|
-
items: ["users"]
|
|
209
|
+
items: ["users"] # Items depend on users being processed first
|
|
210
|
+
|
|
211
|
+
# Per-entity overrides (optional)
|
|
212
|
+
entityConfig:
|
|
213
|
+
users:
|
|
214
|
+
retry:
|
|
215
|
+
maxAttempts: 5 # More retries for user creation
|
|
216
|
+
items:
|
|
217
|
+
concurrency: 10 # Higher concurrency for items
|
|
161
218
|
```
|
|
162
219
|
|
|
163
220
|
## Development
|
|
@@ -165,21 +222,11 @@ entityDependencies:
|
|
|
165
222
|
### Scripts
|
|
166
223
|
|
|
167
224
|
```bash
|
|
168
|
-
npm run build
|
|
169
|
-
npm run build:types
|
|
170
|
-
npm run build:all
|
|
171
|
-
npm run dev
|
|
172
|
-
npm run test
|
|
173
|
-
npm run test:watch # Run tests in watch mode
|
|
174
|
-
npm run test:coverage # Run tests with coverage report
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### Testing
|
|
178
|
-
|
|
179
|
-
The project includes comprehensive unit tests for all modules:
|
|
180
|
-
|
|
181
|
-
```bash
|
|
182
|
-
npm test # Run all tests
|
|
225
|
+
npm run build # Build CLI bundle with esbuild
|
|
226
|
+
npm run build:types # Generate TypeScript declarations
|
|
227
|
+
npm run build:all # Build bundle + types
|
|
228
|
+
npm run dev # Run in development mode
|
|
229
|
+
npm run test # Run test suite
|
|
183
230
|
```
|
|
184
231
|
|
|
185
232
|
## How It Works
|
|
@@ -194,9 +241,13 @@ npm test # Run all tests
|
|
|
194
241
|
- Loads the GraphQL mutation definition
|
|
195
242
|
- Maps CSV columns to GraphQL variables using the mapping configuration
|
|
196
243
|
- Executes the mutation against the GraphQL endpoint
|
|
197
|
-
5. **Error Handling &
|
|
198
|
-
- Failed mutations are
|
|
199
|
-
-
|
|
244
|
+
5. **Error Handling & Retries**:
|
|
245
|
+
- Failed mutations are automatically retried with exponential backoff
|
|
246
|
+
- Non-retryable errors (e.g., validation failures) are logged and skipped
|
|
247
|
+
- Configurable retry policies per entity type
|
|
248
|
+
6. **Metrics & Monitoring**:
|
|
249
|
+
- Real-time progress tracking and success/failure rates
|
|
250
|
+
- Retry attempt counts and success rates
|
|
200
251
|
- Detailed per-entity performance breakdown
|
|
201
252
|
|
|
202
253
|
## License
|