@jackchuka/gql-ingest 1.4.0 → 2.0.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/LICENSE +21 -0
- package/README.md +162 -6
- package/bin/cli.js +55 -52
- package/dist/dependency-resolver.d.ts +2 -1
- package/dist/dependency-resolver.d.ts.map +1 -1
- package/dist/mapper.d.ts +10 -5
- package/dist/mapper.d.ts.map +1 -1
- package/dist/metrics.d.ts.map +1 -1
- package/dist/readers/csv.d.ts +10 -0
- package/dist/readers/csv.d.ts.map +1 -0
- package/dist/readers/csv.test.d.ts +2 -0
- package/dist/readers/csv.test.d.ts.map +1 -0
- package/dist/readers/data-reader.d.ts +21 -0
- package/dist/readers/data-reader.d.ts.map +1 -0
- package/dist/readers/data-reader.test.d.ts +2 -0
- package/dist/readers/data-reader.test.d.ts.map +1 -0
- package/dist/readers/index.d.ts +6 -0
- package/dist/readers/index.d.ts.map +1 -0
- package/dist/readers/json.d.ts +6 -0
- package/dist/readers/json.d.ts.map +1 -0
- package/dist/readers/json.test.d.ts +2 -0
- package/dist/readers/json.test.d.ts.map +1 -0
- package/dist/readers/jsonl.d.ts +6 -0
- package/dist/readers/jsonl.d.ts.map +1 -0
- package/dist/readers/jsonl.test.d.ts +2 -0
- package/dist/readers/jsonl.test.d.ts.map +1 -0
- package/dist/readers/yaml.d.ts +6 -0
- package/dist/readers/yaml.d.ts.map +1 -0
- package/dist/readers/yaml.test.d.ts +2 -0
- package/dist/readers/yaml.test.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/cli.ts +49 -8
- package/src/dependency-resolver.test.ts +15 -1
- package/src/dependency-resolver.ts +6 -2
- package/src/graphql-client.test.ts +19 -4
- package/src/mapper.test.ts +115 -64
- package/src/mapper.ts +176 -32
- package/src/metrics.ts +18 -10
- package/src/{csv-reader.test.ts → readers/csv.test.ts} +1 -1
- package/src/readers/csv.ts +29 -0
- package/src/readers/data-reader.test.ts +104 -0
- package/src/readers/data-reader.ts +61 -0
- package/src/readers/index.ts +18 -0
- package/src/readers/json.test.ts +80 -0
- package/src/readers/json.ts +27 -0
- package/src/readers/jsonl.test.ts +96 -0
- package/src/readers/jsonl.ts +28 -0
- package/src/readers/yaml.test.ts +95 -0
- package/src/readers/yaml.ts +28 -0
- package/dist/csv-reader.d.ts +0 -5
- package/dist/csv-reader.d.ts.map +0 -1
- package/dist/csv-reader.test.d.ts +0 -2
- package/dist/csv-reader.test.d.ts.map +0 -1
- package/src/csv-reader.ts +0 -18
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 jackchuka
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
[](https://badge.fury.io/js/%40jackchuka%2Fgql-ingest)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
A TypeScript CLI tool that reads CSV
|
|
6
|
+
A TypeScript CLI tool that reads data from multiple formats (CSV, JSON, YAML, JSONL) and ingests it into GraphQL APIs through configurable mutations.
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
|
+
- ✅ **Supported data formats**: CSV, JSON, YAML, JSONL
|
|
11
|
+
- ✅ **Complex nested data support** for sophisticated GraphQL mutations
|
|
10
12
|
- ✅ External GraphQL mutation definitions (separate .graphql files)
|
|
11
|
-
- ✅
|
|
13
|
+
- ✅ Flexible data-to-GraphQL variable mapping via JSON configuration
|
|
12
14
|
- ✅ Configurable GraphQL endpoint and headers
|
|
13
15
|
- ✅ **Parallel processing** with dependency management
|
|
14
16
|
- ✅ Entity-level and row-level concurrency control
|
|
@@ -47,7 +49,10 @@ Options:
|
|
|
47
49
|
-V, --version output the version number
|
|
48
50
|
-e, --endpoint <url> GraphQL endpoint URL (required)
|
|
49
51
|
-c, --config <path> Path to configuration directory (required)
|
|
52
|
+
-n, --entities <list> Comma-separated list of specific entities to process
|
|
50
53
|
-h, --headers <headers> JSON string of headers to include in requests
|
|
54
|
+
-f, --format <format> Override data format detection (csv, json, yaml, jsonl)
|
|
55
|
+
-v, --verbose Show detailed request results and responses
|
|
51
56
|
--help display help for command
|
|
52
57
|
```
|
|
53
58
|
|
|
@@ -70,6 +75,18 @@ npx @jackchuka/gql-ingest \
|
|
|
70
75
|
--endpoint https://api.example.com/graphql \
|
|
71
76
|
--config ./my-config \
|
|
72
77
|
--headers '{"X-API-Key": "your-api-key", "Content-Type": "application/json"}'
|
|
78
|
+
|
|
79
|
+
# Process specific entities only
|
|
80
|
+
npx @jackchuka/gql-ingest \
|
|
81
|
+
--endpoint https://your-graphql-api.com/graphql \
|
|
82
|
+
--config ./examples/demo \
|
|
83
|
+
--entities users,products
|
|
84
|
+
|
|
85
|
+
# Process a single entity
|
|
86
|
+
npx @jackchuka/gql-ingest \
|
|
87
|
+
--endpoint https://your-graphql-api.com/graphql \
|
|
88
|
+
--config ./examples/demo \
|
|
89
|
+
--entities items
|
|
73
90
|
```
|
|
74
91
|
|
|
75
92
|
## Parallel Processing 🚀
|
|
@@ -143,12 +160,21 @@ entityConfig:
|
|
|
143
160
|
|
|
144
161
|
**Reliability Impact**: Retry capabilities can improve success rates from 95% to 99.9%+ for APIs with transient failures.
|
|
145
162
|
|
|
163
|
+
## Selective Entity Processing
|
|
164
|
+
|
|
165
|
+
The `--entities` flag allows you to process specific entities instead of all discovered mappings:
|
|
166
|
+
|
|
167
|
+
- Process multiple entities: `--entities users,products,orders`
|
|
168
|
+
- Process a single entity: `--entities items`
|
|
169
|
+
- Entities are processed in dependency order automatically
|
|
170
|
+
- Missing dependencies will trigger a warning but not prevent execution
|
|
171
|
+
|
|
172
|
+
**Note**: When using `--entities` with entity dependencies defined in `config.yaml`, the tool will warn you about any missing dependencies but will still attempt to process the selected entities. Ensure dependent data exists in your GraphQL API before processing entities with unmet dependencies.
|
|
173
|
+
|
|
146
174
|
## Configuration
|
|
147
175
|
|
|
148
|
-
The `--config` flag points to a configuration directory containing
|
|
176
|
+
The `--config` flag points to a configuration directory containing these necessary files:
|
|
149
177
|
|
|
150
|
-
- `data/` - CSV files with actual data
|
|
151
|
-
- `graphql/` - GraphQL mutation definitions
|
|
152
178
|
- `mappings/` - JSON files that map CSV columns to GraphQL variables
|
|
153
179
|
- `config.yaml` - _(Optional)_ Parallel processing and dependency configuration
|
|
154
180
|
|
|
@@ -160,7 +186,8 @@ Each entity has three corresponding files across these directories with matching
|
|
|
160
186
|
|
|
161
187
|
```json
|
|
162
188
|
{
|
|
163
|
-
"
|
|
189
|
+
"dataFile": "data/items.csv",
|
|
190
|
+
"dataFormat": "csv",
|
|
164
191
|
"graphqlFile": "graphql/items.graphql",
|
|
165
192
|
"mapping": {
|
|
166
193
|
"name": "item_name",
|
|
@@ -217,6 +244,135 @@ entityConfig:
|
|
|
217
244
|
concurrency: 10 # Higher concurrency for items
|
|
218
245
|
```
|
|
219
246
|
|
|
247
|
+
## Supported Data Formats 📄
|
|
248
|
+
|
|
249
|
+
GQL Ingest now supports multiple data formats beyond CSV for more flexible data ingestion, especially for complex nested GraphQL mutations:
|
|
250
|
+
|
|
251
|
+
### Supported Formats
|
|
252
|
+
|
|
253
|
+
- **CSV** - Traditional flat file format
|
|
254
|
+
- **JSON** - Perfect for nested/complex data structures
|
|
255
|
+
- **YAML** - Human-friendly alternative to JSON
|
|
256
|
+
- **JSONL** - JSON Lines format for streaming large datasets
|
|
257
|
+
|
|
258
|
+
### Format Selection
|
|
259
|
+
|
|
260
|
+
The tool automatically detects the format based on file extension, or you can specify it explicitly:
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
# Auto-detect from mapping configuration
|
|
264
|
+
gql-ingest --endpoint <url> --config ./config
|
|
265
|
+
|
|
266
|
+
# Force specific format
|
|
267
|
+
gql-ingest --endpoint <url> --config ./config --format json
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### JSON/YAML Format Examples
|
|
271
|
+
|
|
272
|
+
#### Direct Mapping (Entire Object)
|
|
273
|
+
|
|
274
|
+
For complex GraphQL mutations with nested input types, you can map the entire data object:
|
|
275
|
+
|
|
276
|
+
**data/products.json**:
|
|
277
|
+
|
|
278
|
+
```json
|
|
279
|
+
[
|
|
280
|
+
{
|
|
281
|
+
"name": "Premium T-Shirt",
|
|
282
|
+
"type": "PHYSICAL",
|
|
283
|
+
"options": [
|
|
284
|
+
{
|
|
285
|
+
"name": "Color",
|
|
286
|
+
"values": ["Red", "Blue", "Green"]
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
"name": "Size",
|
|
290
|
+
"values": ["S", "M", "L", "XL"]
|
|
291
|
+
}
|
|
292
|
+
],
|
|
293
|
+
"variants": [
|
|
294
|
+
{
|
|
295
|
+
"name": "Red Small",
|
|
296
|
+
"sku": "TS-RED-S",
|
|
297
|
+
"optionMappings": [
|
|
298
|
+
{ "name": "Color", "value": "Red" },
|
|
299
|
+
{ "name": "Size", "value": "S" }
|
|
300
|
+
]
|
|
301
|
+
}
|
|
302
|
+
]
|
|
303
|
+
}
|
|
304
|
+
]
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
**mappings/products.json**:
|
|
308
|
+
|
|
309
|
+
```json
|
|
310
|
+
{
|
|
311
|
+
"dataFile": "data/products.json",
|
|
312
|
+
"dataFormat": "json",
|
|
313
|
+
"graphqlFile": "graphql/newProduct.graphql",
|
|
314
|
+
"mapping": {
|
|
315
|
+
"input": "$" // Map entire object to input variable
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
#### Path-Based Mapping
|
|
321
|
+
|
|
322
|
+
For transforming flat JSON into nested structures:
|
|
323
|
+
|
|
324
|
+
**data/products-flat.json**:
|
|
325
|
+
|
|
326
|
+
```json
|
|
327
|
+
[
|
|
328
|
+
{
|
|
329
|
+
"product_name": "Notebook",
|
|
330
|
+
"product_type": "PHYSICAL",
|
|
331
|
+
"brand": "ACME"
|
|
332
|
+
}
|
|
333
|
+
]
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
**mappings/products-flat.json**:
|
|
337
|
+
|
|
338
|
+
```json
|
|
339
|
+
{
|
|
340
|
+
"dataFile": "data/products-flat.json",
|
|
341
|
+
"graphqlFile": "graphql/newProduct.graphql",
|
|
342
|
+
"mapping": {
|
|
343
|
+
"input": {
|
|
344
|
+
"name": "$.product_name",
|
|
345
|
+
"type": "$.product_type",
|
|
346
|
+
"brandCode": "$.brand"
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### YAML Format
|
|
353
|
+
|
|
354
|
+
YAML provides a more readable alternative:
|
|
355
|
+
|
|
356
|
+
**data/products.yaml**:
|
|
357
|
+
|
|
358
|
+
```yaml
|
|
359
|
+
- name: Premium T-Shirt
|
|
360
|
+
type: PHYSICAL
|
|
361
|
+
options:
|
|
362
|
+
- name: Color
|
|
363
|
+
values: [Red, Blue, Green]
|
|
364
|
+
- name: Size
|
|
365
|
+
values: [S, M, L, XL]
|
|
366
|
+
variants:
|
|
367
|
+
- name: Red Small
|
|
368
|
+
sku: TS-RED-S
|
|
369
|
+
optionMappings:
|
|
370
|
+
- name: Color
|
|
371
|
+
value: Red
|
|
372
|
+
- name: Size
|
|
373
|
+
value: S
|
|
374
|
+
```
|
|
375
|
+
|
|
220
376
|
## Development
|
|
221
377
|
|
|
222
378
|
### Scripts
|