@jackchuka/sdl-decompose 1.3.7 → 1.3.9
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/bin/cli.js +2 -2
- package/package.json +5 -6
package/bin/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var g=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var m=g((W,C)=>{C.exports={name:"@jackchuka/sdl-decompose",version:"1.3.
|
|
2
|
+
var g=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var m=g((W,C)=>{C.exports={name:"@jackchuka/sdl-decompose",version:"1.3.9",description:"Decompose GraphQL SDL by operation name to produce partial SDL",keywords:["decompose","graphql","schema","sdl"],license:"MIT",author:"jackchuka",repository:{type:"git",url:"https://github.com/jackchuka/sdl-decompose.git"},bin:{"sdl-decompose":"bin/cli.js"},files:["bin/**/*","dist/**/*"],type:"module",main:"dist/index.js",types:"dist/index.d.ts",scripts:{lint:"oxlint --type-aware --tsconfig ./tsconfig.json","lint:fix":"oxlint --fix --type-aware --tsconfig ./tsconfig.json",fmt:"oxfmt",build:"tsc","build:cli":"node esbuild.config.js",dev:"tsc --watch",test:"jest",prepublishOnly:"npm run build && npm run build:cli"},dependencies:{commander:"^14.0.2",graphql:"^16.12.0"},devDependencies:{"@types/jest":"^30.0.0","@types/node":"^25.0.6",esbuild:"^0.28.0",jest:"^30.2.0",oxfmt:"^0.44.0",oxlint:"^1.39.0","oxlint-tsgolint":"^0.20.0","ts-jest":"^29.4.6",typescript:"^6.0.2"},packageManager:"pnpm@10.33.0",pnpm:{onlyBuiltDependencies:["esbuild","unrs-resolver"]}}});import{Command as G}from"commander";import{readFileSync as N,writeFileSync as $,existsSync as q}from"fs";import{resolve as I}from"path";import{buildASTSchema as D,parse as T,visit as h,isObjectType as S,isInputObjectType as b,isInterfaceType as L,isUnionType as x,getNamedType as d,printType as O}from"graphql";var j=new Set(["String","Int","Float","Boolean","ID"]);function v(n,t){return t.excludeComments||!t.includeDeprecated?h(n,{FieldDefinition(e){return!t.includeDeprecated&&e.directives&&e.directives.some(s=>s.name.value==="deprecated")?null:t.excludeComments&&e.description?{...e,description:void 0}:e},Directive(e){return e.name.value==="deprecated"&&!t.includeDeprecated?null:e},ObjectTypeDefinition(e){return t.excludeComments&&e.description?{...e,description:void 0}:e},InputObjectTypeDefinition(e){return t.excludeComments&&e.description?{...e,description:void 0}:e},InterfaceTypeDefinition(e){return t.excludeComments&&e.description?{...e,description:void 0}:e},UnionTypeDefinition(e){return t.excludeComments&&e.description?{...e,description:void 0}:e},EnumTypeDefinition(e){return t.excludeComments&&e.description?{...e,description:void 0}:e},ScalarTypeDefinition(e){return t.excludeComments&&e.description?{...e,description:void 0}:e}}):n}function l(n,t,i="query",e={}){try{let r=T(n),s=v(r,e),o=D(s),c={collected:new Set,typeNames:new Set},p=f(o,i);if(!p)return{sdl:"",collectedTypes:new Set,operationFound:!1};let a=p.getFields()[t];return a?(F(a,c,e),{sdl:Q(o,c,i,t),collectedTypes:c.typeNames,operationFound:!0}):{sdl:"",collectedTypes:new Set,operationFound:!1}}catch(r){throw new Error(`Failed to decompose GraphQL: ${r instanceof Error?r.message:String(r)}`)}}function f(n,t){switch(t){case"query":return n.getQueryType();case"mutation":return n.getMutationType();case"subscription":return n.getSubscriptionType();default:return null}}function F(n,t,i){let e=d(n.type);if(u(e,t,i),n.args)for(let r of n.args){let s=d(r.type);u(s,t,i)}}function u(n,t,i){if(!(!n||t.collected.has(n))&&!(!i.includeBuiltinScalars&&j.has(n.name))){if(t.collected.add(n),t.typeNames.add(n.name),S(n)||b(n)){let e=n.getFields();for(let r of Object.values(e)){let s=d(r.type);if(u(s,t,i),"args"in r&&r.args)for(let o of r.args){let c=d(o.type);u(c,t,i)}}}else if(L(n)){let e=n.getFields();for(let r of Object.values(e)){let s=d(r.type);if(u(s,t,i),r.args)for(let o of r.args){let c=d(o.type);u(c,t,i)}}}else if(x(n))for(let e of n.getTypes())u(e,t,i)}}function Q(n,t,i,e){let r=[],s=f(n,i);if(s){let o=s.getFields()[e];if(o){let c=i==="query"?"Query":i==="mutation"?"Mutation":"Subscription";r.push(`type ${c} {
|
|
3
3
|
${e}${w(o)}
|
|
4
4
|
}`)}}for(let o of t.collected)o.name==="Query"||o.name==="Mutation"||o.name==="Subscription"||r.push(O(o));return r.join(`
|
|
5
5
|
|
|
6
|
-
`)}function w(n){return`${n.args&&n.args.length>0?`(${n.args.map(i=>`${i.name}: ${String(i.type)}`).join(", ")})`:""}: ${String(n.type)}`}var y=new G;async function
|
|
6
|
+
`)}function w(n){return`${n.args&&n.args.length>0?`(${n.args.map(i=>`${i.name}: ${String(i.type)}`).join(", ")})`:""}: ${String(n.type)}`}var y=new G;async function B(n){if(n){let i=I(n);if(!q(i))throw new Error(`SDL file not found: ${i}`);return N(i,"utf8")}let t=[];return new Promise((i,e)=>{process.stdin.on("data",r=>{if(typeof r=="string"){t.push(Buffer.from(r,"utf8"));return}t.push(r)}),process.stdin.on("end",()=>{let r=Buffer.concat(t).toString("utf8");r.trim()?i(r):e(new Error("No SDL content provided via stdin"))}),process.stdin.on("error",e)})}y.name("sdl-decompose").description("Decompose GraphQL SDL by operation name to produce partial SDL").version(m().version).option("-s, --sdl <file>","Path to SDL file (optional, reads from stdin if not provided)").requiredOption("-o, --operation <name>","Operation name to decompose").option("-t, --type <type>","Operation type: query, mutation, subscription","query").option("--output <file>","Output file path (optional, prints to stdout if not provided)").option("--include-builtins","Include builtin scalar types in output",!1).option("--exclude-comments","Remove comments and descriptions from output SDL",!1).option("--include-deprecated","Include deprecated fields in output",!1).action(async n=>{let{sdl:t,operation:i,type:e,output:r,includeBuiltins:s,excludeComments:o,includeDeprecated:c}=n;["query","mutation","subscription"].includes(e)||(console.error("Error: --type must be one of: query, mutation, subscription"),process.exit(1));try{let p=await B(t),a=l(p,i,e,{includeBuiltinScalars:s,excludeComments:o,includeDeprecated:c});a.operationFound||(console.error(`Error: Operation '${i}' not found in ${e} type`),process.exit(1)),r?($(r,a.sdl),console.log(`Decomposed SDL written to: ${r}`),console.log(`Collected types: ${Array.from(a.collectedTypes).join(", ")}`)):console.log(a.sdl)}catch(p){console.error(`Error: ${p instanceof Error?p.message:String(p)}`),process.exit(1)}});y.parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jackchuka/sdl-decompose",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.9",
|
|
4
4
|
"description": "Decompose GraphQL SDL by operation name to produce partial SDL",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"decompose",
|
|
@@ -31,15 +31,14 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/jest": "^30.0.0",
|
|
33
33
|
"@types/node": "^25.0.6",
|
|
34
|
-
"esbuild": "^0.
|
|
34
|
+
"esbuild": "^0.28.0",
|
|
35
35
|
"jest": "^30.2.0",
|
|
36
|
-
"oxfmt": "^0.
|
|
36
|
+
"oxfmt": "^0.44.0",
|
|
37
37
|
"oxlint": "^1.39.0",
|
|
38
|
-
"oxlint-tsgolint": "^0.
|
|
38
|
+
"oxlint-tsgolint": "^0.20.0",
|
|
39
39
|
"ts-jest": "^29.4.6",
|
|
40
|
-
"typescript": "^
|
|
40
|
+
"typescript": "^6.0.2"
|
|
41
41
|
},
|
|
42
|
-
"packageManager": "pnpm@8.14.1",
|
|
43
42
|
"scripts": {
|
|
44
43
|
"lint": "oxlint --type-aware --tsconfig ./tsconfig.json",
|
|
45
44
|
"lint:fix": "oxlint --fix --type-aware --tsconfig ./tsconfig.json",
|