@jackchuka/gql-ingest 1.0.1 → 1.0.2

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 (2) hide show
  1. package/bin/cli.js +2 -0
  2. package/package.json +2 -2
package/bin/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var R=Object.create;var u=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var Q=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var k=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of F(e))!G.call(t,n)&&n!==r&&u(t,n,{get:()=>e[n],enumerable:!(s=L(e,n))||s.enumerable});return t};var a=(t,e,r)=>(r=t!=null?R(S(t)):{},k(e||!t||!t.__esModule?u(r,"default",{value:t,enumerable:!0}):r,t));var C=Q((A,x)=>{x.exports={name:"@jackchuka/gql-ingest",version:"1.0.2",description:"A CLI tool for ingesting data from CSV files into a GraphQL API",main:"dist/cli.js",bin:{"gql-ingest":"bin/cli.js"},scripts:{build:"node esbuild.config.js","build:types":"tsc --emitDeclarationOnly","build:all":"npm run build && npm run build:types",dev:"ts-node src/cli.ts",test:"jest","test:watch":"jest --watch",prepublishOnly:"npm run build:all"},keywords:["graphql","cli","csv","ingest","api"],author:"jackchuka",license:"MIT",repository:{type:"git",url:"https://github.com/jackchuka/gql-ingest.git"},dependencies:{commander:"^14.0.0","csv-parser":"^3.0.0","graphql-request":"^7.2.0"},devDependencies:{"@types/jest":"^30.0.0","@types/node":"^24.0.4",esbuild:"^0.25.5",jest:"^30.0.3","ts-jest":"^29.4.0","ts-node":"^10.9.0",typescript:"^5.3.0"},files:["dist/**/*","src/**/*"]}});var b=require("commander");var f=require("graphql-request"),c=class{constructor(e,r){this.client=new f.GraphQLClient(e,{headers:r||{}})}async executeMutation(e,r){try{return await this.client.request(e,r)}catch(s){throw console.error("GraphQL mutation failed:",s),s}}setHeaders(e){this.client.setHeaders(e)}};var p=a(require("fs")),o=a(require("path"));var v=a(require("fs")),y=a(require("csv-parser"));async function w(t){return new Promise((e,r)=>{let s=[];v.default.createReadStream(t).pipe((0,y.default)()).on("data",n=>s.push(n)).on("end",()=>e(s)).on("error",n=>r(n))})}var l=class{constructor(e,r=process.cwd()){this.client=e,this.basePath=r}discoverMappings(e){let r=o.default.resolve(this.basePath,e,"mappings");try{let n=p.default.readdirSync(r).filter(i=>i.endsWith(".json")).sort();return console.log(`Discovered ${n.length} mapping files: ${n.join(", ")}`),n.map(i=>o.default.join(e,"mappings",i))}catch(s){return console.error(`Error reading mappings directory ${r}:`,s),[]}}async processEntity(e){console.log(`Processing entity: ${e}`);let r=o.default.resolve(this.basePath,e),s=JSON.parse(p.default.readFileSync(r,"utf8")),n=o.default.dirname(o.default.dirname(r)),i=o.default.resolve(n,s.csvFile),g=await w(i),q=o.default.resolve(n,s.graphqlFile),P=p.default.readFileSync(q,"utf8");for(let m of g){let j=this.mapCsvRowToVariables(m,s.mapping);try{let d=await this.client.executeMutation(P,j);console.log("\u2713 Created entity with result:",d)}catch(d){console.error("\u2717 Failed to create entity for row:",m,d)}}}mapCsvRowToVariables(e,r){let s={};for(let[n,i]of Object.entries(r))e[i]!==void 0&&(s[n]=e[i]);return s}};var h=new b.Command;h.name("gql-ingest").description("A CLI tool for ingesting data from CSV files into a GraphQL API").version(C().version);h.requiredOption("-e, --endpoint <url>","GraphQL endpoint URL").requiredOption("-c, --config <path>","Path to configuration directory (containing data/, graphql/, mappings/ subdirectories)").option("-h, --headers <headers>","JSON string of headers to include in requests").action(async t=>{try{console.log("Starting seed data generation...");let e=t.headers?JSON.parse(t.headers):{},r=new c(t.endpoint,e),s=new l(r),n=s.discoverMappings(t.config);if(n.length===0){console.warn(`No mapping files found in ${t.config}/mappings`);return}for(let i of n)try{await s.processEntity(i)}catch(g){console.warn(`Warning: Could not process ${i}:`,g)}console.log("Seed data generation completed!")}catch(e){console.error("Error:",e),process.exit(1)}});h.parse();
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@jackchuka/gql-ingest",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A CLI tool for ingesting data from CSV files into a GraphQL API",
5
5
  "main": "dist/cli.js",
6
6
  "bin": {
7
- "gql-ingest": "dist/cli.js"
7
+ "gql-ingest": "bin/cli.js"
8
8
  },
9
9
  "scripts": {
10
10
  "build": "node esbuild.config.js",