@jackchuka/gql-ingest 1.5.0 → 2.0.1

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.
Files changed (47) hide show
  1. package/README.md +138 -6
  2. package/bin/cli.js +53 -52
  3. package/dist/mapper.d.ts +9 -4
  4. package/dist/mapper.d.ts.map +1 -1
  5. package/dist/readers/csv.d.ts +10 -0
  6. package/dist/readers/csv.d.ts.map +1 -0
  7. package/dist/readers/csv.test.d.ts +2 -0
  8. package/dist/readers/csv.test.d.ts.map +1 -0
  9. package/dist/readers/data-reader.d.ts +21 -0
  10. package/dist/readers/data-reader.d.ts.map +1 -0
  11. package/dist/readers/data-reader.test.d.ts +2 -0
  12. package/dist/readers/data-reader.test.d.ts.map +1 -0
  13. package/dist/readers/index.d.ts +6 -0
  14. package/dist/readers/index.d.ts.map +1 -0
  15. package/dist/readers/json.d.ts +6 -0
  16. package/dist/readers/json.d.ts.map +1 -0
  17. package/dist/readers/json.test.d.ts +2 -0
  18. package/dist/readers/json.test.d.ts.map +1 -0
  19. package/dist/readers/jsonl.d.ts +6 -0
  20. package/dist/readers/jsonl.d.ts.map +1 -0
  21. package/dist/readers/jsonl.test.d.ts +2 -0
  22. package/dist/readers/jsonl.test.d.ts.map +1 -0
  23. package/dist/readers/yaml.d.ts +6 -0
  24. package/dist/readers/yaml.d.ts.map +1 -0
  25. package/dist/readers/yaml.test.d.ts +2 -0
  26. package/dist/readers/yaml.test.d.ts.map +1 -0
  27. package/package.json +1 -1
  28. package/src/cli.ts +10 -25
  29. package/src/graphql-client.test.ts +19 -4
  30. package/src/mapper.test.ts +115 -64
  31. package/src/mapper.ts +138 -33
  32. package/src/{csv-reader.test.ts → readers/csv.test.ts} +1 -1
  33. package/src/readers/csv.ts +29 -0
  34. package/src/readers/data-reader.test.ts +104 -0
  35. package/src/readers/data-reader.ts +61 -0
  36. package/src/readers/index.ts +18 -0
  37. package/src/readers/json.test.ts +80 -0
  38. package/src/readers/json.ts +27 -0
  39. package/src/readers/jsonl.test.ts +96 -0
  40. package/src/readers/jsonl.ts +28 -0
  41. package/src/readers/yaml.test.ts +95 -0
  42. package/src/readers/yaml.ts +28 -0
  43. package/dist/csv-reader.d.ts +0 -5
  44. package/dist/csv-reader.d.ts.map +0 -1
  45. package/dist/csv-reader.test.d.ts +0 -2
  46. package/dist/csv-reader.test.d.ts.map +0 -1
  47. package/src/csv-reader.ts +0 -18
package/README.md CHANGED
@@ -3,12 +3,14 @@
3
3
  [![npm version](https://badge.fury.io/js/%40jackchuka%2Fgql-ingest.svg)](https://badge.fury.io/js/%40jackchuka%2Fgql-ingest)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- A TypeScript CLI tool that reads CSV files and ingests data into GraphQL APIs through configurable mutations.
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
- - ✅ CSV-to-GraphQL variable mapping via JSON configuration
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
@@ -49,6 +51,8 @@ Options:
49
51
  -c, --config <path> Path to configuration directory (required)
50
52
  -n, --entities <list> Comma-separated list of specific entities to process
51
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
52
56
  --help display help for command
53
57
  ```
54
58
 
@@ -169,10 +173,8 @@ The `--entities` flag allows you to process specific entities instead of all dis
169
173
 
170
174
  ## Configuration
171
175
 
172
- The `--config` flag points to a configuration directory containing three subdirectories:
176
+ The `--config` flag points to a configuration directory containing these necessary files:
173
177
 
174
- - `data/` - CSV files with actual data
175
- - `graphql/` - GraphQL mutation definitions
176
178
  - `mappings/` - JSON files that map CSV columns to GraphQL variables
177
179
  - `config.yaml` - _(Optional)_ Parallel processing and dependency configuration
178
180
 
@@ -184,7 +186,8 @@ Each entity has three corresponding files across these directories with matching
184
186
 
185
187
  ```json
186
188
  {
187
- "csvFile": "data/items.csv",
189
+ "dataFile": "data/items.csv",
190
+ "dataFormat": "csv",
188
191
  "graphqlFile": "graphql/items.graphql",
189
192
  "mapping": {
190
193
  "name": "item_name",
@@ -241,6 +244,135 @@ entityConfig:
241
244
  concurrency: 10 # Higher concurrency for items
242
245
  ```
243
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
+
244
376
  ## Development
245
377
 
246
378
  ### Scripts