@manot40/genql-cli 1.0.2 → 1.1.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 -21
- package/README.md +3 -3
- package/dist/{chunk-BBnsswwY.mjs → chunk.mjs} +14 -1
- package/dist/{cli-truncate-D9-H5ZcK.mjs → cli-truncate.mjs} +2 -2
- package/dist/cli.d.mts +1 -9
- package/dist/cli.mjs +484 -120
- package/dist/index.mjs +1 -1
- package/dist/{log-update-C7F4wEC4.mjs → log-update.mjs} +3 -3
- package/dist/{main-DnxPgNLv.mjs → main.mjs} +75 -69
- package/dist/runtime/generateGraphqlOperation.ts +6 -6
- package/dist/runtime/index.ts +1 -1
- package/dist/runtime/typeSelection.ts +9 -9
- package/dist/{slice-ansi-BXJtqwp2.mjs → slice-ansi.mjs} +1 -1
- package/package.json +2 -2
- package/dist/get-east-asian-width-BrRn4isQ.mjs +0 -24
- package/dist/wrap-ansi-B5Z_xwBN.mjs +0 -3
- package/dist/wrap-ansi-BLh1Umdy.mjs +0 -359
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as wrapAnsi } from "./
|
|
2
|
-
import { t as sliceAnsi } from "./slice-ansi
|
|
3
|
-
import process$1 from "node:process";
|
|
1
|
+
import { t as wrapAnsi } from "./cli.mjs";
|
|
2
|
+
import { t as sliceAnsi } from "./slice-ansi.mjs";
|
|
4
3
|
import os from "node:os";
|
|
4
|
+
import process$1 from "node:process";
|
|
5
5
|
|
|
6
6
|
//#region node_modules/environment/index.js
|
|
7
7
|
const isBrowser = globalThis.window?.document !== void 0;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as tty from "tty";
|
|
3
|
-
import { format } from "util";
|
|
4
|
-
import { EOL } from "os";
|
|
5
|
-
import { StringDecoder } from "string_decoder";
|
|
6
|
-
import { Writable } from "stream";
|
|
7
|
-
import { randomUUID } from "crypto";
|
|
1
|
+
import { r as __toESM, t as __commonJSMin } from "./chunk.mjs";
|
|
2
|
+
import * as tty from "node:tty";
|
|
3
|
+
import { format } from "node:util";
|
|
4
|
+
import { EOL } from "node:os";
|
|
5
|
+
import { StringDecoder } from "node:string_decoder";
|
|
6
|
+
import { Writable } from "node:stream";
|
|
7
|
+
import { randomUUID } from "node:crypto";
|
|
8
8
|
import fs, { glob, mkdir, rm, writeFile } from "node:fs/promises";
|
|
9
9
|
import url from "node:url";
|
|
10
10
|
import path, { resolve } from "node:path";
|
|
11
11
|
import { assertValidSchema, buildClientSchema, getIntrospectionQuery, getNamedType, isEnumType, isInputObjectType, isInterfaceType, isListType, isNamedType, isNonNullType, isObjectType, isScalarType, isUnionType, lexicographicSortSchema, printSchema } from "graphql";
|
|
12
|
-
import path$1 from "path";
|
|
13
12
|
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
|
|
14
13
|
import { loadSchema } from "@graphql-tools/load";
|
|
15
14
|
|
|
@@ -1100,9 +1099,9 @@ var DefaultRenderer = class DefaultRenderer$1 {
|
|
|
1100
1099
|
this.logger.options.color = this.options.color;
|
|
1101
1100
|
}
|
|
1102
1101
|
async render() {
|
|
1103
|
-
const { createLogUpdate } = await import("./log-update
|
|
1104
|
-
const { default: truncate } = await import("./cli-truncate
|
|
1105
|
-
const { default: wrap } = await import("./
|
|
1102
|
+
const { createLogUpdate } = await import("./log-update.mjs");
|
|
1103
|
+
const { default: truncate } = await import("./cli-truncate.mjs");
|
|
1104
|
+
const { default: wrap } = await import("./cli.mjs");
|
|
1106
1105
|
this.updater = createLogUpdate(this.logger.process.stdout);
|
|
1107
1106
|
this.truncate = truncate;
|
|
1108
1107
|
this.wrap = wrap;
|
|
@@ -1761,8 +1760,8 @@ var Concurrency = class {
|
|
|
1761
1760
|
}
|
|
1762
1761
|
add(fn) {
|
|
1763
1762
|
if (this.count < this.concurrency) return this.run(fn);
|
|
1764
|
-
return new Promise((resolve$
|
|
1765
|
-
const callback = () => resolve$
|
|
1763
|
+
return new Promise((resolve$1) => {
|
|
1764
|
+
const callback = () => resolve$1(this.run(fn));
|
|
1766
1765
|
this.queue.add(callback);
|
|
1767
1766
|
});
|
|
1768
1767
|
}
|
|
@@ -1787,8 +1786,8 @@ var Concurrency = class {
|
|
|
1787
1786
|
}
|
|
1788
1787
|
};
|
|
1789
1788
|
function delay(time) {
|
|
1790
|
-
return new Promise((resolve$
|
|
1791
|
-
setTimeout(resolve$
|
|
1789
|
+
return new Promise((resolve$1) => {
|
|
1790
|
+
setTimeout(resolve$1, time);
|
|
1792
1791
|
});
|
|
1793
1792
|
}
|
|
1794
1793
|
/**
|
|
@@ -2134,20 +2133,20 @@ var Task = class extends ListrTaskEventManager {
|
|
|
2134
2133
|
this.emit(ListrTaskEventType.SUBTASK, this.subtasks);
|
|
2135
2134
|
result = result.run(context);
|
|
2136
2135
|
} else if (result instanceof Promise) result = result.then(handleResult);
|
|
2137
|
-
else if (isReadable(result)) result = new Promise((resolve$
|
|
2136
|
+
else if (isReadable(result)) result = new Promise((resolve$1, reject) => {
|
|
2138
2137
|
result.on("data", (data) => {
|
|
2139
2138
|
this.output$ = data.toString();
|
|
2140
2139
|
});
|
|
2141
2140
|
result.on("error", (error) => reject(error));
|
|
2142
|
-
result.on("end", () => resolve$
|
|
2141
|
+
result.on("end", () => resolve$1(null));
|
|
2143
2142
|
});
|
|
2144
|
-
else if (isObservable(result)) result = new Promise((resolve$
|
|
2143
|
+
else if (isObservable(result)) result = new Promise((resolve$1, reject) => {
|
|
2145
2144
|
result.subscribe({
|
|
2146
2145
|
next: (data) => {
|
|
2147
2146
|
this.output$ = data;
|
|
2148
2147
|
},
|
|
2149
2148
|
error: reject,
|
|
2150
|
-
complete: resolve$
|
|
2149
|
+
complete: resolve$1
|
|
2151
2150
|
});
|
|
2152
2151
|
});
|
|
2153
2152
|
return result;
|
|
@@ -3240,13 +3239,13 @@ function capitalize(str) {
|
|
|
3240
3239
|
|
|
3241
3240
|
//#endregion
|
|
3242
3241
|
//#region src/helpers/files.ts
|
|
3243
|
-
const ensurePath = async (path$
|
|
3244
|
-
if (clear) await rimraf(resolve(...path$
|
|
3245
|
-
await mkdir(resolve(...path$
|
|
3242
|
+
const ensurePath = async (path$1, clear = false) => {
|
|
3243
|
+
if (clear) await rimraf(resolve(...path$1));
|
|
3244
|
+
await mkdir(resolve(...path$1), { recursive: true });
|
|
3246
3245
|
};
|
|
3247
|
-
const writeFileToPath = async (path$
|
|
3248
|
-
await mkdir(resolve(...path$
|
|
3249
|
-
await writeFile(resolve(...path$
|
|
3246
|
+
const writeFileToPath = async (path$1, content) => {
|
|
3247
|
+
await mkdir(resolve(...path$1, ".."), { recursive: true });
|
|
3248
|
+
await writeFile(resolve(...path$1), content, "utf-8");
|
|
3250
3249
|
};
|
|
3251
3250
|
/**
|
|
3252
3251
|
* Remove files/directories matching a glob pattern.
|
|
@@ -3324,24 +3323,24 @@ ${renderClientTypesImports({
|
|
|
3324
3323
|
export const createClient = ${renderClientCode(ctx)}
|
|
3325
3324
|
|
|
3326
3325
|
export const everything = {
|
|
3327
|
-
|
|
3326
|
+
$scalar: true
|
|
3328
3327
|
}
|
|
3329
3328
|
`);
|
|
3330
3329
|
if (queryType) ctx.addCodeBlock(`
|
|
3331
3330
|
export type QueryResult<fields extends ${requestTypeName(queryType)}> = FieldsSelection<${queryType.name}, fields>
|
|
3332
|
-
export const generateQueryOp: (fields: ${requestTypeName(queryType)} & {
|
|
3331
|
+
export const generateQueryOp: (fields: ${requestTypeName(queryType)} & { $name?: string }) => GraphqlOperation = function(fields) {
|
|
3333
3332
|
return generateGraphqlOperation('query', typeMap.Query!, fields as any)
|
|
3334
3333
|
}
|
|
3335
3334
|
`);
|
|
3336
3335
|
if (mutationType) ctx.addCodeBlock(`
|
|
3337
3336
|
export type MutationResult<fields extends ${requestTypeName(mutationType)}> = FieldsSelection<${mutationType.name}, fields>
|
|
3338
|
-
export const generateMutationOp: (fields: ${requestTypeName(mutationType)} & {
|
|
3337
|
+
export const generateMutationOp: (fields: ${requestTypeName(mutationType)} & { $name?: string }) => GraphqlOperation = function(fields) {
|
|
3339
3338
|
return generateGraphqlOperation('mutation', typeMap.Mutation!, fields as any)
|
|
3340
3339
|
}
|
|
3341
3340
|
`);
|
|
3342
3341
|
if (subscriptionType) ctx.addCodeBlock(`
|
|
3343
3342
|
export type SubscriptionResult<fields extends ${requestTypeName(subscriptionType)}> = FieldsSelection<${subscriptionType.name}, fields>
|
|
3344
|
-
export const generateSubscriptionOp: (fields: ${requestTypeName(subscriptionType)} & {
|
|
3343
|
+
export const generateSubscriptionOp: (fields: ${requestTypeName(subscriptionType)} & { $name?: string }) => GraphqlOperation = function(fields) {
|
|
3345
3344
|
return generateGraphqlOperation('subscription', typeMap.Subscription!, fields as any)
|
|
3346
3345
|
}
|
|
3347
3346
|
`);
|
|
@@ -3358,12 +3357,12 @@ function renderClientType({ queryType, mutationType, subscriptionType }) {
|
|
|
3358
3357
|
let interfaceContent = "";
|
|
3359
3358
|
if (queryType) interfaceContent += `
|
|
3360
3359
|
query<R extends ${requestTypeName(queryType)}>(
|
|
3361
|
-
request: R & {
|
|
3360
|
+
request: R & { $name?: string },
|
|
3362
3361
|
): Promise<FieldsSelection<${queryType.name}, R>>
|
|
3363
3362
|
`;
|
|
3364
3363
|
if (mutationType) interfaceContent += `
|
|
3365
3364
|
mutation<R extends ${requestTypeName(mutationType)}>(
|
|
3366
|
-
request: R & {
|
|
3365
|
+
request: R & { $name?: string },
|
|
3367
3366
|
): Promise<FieldsSelection<${mutationType.name}, R>>
|
|
3368
3367
|
`;
|
|
3369
3368
|
return `
|
|
@@ -3389,36 +3388,43 @@ const excludedTypes = [
|
|
|
3389
3388
|
//#endregion
|
|
3390
3389
|
//#region src/helpers/prettify.ts
|
|
3391
3390
|
function prettify(code, parser) {
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3391
|
+
if (parser === "skip" || !hasPrettier()) return code;
|
|
3392
|
+
else return runPrettier(code, parser);
|
|
3393
|
+
}
|
|
3394
|
+
function hasPrettier() {
|
|
3395
|
+
try {
|
|
3396
|
+
import.meta.resolve("prettier");
|
|
3397
|
+
return true;
|
|
3398
|
+
} catch {
|
|
3399
|
+
return false;
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
async function runPrettier(code, parser) {
|
|
3403
|
+
const prettier = await import("prettier/standalone.js").then(({ default: mod }) => mod);
|
|
3404
|
+
const parserTS = await import("prettier/plugins/typescript.js").then(({ default: mod }) => mod);
|
|
3405
|
+
const parserEstree = await import("prettier/plugins/estree.js").then(({ default: mod }) => mod);
|
|
3406
|
+
const parserGraphQL = await import("prettier/plugins/graphql.js").then(({ default: mod }) => mod);
|
|
3407
|
+
const userConfig = await (await import("prettier").then((mod) => mod.resolveConfig))("") ?? {
|
|
3408
|
+
semi: false,
|
|
3409
|
+
printWidth: 80,
|
|
3410
|
+
singleQuote: true,
|
|
3411
|
+
trailingComma: "all"
|
|
3412
|
+
};
|
|
3413
|
+
return await prettier.format(code, {
|
|
3414
|
+
...userConfig,
|
|
3415
|
+
parser,
|
|
3416
|
+
plugins: [
|
|
3417
|
+
parserGraphQL,
|
|
3418
|
+
parserTS,
|
|
3419
|
+
parserEstree
|
|
3420
|
+
]
|
|
3415
3421
|
});
|
|
3416
3422
|
}
|
|
3417
3423
|
|
|
3418
3424
|
//#endregion
|
|
3419
3425
|
//#region src/render/common/relativeImportPath.ts
|
|
3420
3426
|
const relativeImportPath = (from, to) => {
|
|
3421
|
-
const fromResolved = path
|
|
3427
|
+
const fromResolved = path.relative(from, to);
|
|
3422
3428
|
return fromResolved[0] === "." ? fromResolved : `./${fromResolved}`;
|
|
3423
3429
|
};
|
|
3424
3430
|
|
|
@@ -3471,7 +3477,7 @@ var RenderContext = class {
|
|
|
3471
3477
|
}
|
|
3472
3478
|
if (parser) {
|
|
3473
3479
|
const whiteSpaced = blocks.join("\n\n");
|
|
3474
|
-
if (pretty
|
|
3480
|
+
if (pretty) return prettify(whiteSpaced, parser);
|
|
3475
3481
|
return whiteSpaced;
|
|
3476
3482
|
}
|
|
3477
3483
|
return blocks.join("");
|
|
@@ -3546,8 +3552,8 @@ const objectType$2 = (type, ctx) => {
|
|
|
3546
3552
|
const argsPresent = field.args.length > 0;
|
|
3547
3553
|
const argsString = toArgsString(field);
|
|
3548
3554
|
const argsOptional = !argsString.match(/[^?]:/);
|
|
3549
|
-
if (argsPresent) if (resolvable) types.push(`(${requestTypeName(resolvedType)} & {
|
|
3550
|
-
else types.push(`{
|
|
3555
|
+
if (argsPresent) if (resolvable) types.push(`(${requestTypeName(resolvedType)} & { $args${argsOptional ? "?" : ""}: ${argsString} })`);
|
|
3556
|
+
else types.push(`{ $args: ${argsString} }`);
|
|
3551
3557
|
if (argsOptional && !resolvable) types.push("boolean | number");
|
|
3552
3558
|
if (!argsPresent && resolvable) types.push(requestTypeName(resolvedType));
|
|
3553
3559
|
return `${fieldComment(field)}${field.name}?: ${types.join(" | ")}`;
|
|
@@ -3557,8 +3563,8 @@ const objectType$2 = (type, ctx) => {
|
|
|
3557
3563
|
if (ctx.config?.sortProperties) interfaceProperties = interfaceProperties.sort();
|
|
3558
3564
|
fieldStrings = fieldStrings.concat(interfaceProperties);
|
|
3559
3565
|
}
|
|
3560
|
-
fieldStrings.push("
|
|
3561
|
-
fieldStrings.push("
|
|
3566
|
+
fieldStrings.push("$typeName?: boolean | number");
|
|
3567
|
+
fieldStrings.push("$scalar?: boolean | number");
|
|
3562
3568
|
fieldStrings = fieldStrings.map((x) => x.split("\n").filter(Boolean).map((l) => INDENTATION$1 + l).join("\n"));
|
|
3563
3569
|
ctx.addCodeBlock(`${typeComment(type)}export interface ${requestTypeName(type)}{\n${fieldStrings.join("\n")}\n}`);
|
|
3564
3570
|
};
|
|
@@ -4493,7 +4499,7 @@ const unionType$2 = (type, ctx) => {
|
|
|
4493
4499
|
fieldStrings.push(...commonInterfaces.map((type$1) => {
|
|
4494
4500
|
return `on_${type$1.name}?: ${requestTypeName(type$1)}`;
|
|
4495
4501
|
}));
|
|
4496
|
-
fieldStrings.push("
|
|
4502
|
+
fieldStrings.push("$typeName?: boolean | number");
|
|
4497
4503
|
ctx.addCodeBlock(`${typeComment(type)}export interface ${requestTypeName(type)}{\n${fieldStrings.map((x) => " " + x).join(",\n")}\n}`);
|
|
4498
4504
|
};
|
|
4499
4505
|
|
|
@@ -4548,7 +4554,7 @@ const objectType$1 = (type, ctx) => {
|
|
|
4548
4554
|
const typeNames = isObjectType(type) ? [type.name] : ctx.schema.getPossibleTypes(type).map((t) => t.name);
|
|
4549
4555
|
let fieldStrings = fields.map((f) => {
|
|
4550
4556
|
return `${fieldComment(f)}${f.name}: ${renderTyping(f.type)}`;
|
|
4551
|
-
}).concat([
|
|
4557
|
+
}).concat([`$typeName: ${typeNames.length > 0 ? typeNames.map((t) => `'${t}'`).join("|") : "string"}`]);
|
|
4552
4558
|
fieldStrings = fieldStrings.map((x) => x.split("\n").filter(Boolean).map((l) => INDENTATION + l).join("\n"));
|
|
4553
4559
|
ctx.addCodeBlock(`${typeComment(type)}export interface ${type.name} {\n${fieldStrings.join("\n")}\n}`);
|
|
4554
4560
|
};
|
|
@@ -4584,7 +4590,7 @@ function renderScalarTypes(ctx, types) {
|
|
|
4584
4590
|
const unionType$1 = (type, ctx) => {
|
|
4585
4591
|
let typeNames = type.getTypes().map((t) => t.name);
|
|
4586
4592
|
if (ctx.config?.sortProperties) typeNames = typeNames.sort();
|
|
4587
|
-
ctx.addCodeBlock(`${typeComment(type)}export type ${type.name} = (${typeNames.join(" | ")}) & {
|
|
4593
|
+
ctx.addCodeBlock(`${typeComment(type)}export type ${type.name} = (${typeNames.join(" | ")}) & { $isUnion?: true }`);
|
|
4588
4594
|
};
|
|
4589
4595
|
|
|
4590
4596
|
//#endregion
|
|
@@ -4593,7 +4599,7 @@ const interfaceType = (type, ctx) => {
|
|
|
4593
4599
|
if (!ctx.schema) throw new Error("schema is required to render unionType");
|
|
4594
4600
|
const typeNames = ctx.schema.getPossibleTypes(type).map((t) => t.name);
|
|
4595
4601
|
if (!typeNames.length) objectType$1(type, ctx);
|
|
4596
|
-
else ctx.addCodeBlock(`${typeComment(type)}export type ${type.name} = (${typeNames.join(" | ")}) & {
|
|
4602
|
+
else ctx.addCodeBlock(`${typeComment(type)}export type ${type.name} = (${typeNames.join(" | ")}) & { $isUnion?: true }`);
|
|
4597
4603
|
};
|
|
4598
4604
|
|
|
4599
4605
|
//#endregion
|
|
@@ -4642,9 +4648,9 @@ const renderSchema = (schema, ctx) => {
|
|
|
4642
4648
|
const renderTypeGuard = (target, possible) => {
|
|
4643
4649
|
return `
|
|
4644
4650
|
const ${target}_possibleTypes: string[] = [${possible.map((t) => `'${t}'`).join(",")}]
|
|
4645
|
-
export const is${target} = (obj?: {
|
|
4646
|
-
if (!obj
|
|
4647
|
-
return ${target}_possibleTypes.includes(obj
|
|
4651
|
+
export const is${target} = (obj?: { $typeName?: any } | null): obj is ${target} => {
|
|
4652
|
+
if (!obj?.$typeName) throw new Error('$typeName is missing in "is${target}"')
|
|
4653
|
+
return ${target}_possibleTypes.includes(obj.$typeName)
|
|
4648
4654
|
}
|
|
4649
4655
|
`;
|
|
4650
4656
|
};
|
|
@@ -4690,7 +4696,7 @@ const objectType = (type, ctx) => {
|
|
|
4690
4696
|
if (isInterfaceType(type) && ctx.schema) ctx.schema.getPossibleTypes(type).map((t) => {
|
|
4691
4697
|
if (!isEmpty(typeObj)) typeObj[`on_${t.name}`] = { type: t.name };
|
|
4692
4698
|
});
|
|
4693
|
-
if (!isEmpty(typeObj)) typeObj
|
|
4699
|
+
if (!isEmpty(typeObj)) typeObj.$typeName = { type: "String" };
|
|
4694
4700
|
return typeObj;
|
|
4695
4701
|
};
|
|
4696
4702
|
|
|
@@ -4705,7 +4711,7 @@ const unionType = (type, _) => {
|
|
|
4705
4711
|
uniq_default(types.map((x) => x.getInterfaces()).flat()).forEach((t) => {
|
|
4706
4712
|
typeObj[`on_${t.name}`] = { type: t.name };
|
|
4707
4713
|
});
|
|
4708
|
-
typeObj
|
|
4714
|
+
typeObj.$typeName = { type: "String" };
|
|
4709
4715
|
return typeObj;
|
|
4710
4716
|
};
|
|
4711
4717
|
|
|
@@ -32,10 +32,10 @@ export interface GraphqlOperation {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const parseRequest = (request: Request | undefined, ctx: Context, path: string[]): string => {
|
|
35
|
-
if (typeof request === 'object' && '
|
|
36
|
-
const args: any = request
|
|
35
|
+
if (typeof request === 'object' && '$args' in request) {
|
|
36
|
+
const args: any = request.$args;
|
|
37
37
|
let fields: Request | undefined = { ...request };
|
|
38
|
-
delete fields
|
|
38
|
+
delete fields.$args;
|
|
39
39
|
const argNames = Object.keys(args);
|
|
40
40
|
|
|
41
41
|
if (argNames.length === 0) {
|
|
@@ -75,7 +75,7 @@ const parseRequest = (request: Request | undefined, ctx: Context, path: string[]
|
|
|
75
75
|
|
|
76
76
|
let scalarFieldsFragment: string | undefined;
|
|
77
77
|
|
|
78
|
-
if (fieldNames.includes('
|
|
78
|
+
if (fieldNames.includes('$scalar')) {
|
|
79
79
|
const falsyFieldNames = new Set(Object.keys(fields).filter((k) => !Boolean(fields[k])));
|
|
80
80
|
if (scalarFields?.length) {
|
|
81
81
|
ctx.fragmentCounter++;
|
|
@@ -90,7 +90,7 @@ const parseRequest = (request: Request | undefined, ctx: Context, path: string[]
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const fieldsSelection = fieldNames
|
|
93
|
-
.filter((f) => !['
|
|
93
|
+
.filter((f) => !['$scalar', '$name'].includes(f))
|
|
94
94
|
.map((f) => {
|
|
95
95
|
const parsed = parseRequest(fields[f], ctx, [...path, f]);
|
|
96
96
|
|
|
@@ -142,7 +142,7 @@ export const generateGraphqlOperation = (
|
|
|
142
142
|
})})`
|
|
143
143
|
: '';
|
|
144
144
|
|
|
145
|
-
const operationName = fields
|
|
145
|
+
const operationName = fields?.$name || '';
|
|
146
146
|
|
|
147
147
|
return {
|
|
148
148
|
query: [`${operation} ${operationName}${varsString}${result}`, ...ctx.fragments].join(','),
|
package/dist/runtime/index.ts
CHANGED
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
|
|
11
11
|
3. HandleObject handles object types
|
|
12
12
|
|
|
13
|
-
4.
|
|
13
|
+
4. Handle$scalar adds all scalar properties excluding non scalar props
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
export type FieldsSelection<SRC extends Anify<DST> | undefined, DST> = {
|
|
17
17
|
scalar: SRC;
|
|
18
|
-
union:
|
|
18
|
+
union: Handle$isUnion<SRC, DST>;
|
|
19
19
|
object: HandleObject<SRC, DST>;
|
|
20
20
|
array: SRC extends Nil ? never : SRC extends Array<infer T | null> ? Array<FieldsSelection<T, DST>> : never;
|
|
21
|
-
|
|
21
|
+
$scalar: Handle$scalar<SRC, DST>;
|
|
22
22
|
never: never;
|
|
23
23
|
}[DST extends Nil
|
|
24
24
|
? 'never'
|
|
@@ -28,10 +28,10 @@ export type FieldsSelection<SRC extends Anify<DST> | undefined, DST> = {
|
|
|
28
28
|
? 'scalar'
|
|
29
29
|
: SRC extends any[]
|
|
30
30
|
? 'array'
|
|
31
|
-
: SRC extends {
|
|
31
|
+
: SRC extends { $isUnion?: any }
|
|
32
32
|
? 'union'
|
|
33
|
-
: DST extends {
|
|
34
|
-
? '
|
|
33
|
+
: DST extends { $scalar?: any }
|
|
34
|
+
? '$scalar'
|
|
35
35
|
: DST extends {}
|
|
36
36
|
? 'object'
|
|
37
37
|
: 'never'];
|
|
@@ -54,7 +54,7 @@ type HandleObject<SRC extends Anify<DST>, DST> = DST extends boolean
|
|
|
54
54
|
// }[keyof DST]
|
|
55
55
|
>;
|
|
56
56
|
|
|
57
|
-
type
|
|
57
|
+
type Handle$scalar<SRC extends Anify<DST>, DST> = SRC extends Nil
|
|
58
58
|
? never
|
|
59
59
|
: Pick<
|
|
60
60
|
// continue processing fields that are in DST, directly pass SRC type if not in DST
|
|
@@ -75,12 +75,12 @@ type Handle__scalar<SRC extends Anify<DST>, DST> = SRC extends Nil
|
|
|
75
75
|
}[keyof SRC]
|
|
76
76
|
>;
|
|
77
77
|
|
|
78
|
-
type
|
|
78
|
+
type Handle$isUnion<SRC extends Anify<DST>, DST> = SRC extends Nil ? never : Omit<SRC, FieldsToRemove>; // just return the union type
|
|
79
79
|
|
|
80
80
|
type Scalar = string | number | Date | boolean | null | undefined;
|
|
81
81
|
|
|
82
82
|
type Anify<T> = { [P in keyof T]?: any };
|
|
83
83
|
|
|
84
|
-
type FieldsToRemove = '
|
|
84
|
+
type FieldsToRemove = '$name' | '$args' | '$scalar' | '$isUnion';
|
|
85
85
|
|
|
86
86
|
type Nil = undefined | null;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@manot40/genql-cli",
|
|
4
4
|
"author": "Tommaso De Rossi, morse <beats.by.morse@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "1.0
|
|
6
|
+
"version": "1.1.0",
|
|
7
7
|
"homepage": "https://genql.dev",
|
|
8
8
|
"description": "Generate a TypeScript SDK for any GraphQl API",
|
|
9
9
|
"keywords": [
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"listr2": "^9.0.5",
|
|
53
53
|
"lodash-es": "^4.17.22",
|
|
54
54
|
"ts-jest": "^29.4.6",
|
|
55
|
-
"tsdown": "^0.19.0-beta.
|
|
55
|
+
"tsdown": "^0.19.0-beta.5",
|
|
56
56
|
"yargs": "^18.0.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//#region node_modules/get-east-asian-width/lookup.js
|
|
2
|
-
function isAmbiguous(x) {
|
|
3
|
-
return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
|
|
4
|
-
}
|
|
5
|
-
function isFullWidth(x) {
|
|
6
|
-
return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
|
|
7
|
-
}
|
|
8
|
-
function isWide(x) {
|
|
9
|
-
return x >= 4352 && x <= 4447 || x === 8986 || x === 8987 || x === 9001 || x === 9002 || x >= 9193 && x <= 9196 || x === 9200 || x === 9203 || x === 9725 || x === 9726 || x === 9748 || x === 9749 || x >= 9776 && x <= 9783 || x >= 9800 && x <= 9811 || x === 9855 || x >= 9866 && x <= 9871 || x === 9875 || x === 9889 || x === 9898 || x === 9899 || x === 9917 || x === 9918 || x === 9924 || x === 9925 || x === 9934 || x === 9940 || x === 9962 || x === 9970 || x === 9971 || x === 9973 || x === 9978 || x === 9981 || x === 9989 || x === 9994 || x === 9995 || x === 10024 || x === 10060 || x === 10062 || x >= 10067 && x <= 10069 || x === 10071 || x >= 10133 && x <= 10135 || x === 10160 || x === 10175 || x === 11035 || x === 11036 || x === 11088 || x === 11093 || x >= 11904 && x <= 11929 || x >= 11931 && x <= 12019 || x >= 12032 && x <= 12245 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12353 && x <= 12438 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12773 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 42124 || x >= 42128 && x <= 42182 || x >= 43360 && x <= 43388 || x >= 44032 && x <= 55203 || x >= 63744 && x <= 64255 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 94176 && x <= 94180 || x >= 94192 && x <= 94198 || x >= 94208 && x <= 101589 || x >= 101631 && x <= 101662 || x >= 101760 && x <= 101874 || x >= 110576 && x <= 110579 || x >= 110581 && x <= 110587 || x === 110589 || x === 110590 || x >= 110592 && x <= 110882 || x === 110898 || x >= 110928 && x <= 110930 || x === 110933 || x >= 110948 && x <= 110951 || x >= 110960 && x <= 111355 || x >= 119552 && x <= 119638 || x >= 119648 && x <= 119670 || x === 126980 || x === 127183 || x === 127374 || x >= 127377 && x <= 127386 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x === 127568 || x === 127569 || x >= 127584 && x <= 127589 || x >= 127744 && x <= 127776 || x >= 127789 && x <= 127797 || x >= 127799 && x <= 127868 || x >= 127870 && x <= 127891 || x >= 127904 && x <= 127946 || x >= 127951 && x <= 127955 || x >= 127968 && x <= 127984 || x === 127988 || x >= 127992 && x <= 128062 || x === 128064 || x >= 128066 && x <= 128252 || x >= 128255 && x <= 128317 || x >= 128331 && x <= 128334 || x >= 128336 && x <= 128359 || x === 128378 || x === 128405 || x === 128406 || x === 128420 || x >= 128507 && x <= 128591 || x >= 128640 && x <= 128709 || x === 128716 || x >= 128720 && x <= 128722 || x >= 128725 && x <= 128728 || x >= 128732 && x <= 128735 || x === 128747 || x === 128748 || x >= 128756 && x <= 128764 || x >= 128992 && x <= 129003 || x === 129008 || x >= 129292 && x <= 129338 || x >= 129340 && x <= 129349 || x >= 129351 && x <= 129535 || x >= 129648 && x <= 129660 || x >= 129664 && x <= 129674 || x >= 129678 && x <= 129734 || x === 129736 || x >= 129741 && x <= 129756 || x >= 129759 && x <= 129770 || x >= 129775 && x <= 129784 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region node_modules/get-east-asian-width/index.js
|
|
14
|
-
function validate(codePoint) {
|
|
15
|
-
if (!Number.isSafeInteger(codePoint)) throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
16
|
-
}
|
|
17
|
-
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
18
|
-
validate(codePoint);
|
|
19
|
-
if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) return 2;
|
|
20
|
-
return 1;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
export { isFullWidth as n, isWide as r, eastAsianWidth as t };
|