@smartive/graphql-magic 8.1.3 → 9.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/CHANGELOG.md +3 -3
- package/dist/bin/gqm.cjs +37 -64
- package/dist/cjs/index.cjs +2 -13
- package/dist/esm/schema/utils.js +2 -3
- package/dist/esm/schema/utils.js.map +1 -1
- package/dist/esm/values.d.ts +0 -4
- package/dist/esm/values.js +1 -6
- package/dist/esm/values.js.map +1 -1
- package/package.json +1 -1
- package/src/bin/gqm/codegen.ts +3 -2
- package/src/bin/gqm/settings.ts +13 -10
- package/src/bin/gqm/static-eval.ts +7 -3
- package/src/bin/gqm/templates.ts +0 -37
- package/src/bin/gqm/visitor.ts +15 -7
- package/src/schema/utils.ts +3 -3
- package/src/values.ts +1 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# [9.1.0](https://github.com/smartive/graphql-magic/compare/v9.0.0...v9.1.0) (2023-09-06)
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
###
|
|
4
|
+
### Features
|
|
5
5
|
|
|
6
|
-
*
|
|
6
|
+
* Use graphql queries path ([#61](https://github.com/smartive/graphql-magic/issues/61)) ([8c85002](https://github.com/smartive/graphql-magic/commit/8c850028673ced969a61e25b664fac9596586388))
|
package/dist/bin/gqm.cjs
CHANGED
|
@@ -893,15 +893,6 @@ var import_flatMap2 = __toESM(require("lodash/flatMap"), 1);
|
|
|
893
893
|
|
|
894
894
|
// src/schema/utils.ts
|
|
895
895
|
var import_luxon = require("luxon");
|
|
896
|
-
|
|
897
|
-
// src/values.ts
|
|
898
|
-
var Enum = class {
|
|
899
|
-
constructor(value2) {
|
|
900
|
-
this.value = value2;
|
|
901
|
-
}
|
|
902
|
-
};
|
|
903
|
-
|
|
904
|
-
// src/schema/utils.ts
|
|
905
896
|
var document = (definitions) => ({
|
|
906
897
|
kind: "Document",
|
|
907
898
|
definitions
|
|
@@ -1007,9 +998,9 @@ var value = (val = null) => val === null ? {
|
|
|
1007
998
|
} : typeof val === "string" ? {
|
|
1008
999
|
kind: "StringValue",
|
|
1009
1000
|
value: val
|
|
1010
|
-
} : val instanceof
|
|
1001
|
+
} : val instanceof Symbol ? {
|
|
1011
1002
|
kind: "EnumValue",
|
|
1012
|
-
value: val.
|
|
1003
|
+
value: val.description
|
|
1013
1004
|
} : Array.isArray(val) ? {
|
|
1014
1005
|
kind: "ListValue",
|
|
1015
1006
|
values: val.map(value)
|
|
@@ -1288,41 +1279,6 @@ export const rawModels: RawModels = [
|
|
|
1288
1279
|
|
|
1289
1280
|
export const models = getModels(rawModels);
|
|
1290
1281
|
`;
|
|
1291
|
-
var GRAPHQL_CODEGEN = (path) => `
|
|
1292
|
-
overwrite: true
|
|
1293
|
-
schema: '${path}/schema.graphql'
|
|
1294
|
-
documents: null
|
|
1295
|
-
generates:
|
|
1296
|
-
${path}/api/index.ts:
|
|
1297
|
-
plugins:
|
|
1298
|
-
- 'typescript'
|
|
1299
|
-
- 'typescript-resolvers'
|
|
1300
|
-
- add:
|
|
1301
|
-
content: "import { DateTime } from 'luxon'"
|
|
1302
|
-
config:
|
|
1303
|
-
scalars:
|
|
1304
|
-
DateTime: DateTime
|
|
1305
|
-
`;
|
|
1306
|
-
var CLIENT_CODEGEN = (path) => `
|
|
1307
|
-
schema: ${path}/schema.graphql
|
|
1308
|
-
documents: [ './src/**/*.ts', './src/**/*.tsx' ]
|
|
1309
|
-
generates:
|
|
1310
|
-
${path}/client/index.ts:
|
|
1311
|
-
plugins:
|
|
1312
|
-
- typescript
|
|
1313
|
-
- typescript-operations
|
|
1314
|
-
- typescript-compatibility
|
|
1315
|
-
|
|
1316
|
-
config:
|
|
1317
|
-
preResolveTypes: true # Simplifies the generated types
|
|
1318
|
-
namingConvention: keep # Keeps naming as-is
|
|
1319
|
-
nonOptionalTypename: true # Forces \`__typename\` on all selection sets
|
|
1320
|
-
skipTypeNameForRoot: true # Don't generate __typename for root types
|
|
1321
|
-
avoidOptionals: # Avoids optionals on the level of the field
|
|
1322
|
-
field: true
|
|
1323
|
-
scalars:
|
|
1324
|
-
DateTime: string
|
|
1325
|
-
`;
|
|
1326
1282
|
var KNEXFILE = `
|
|
1327
1283
|
const config = {
|
|
1328
1284
|
client: 'postgresql',
|
|
@@ -1355,8 +1311,13 @@ var DEFAULTS = {
|
|
|
1355
1311
|
ensureFileExists(`${path}/db/.gitkeep`, "");
|
|
1356
1312
|
ensureFileExists(`${path}/api/.gitkeep`, "");
|
|
1357
1313
|
ensureFileExists(`${path}/client/.gitkeep`, "");
|
|
1358
|
-
|
|
1359
|
-
|
|
1314
|
+
}
|
|
1315
|
+
},
|
|
1316
|
+
graphqlQueriesPath: {
|
|
1317
|
+
question: "Where to look for graphql queries?",
|
|
1318
|
+
defaultValue: "src/graphql/client/queries",
|
|
1319
|
+
init: (path) => {
|
|
1320
|
+
ensureDirectoryExists(path);
|
|
1360
1321
|
}
|
|
1361
1322
|
}
|
|
1362
1323
|
};
|
|
@@ -1390,13 +1351,13 @@ var getSetting = async (name2) => {
|
|
|
1390
1351
|
}
|
|
1391
1352
|
return settings[name2];
|
|
1392
1353
|
};
|
|
1393
|
-
var ensureDirectoryExists = (
|
|
1394
|
-
const dir = (0, import_path.dirname)(filePath);
|
|
1354
|
+
var ensureDirectoryExists = (dir) => {
|
|
1395
1355
|
if ((0, import_fs.existsSync)(dir)) {
|
|
1396
1356
|
return true;
|
|
1397
1357
|
}
|
|
1398
1358
|
ensureDirectoryExists(dir);
|
|
1399
1359
|
try {
|
|
1360
|
+
console.info(`Creating directory ${dir}`);
|
|
1400
1361
|
(0, import_fs.mkdirSync)(dir);
|
|
1401
1362
|
return true;
|
|
1402
1363
|
} catch (err) {
|
|
@@ -1409,12 +1370,12 @@ var ensureDirectoryExists = (filePath) => {
|
|
|
1409
1370
|
var ensureFileExists = (filePath, content) => {
|
|
1410
1371
|
if (!(0, import_fs.existsSync)(filePath)) {
|
|
1411
1372
|
console.info(`Creating ${filePath}`);
|
|
1412
|
-
ensureDirectoryExists(filePath);
|
|
1373
|
+
ensureDirectoryExists((0, import_path.dirname)(filePath));
|
|
1413
1374
|
(0, import_fs.writeFileSync)(filePath, content);
|
|
1414
1375
|
}
|
|
1415
1376
|
};
|
|
1416
1377
|
var writeToFile = (filePath, content) => {
|
|
1417
|
-
ensureDirectoryExists(filePath);
|
|
1378
|
+
ensureDirectoryExists((0, import_path.dirname)(filePath));
|
|
1418
1379
|
if ((0, import_fs.existsSync)(filePath)) {
|
|
1419
1380
|
const currentContent = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
1420
1381
|
if (content === currentContent) {
|
|
@@ -1434,7 +1395,7 @@ var generateGraphqlApiTypes = async () => {
|
|
|
1434
1395
|
await (0, import_cli.generate)({
|
|
1435
1396
|
overwrite: true,
|
|
1436
1397
|
schema: `${generatedFolderPath}/schema.graphql`,
|
|
1437
|
-
documents:
|
|
1398
|
+
documents: void 0,
|
|
1438
1399
|
generates: {
|
|
1439
1400
|
[`${generatedFolderPath}/api/index.ts`]: {
|
|
1440
1401
|
plugins: ["typescript", "typescript-resolvers", { add: { content: `import { DateTime } from 'luxon';` } }]
|
|
@@ -1449,9 +1410,10 @@ var generateGraphqlApiTypes = async () => {
|
|
|
1449
1410
|
};
|
|
1450
1411
|
var generateGraphqlClientTypes = async () => {
|
|
1451
1412
|
const generatedFolderPath = await getSetting("generatedFolderPath");
|
|
1413
|
+
const graphqlQueriesPath = await getSetting("graphqlQueriesPath");
|
|
1452
1414
|
await (0, import_cli.generate)({
|
|
1453
1415
|
schema: `${generatedFolderPath}/schema.graphql`,
|
|
1454
|
-
documents: [
|
|
1416
|
+
documents: [graphqlQueriesPath],
|
|
1455
1417
|
generates: {
|
|
1456
1418
|
[`${generatedFolderPath}/client/index.ts`]: {
|
|
1457
1419
|
plugins: ["typescript", "typescript-operations", "typescript-compatibility"]
|
|
@@ -1485,16 +1447,23 @@ var import_ts_morph2 = require("ts-morph");
|
|
|
1485
1447
|
|
|
1486
1448
|
// src/bin/gqm/visitor.ts
|
|
1487
1449
|
var import_ts_morph = require("ts-morph");
|
|
1488
|
-
var visit = (node, context,
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1450
|
+
var visit = (node, context, visitor) => {
|
|
1451
|
+
if (!node) {
|
|
1452
|
+
if (visitor.undefined) {
|
|
1453
|
+
return visitor.undefined();
|
|
1454
|
+
}
|
|
1455
|
+
console.trace();
|
|
1456
|
+
throw new Error(`Cannot handle undefined node.`);
|
|
1457
|
+
}
|
|
1458
|
+
const kind = node.getKind();
|
|
1459
|
+
const func = visitor[kind];
|
|
1460
|
+
if (func) {
|
|
1461
|
+
return func(node, context);
|
|
1492
1462
|
}
|
|
1493
|
-
if (
|
|
1494
|
-
return
|
|
1463
|
+
if (visitor.unknown) {
|
|
1464
|
+
return visitor.unknown(node);
|
|
1495
1465
|
}
|
|
1496
1466
|
console.error(node.getText());
|
|
1497
|
-
console.error(node.getParent().getText());
|
|
1498
1467
|
throw new Error(
|
|
1499
1468
|
`Cannot handle kind ${get(
|
|
1500
1469
|
Object.entries(import_ts_morph.SyntaxKind).find(([, val]) => val === kind),
|
|
@@ -1504,8 +1473,8 @@ var visit = (node, context, visitor2) => {
|
|
|
1504
1473
|
};
|
|
1505
1474
|
|
|
1506
1475
|
// src/bin/gqm/static-eval.ts
|
|
1507
|
-
var staticEval = (node, context) => visit(node, context,
|
|
1508
|
-
var
|
|
1476
|
+
var staticEval = (node, context) => visit(node, context, VISITOR);
|
|
1477
|
+
var VISITOR = {
|
|
1509
1478
|
undefined: () => void 0,
|
|
1510
1479
|
[import_ts_morph2.SyntaxKind.VariableDeclaration]: (node, context) => staticEval(node.getInitializer(), context),
|
|
1511
1480
|
[import_ts_morph2.SyntaxKind.ArrayLiteralExpression]: (node, context) => {
|
|
@@ -1541,6 +1510,8 @@ var visitor = {
|
|
|
1541
1510
|
return void 0;
|
|
1542
1511
|
case "process":
|
|
1543
1512
|
return process;
|
|
1513
|
+
case "Symbol":
|
|
1514
|
+
return Symbol;
|
|
1544
1515
|
}
|
|
1545
1516
|
const definitionNodes = node.getDefinitionNodes();
|
|
1546
1517
|
if (!definitionNodes.length) {
|
|
@@ -1554,6 +1525,7 @@ var visitor = {
|
|
|
1554
1525
|
[import_ts_morph2.SyntaxKind.TrueKeyword]: () => true,
|
|
1555
1526
|
[import_ts_morph2.SyntaxKind.FalseKeyword]: () => false,
|
|
1556
1527
|
[import_ts_morph2.SyntaxKind.NumericLiteral]: (node) => node.getLiteralValue(),
|
|
1528
|
+
[import_ts_morph2.SyntaxKind.BigIntLiteral]: (node) => node.getLiteralValue(),
|
|
1557
1529
|
[import_ts_morph2.SyntaxKind.CallExpression]: (node, context) => {
|
|
1558
1530
|
const method = staticEval(node.getExpression(), context);
|
|
1559
1531
|
const args2 = node.getArguments().map((arg) => staticEval(arg, context));
|
|
@@ -1679,7 +1651,8 @@ var visitor = {
|
|
|
1679
1651
|
const argument = staticEval(node.getArgumentExpression(), context);
|
|
1680
1652
|
return target[argument];
|
|
1681
1653
|
},
|
|
1682
|
-
[import_ts_morph2.SyntaxKind.NoSubstitutionTemplateLiteral]: (node) => node.getLiteralValue()
|
|
1654
|
+
[import_ts_morph2.SyntaxKind.NoSubstitutionTemplateLiteral]: (node) => node.getLiteralValue(),
|
|
1655
|
+
[import_ts_morph2.SyntaxKind.NullKeyword]: () => null
|
|
1683
1656
|
};
|
|
1684
1657
|
|
|
1685
1658
|
// src/bin/gqm/utils.ts
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -30,7 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var src_exports = {};
|
|
31
31
|
__export(src_exports, {
|
|
32
32
|
AliasGenerator: () => AliasGenerator,
|
|
33
|
-
Enum: () => Enum,
|
|
34
33
|
ForbiddenError: () => ForbiddenError,
|
|
35
34
|
GraphQLError: () => GraphQLError,
|
|
36
35
|
ID_ALIAS: () => ID_ALIAS,
|
|
@@ -2374,15 +2373,6 @@ var import_flatMap2 = __toESM(require("lodash/flatMap"), 1);
|
|
|
2374
2373
|
|
|
2375
2374
|
// src/schema/utils.ts
|
|
2376
2375
|
var import_luxon = require("luxon");
|
|
2377
|
-
|
|
2378
|
-
// src/values.ts
|
|
2379
|
-
var Enum = class {
|
|
2380
|
-
constructor(value2) {
|
|
2381
|
-
this.value = value2;
|
|
2382
|
-
}
|
|
2383
|
-
};
|
|
2384
|
-
|
|
2385
|
-
// src/schema/utils.ts
|
|
2386
2376
|
var document = (definitions) => ({
|
|
2387
2377
|
kind: "Document",
|
|
2388
2378
|
definitions
|
|
@@ -2509,9 +2499,9 @@ var value = (val = null) => val === null ? {
|
|
|
2509
2499
|
} : typeof val === "string" ? {
|
|
2510
2500
|
kind: "StringValue",
|
|
2511
2501
|
value: val
|
|
2512
|
-
} : val instanceof
|
|
2502
|
+
} : val instanceof Symbol ? {
|
|
2513
2503
|
kind: "EnumValue",
|
|
2514
|
-
value: val.
|
|
2504
|
+
value: val.description
|
|
2515
2505
|
} : Array.isArray(val) ? {
|
|
2516
2506
|
kind: "ListValue",
|
|
2517
2507
|
values: val.map(value)
|
|
@@ -2757,7 +2747,6 @@ var printSchemaFromModels = (models) => printSchema((0, import_graphql5.buildAST
|
|
|
2757
2747
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2758
2748
|
0 && (module.exports = {
|
|
2759
2749
|
AliasGenerator,
|
|
2760
|
-
Enum,
|
|
2761
2750
|
ForbiddenError,
|
|
2762
2751
|
GraphQLError,
|
|
2763
2752
|
ID_ALIAS,
|
package/dist/esm/schema/utils.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DateTime } from 'luxon';
|
|
2
|
-
import { Enum } from '../values';
|
|
3
2
|
export const document = (definitions) => ({
|
|
4
3
|
kind: 'Document',
|
|
5
4
|
definitions,
|
|
@@ -124,10 +123,10 @@ export const value = (val = null) => val === null
|
|
|
124
123
|
kind: 'StringValue',
|
|
125
124
|
value: val,
|
|
126
125
|
}
|
|
127
|
-
: val instanceof
|
|
126
|
+
: val instanceof Symbol
|
|
128
127
|
? {
|
|
129
128
|
kind: 'EnumValue',
|
|
130
|
-
value: val.
|
|
129
|
+
value: val.description,
|
|
131
130
|
}
|
|
132
131
|
: Array.isArray(val)
|
|
133
132
|
? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/schema/utils.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/schema/utils.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAuBjC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,WAA6B,EAAgB,EAAE,CAAC,CAAC;IACxE,IAAI,EAAE,UAAU;IAChB,WAAW;CACZ,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,SAA8B,EAAE,MAAgB,EAA2B,EAAE,CAAC,CAAC;IACpH,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;IACf,UAAU,EAAE,KAAK;IACjB,IAAI,EAAE,qBAAqB;IAC3B,SAAS,EAAE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC;IACxC,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;CAC/B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAW,EAA4B,EAAE,CAAC,CAAC;IAChE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;IACf,IAAI,EAAE,sBAAsB;CAC7B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,MAAe,EAAE,GAAiB,EAAiC,EAAE,CAAC,CAAC;IACxG,IAAI,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;wBACpB,CAAC,CAAC;4BACE,IAAI,EAAE,WAAW;4BACjB,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC;yBACvB;wBACH,CAAC,CAAC,GAAG,YAAY,QAAQ;4BACzB,CAAC,CAAC;gCACE,IAAI,EAAE,aAAa;gCACnB,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE;6BACtB;4BACH,CAAC,CAAC;gCACE,IAAI,EAAE,aAAa;gCACnB,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAC1B,CAAC,GAAG,EAAmB,EAAE,CAAC,CAAC;oCACzB,IAAI,EAAE,aAAa;oCACnB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;oCACf,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;iCACvB,CAAC,CACH;6BACF,CAAC"}
|
package/dist/esm/values.d.ts
CHANGED
package/dist/esm/values.js
CHANGED
package/dist/esm/values.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../src/values.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../src/values.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/src/bin/gqm/codegen.ts
CHANGED
|
@@ -6,7 +6,7 @@ export const generateGraphqlApiTypes = async () => {
|
|
|
6
6
|
await generate({
|
|
7
7
|
overwrite: true,
|
|
8
8
|
schema: `${generatedFolderPath}/schema.graphql`,
|
|
9
|
-
documents:
|
|
9
|
+
documents: undefined,
|
|
10
10
|
generates: {
|
|
11
11
|
[`${generatedFolderPath}/api/index.ts`]: {
|
|
12
12
|
plugins: ['typescript', 'typescript-resolvers', { add: { content: `import { DateTime } from 'luxon';` } }],
|
|
@@ -22,9 +22,10 @@ export const generateGraphqlApiTypes = async () => {
|
|
|
22
22
|
|
|
23
23
|
export const generateGraphqlClientTypes = async () => {
|
|
24
24
|
const generatedFolderPath = await getSetting('generatedFolderPath');
|
|
25
|
+
const graphqlQueriesPath = await getSetting('graphqlQueriesPath');
|
|
25
26
|
await generate({
|
|
26
27
|
schema: `${generatedFolderPath}/schema.graphql`,
|
|
27
|
-
documents: [
|
|
28
|
+
documents: [graphqlQueriesPath],
|
|
28
29
|
generates: {
|
|
29
30
|
[`${generatedFolderPath}/client/index.ts`]: {
|
|
30
31
|
plugins: ['typescript', 'typescript-operations', 'typescript-compatibility'],
|
package/src/bin/gqm/settings.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
2
2
|
import { dirname } from 'path';
|
|
3
3
|
import { readLine } from './readline';
|
|
4
|
-
import {
|
|
4
|
+
import { EMPTY_MODELS } from './templates';
|
|
5
5
|
|
|
6
6
|
const SETTINGS_PATH = '.gqmrc.json';
|
|
7
7
|
|
|
@@ -21,15 +21,19 @@ const DEFAULTS = {
|
|
|
21
21
|
ensureFileExists(`${path}/db/.gitkeep`, '');
|
|
22
22
|
ensureFileExists(`${path}/api/.gitkeep`, '');
|
|
23
23
|
ensureFileExists(`${path}/client/.gitkeep`, '');
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
graphqlQueriesPath: {
|
|
27
|
+
question: 'Where to look for graphql queries?',
|
|
28
|
+
defaultValue: 'src/graphql/client/queries',
|
|
29
|
+
init: (path: string) => {
|
|
30
|
+
ensureDirectoryExists(path);
|
|
26
31
|
},
|
|
27
32
|
},
|
|
28
33
|
};
|
|
29
34
|
|
|
30
35
|
type Settings = {
|
|
31
|
-
|
|
32
|
-
generatedFolderPath: string;
|
|
36
|
+
[key in keyof typeof DEFAULTS]: string;
|
|
33
37
|
};
|
|
34
38
|
|
|
35
39
|
const initSetting = async (name: string) => {
|
|
@@ -67,9 +71,7 @@ export const getSetting = async (name: keyof Settings): Promise<string> => {
|
|
|
67
71
|
return settings[name];
|
|
68
72
|
};
|
|
69
73
|
|
|
70
|
-
const ensureDirectoryExists = (
|
|
71
|
-
const dir = dirname(filePath);
|
|
72
|
-
|
|
74
|
+
const ensureDirectoryExists = (dir: string) => {
|
|
73
75
|
if (existsSync(dir)) {
|
|
74
76
|
return true;
|
|
75
77
|
}
|
|
@@ -77,6 +79,7 @@ const ensureDirectoryExists = (filePath: string) => {
|
|
|
77
79
|
ensureDirectoryExists(dir);
|
|
78
80
|
|
|
79
81
|
try {
|
|
82
|
+
console.info(`Creating directory ${dir}`);
|
|
80
83
|
mkdirSync(dir);
|
|
81
84
|
return true;
|
|
82
85
|
} catch (err) {
|
|
@@ -90,13 +93,13 @@ const ensureDirectoryExists = (filePath: string) => {
|
|
|
90
93
|
export const ensureFileExists = (filePath: string, content: string) => {
|
|
91
94
|
if (!existsSync(filePath)) {
|
|
92
95
|
console.info(`Creating ${filePath}`);
|
|
93
|
-
ensureDirectoryExists(filePath);
|
|
96
|
+
ensureDirectoryExists(dirname(filePath));
|
|
94
97
|
writeFileSync(filePath, content);
|
|
95
98
|
}
|
|
96
99
|
};
|
|
97
100
|
|
|
98
101
|
export const writeToFile = (filePath: string, content: string) => {
|
|
99
|
-
ensureDirectoryExists(filePath);
|
|
102
|
+
ensureDirectoryExists(dirname(filePath));
|
|
100
103
|
if (existsSync(filePath)) {
|
|
101
104
|
const currentContent = readFileSync(filePath, 'utf-8');
|
|
102
105
|
if (content === currentContent) {
|
|
@@ -13,10 +13,10 @@ import {
|
|
|
13
13
|
} from 'ts-morph';
|
|
14
14
|
import { Visitor, visit } from './visitor';
|
|
15
15
|
|
|
16
|
-
export const staticEval = (node: Node, context: Dictionary<unknown>) =>
|
|
17
|
-
visit<unknown, Dictionary<unknown>>(node, context,
|
|
16
|
+
export const staticEval = (node: Node | undefined, context: Dictionary<unknown>) =>
|
|
17
|
+
visit<unknown, Dictionary<unknown>>(node, context, VISITOR);
|
|
18
18
|
|
|
19
|
-
const
|
|
19
|
+
const VISITOR: Visitor<unknown, Dictionary<unknown>> = {
|
|
20
20
|
undefined: () => undefined,
|
|
21
21
|
[SyntaxKind.VariableDeclaration]: (node, context) => staticEval(node.getInitializer(), context),
|
|
22
22
|
[SyntaxKind.ArrayLiteralExpression]: (node, context) => {
|
|
@@ -52,6 +52,8 @@ const visitor: Visitor<unknown, Dictionary<unknown>> = {
|
|
|
52
52
|
return undefined;
|
|
53
53
|
case 'process':
|
|
54
54
|
return process;
|
|
55
|
+
case 'Symbol':
|
|
56
|
+
return Symbol;
|
|
55
57
|
}
|
|
56
58
|
const definitionNodes = node.getDefinitionNodes();
|
|
57
59
|
if (!definitionNodes.length) {
|
|
@@ -68,6 +70,7 @@ const visitor: Visitor<unknown, Dictionary<unknown>> = {
|
|
|
68
70
|
[SyntaxKind.TrueKeyword]: () => true,
|
|
69
71
|
[SyntaxKind.FalseKeyword]: () => false,
|
|
70
72
|
[SyntaxKind.NumericLiteral]: (node) => node.getLiteralValue(),
|
|
73
|
+
[SyntaxKind.BigIntLiteral]: (node) => node.getLiteralValue(),
|
|
71
74
|
[SyntaxKind.CallExpression]: (node, context) => {
|
|
72
75
|
const method = staticEval(node.getExpression(), context) as (...args: unknown[]) => unknown;
|
|
73
76
|
const args = node.getArguments().map((arg) => staticEval(arg, context));
|
|
@@ -200,4 +203,5 @@ const visitor: Visitor<unknown, Dictionary<unknown>> = {
|
|
|
200
203
|
return target[argument];
|
|
201
204
|
},
|
|
202
205
|
[SyntaxKind.NoSubstitutionTemplateLiteral]: (node) => node.getLiteralValue(),
|
|
206
|
+
[SyntaxKind.NullKeyword]: () => null,
|
|
203
207
|
};
|
package/src/bin/gqm/templates.ts
CHANGED
|
@@ -12,43 +12,6 @@ export const rawModels: RawModels = [
|
|
|
12
12
|
export const models = getModels(rawModels);
|
|
13
13
|
`;
|
|
14
14
|
|
|
15
|
-
export const GRAPHQL_CODEGEN = (path: string) => `
|
|
16
|
-
overwrite: true
|
|
17
|
-
schema: '${path}/schema.graphql'
|
|
18
|
-
documents: null
|
|
19
|
-
generates:
|
|
20
|
-
${path}/api/index.ts:
|
|
21
|
-
plugins:
|
|
22
|
-
- 'typescript'
|
|
23
|
-
- 'typescript-resolvers'
|
|
24
|
-
- add:
|
|
25
|
-
content: "import { DateTime } from 'luxon'"
|
|
26
|
-
config:
|
|
27
|
-
scalars:
|
|
28
|
-
DateTime: DateTime
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
export const CLIENT_CODEGEN = (path: string) => `
|
|
32
|
-
schema: ${path}/schema.graphql
|
|
33
|
-
documents: [ './src/**/*.ts', './src/**/*.tsx' ]
|
|
34
|
-
generates:
|
|
35
|
-
${path}/client/index.ts:
|
|
36
|
-
plugins:
|
|
37
|
-
- typescript
|
|
38
|
-
- typescript-operations
|
|
39
|
-
- typescript-compatibility
|
|
40
|
-
|
|
41
|
-
config:
|
|
42
|
-
preResolveTypes: true # Simplifies the generated types
|
|
43
|
-
namingConvention: keep # Keeps naming as-is
|
|
44
|
-
nonOptionalTypename: true # Forces \`__typename\` on all selection sets
|
|
45
|
-
skipTypeNameForRoot: true # Don't generate __typename for root types
|
|
46
|
-
avoidOptionals: # Avoids optionals on the level of the field
|
|
47
|
-
field: true
|
|
48
|
-
scalars:
|
|
49
|
-
DateTime: string
|
|
50
|
-
`;
|
|
51
|
-
|
|
52
15
|
export const KNEXFILE = `
|
|
53
16
|
const config = {
|
|
54
17
|
client: 'postgresql',
|
package/src/bin/gqm/visitor.ts
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ImplementedKindToNodeMappings, Node, SyntaxKind } from 'ts-morph';
|
|
2
2
|
import { get } from '../..';
|
|
3
3
|
|
|
4
4
|
export type Visitor<T, C> = {
|
|
5
5
|
undefined?: () => T;
|
|
6
6
|
unknown?: (node: Node) => T;
|
|
7
7
|
} & {
|
|
8
|
-
[kind in keyof
|
|
8
|
+
[kind in keyof ImplementedKindToNodeMappings]?: (node: ImplementedKindToNodeMappings[kind], context: C) => T;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export const visit = <T, C>(node: Node | undefined, context: C, visitor: Visitor<T, C>) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
if (!node) {
|
|
13
|
+
if (visitor.undefined) {
|
|
14
|
+
return visitor.undefined();
|
|
15
|
+
}
|
|
16
|
+
console.trace();
|
|
17
|
+
throw new Error(`Cannot handle undefined node.`);
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
const kind = node.getKind();
|
|
21
|
+
const func = visitor[kind];
|
|
22
|
+
if (func) {
|
|
23
|
+
return func(node, context);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (visitor.unknown) {
|
|
18
27
|
return visitor.unknown(node);
|
|
19
28
|
}
|
|
20
29
|
|
|
21
30
|
console.error(node.getText());
|
|
22
|
-
console.error(node.getParent().getText());
|
|
23
31
|
throw new Error(
|
|
24
32
|
`Cannot handle kind ${get(
|
|
25
33
|
Object.entries(SyntaxKind).find(([, val]) => val === kind),
|
package/src/schema/utils.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
ValueNode,
|
|
23
23
|
} from 'graphql';
|
|
24
24
|
import { DateTime } from 'luxon';
|
|
25
|
-
import { Directive,
|
|
25
|
+
import { Directive, Value, Values } from '../values';
|
|
26
26
|
|
|
27
27
|
export type Field = {
|
|
28
28
|
name: string;
|
|
@@ -206,10 +206,10 @@ export const value = (val: Value = null): ValueNode =>
|
|
|
206
206
|
kind: 'StringValue',
|
|
207
207
|
value: val,
|
|
208
208
|
}
|
|
209
|
-
: val instanceof
|
|
209
|
+
: val instanceof Symbol
|
|
210
210
|
? {
|
|
211
211
|
kind: 'EnumValue',
|
|
212
|
-
value: val.
|
|
212
|
+
value: val.description,
|
|
213
213
|
}
|
|
214
214
|
: Array.isArray(val)
|
|
215
215
|
? {
|
package/src/values.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { DateTime } from 'luxon';
|
|
2
2
|
|
|
3
|
-
export class Enum {
|
|
4
|
-
constructor(public value: string) {}
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
export type BasicValue = undefined | null | boolean | string | number | DateTime;
|
|
8
4
|
|
|
9
|
-
export type Value = any; // BasicValue |
|
|
5
|
+
export type Value = any; // BasicValue | Symbol | Symbol[] | Record<string, Value> | Value[];
|
|
10
6
|
|
|
11
7
|
export type Values = {
|
|
12
8
|
name: string;
|