@smartive/graphql-magic 9.0.0 → 9.1.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.
- package/CHANGELOG.md +6 -1
- package/dist/bin/gqm.cjs +14 -43
- 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/templates.ts +0 -37
package/CHANGELOG.md
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
## [9.1.1](https://github.com/smartive/graphql-magic/compare/v9.1.0...v9.1.1) (2023-09-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Codegen mutations ([#62](https://github.com/smartive/graphql-magic/issues/62)) ([ea87f2b](https://github.com/smartive/graphql-magic/commit/ea87f2ba5fb4540450a8ebd52a35fff40b0a1a3a))
|
package/dist/bin/gqm.cjs
CHANGED
|
@@ -1279,41 +1279,6 @@ export const rawModels: RawModels = [
|
|
|
1279
1279
|
|
|
1280
1280
|
export const models = getModels(rawModels);
|
|
1281
1281
|
`;
|
|
1282
|
-
var GRAPHQL_CODEGEN = (path) => `
|
|
1283
|
-
overwrite: true
|
|
1284
|
-
schema: '${path}/schema.graphql'
|
|
1285
|
-
documents: null
|
|
1286
|
-
generates:
|
|
1287
|
-
${path}/api/index.ts:
|
|
1288
|
-
plugins:
|
|
1289
|
-
- 'typescript'
|
|
1290
|
-
- 'typescript-resolvers'
|
|
1291
|
-
- add:
|
|
1292
|
-
content: "import { DateTime } from 'luxon'"
|
|
1293
|
-
config:
|
|
1294
|
-
scalars:
|
|
1295
|
-
DateTime: DateTime
|
|
1296
|
-
`;
|
|
1297
|
-
var CLIENT_CODEGEN = (path) => `
|
|
1298
|
-
schema: ${path}/schema.graphql
|
|
1299
|
-
documents: [ './src/**/*.ts', './src/**/*.tsx' ]
|
|
1300
|
-
generates:
|
|
1301
|
-
${path}/client/index.ts:
|
|
1302
|
-
plugins:
|
|
1303
|
-
- typescript
|
|
1304
|
-
- typescript-operations
|
|
1305
|
-
- typescript-compatibility
|
|
1306
|
-
|
|
1307
|
-
config:
|
|
1308
|
-
preResolveTypes: true # Simplifies the generated types
|
|
1309
|
-
namingConvention: keep # Keeps naming as-is
|
|
1310
|
-
nonOptionalTypename: true # Forces \`__typename\` on all selection sets
|
|
1311
|
-
skipTypeNameForRoot: true # Don't generate __typename for root types
|
|
1312
|
-
avoidOptionals: # Avoids optionals on the level of the field
|
|
1313
|
-
field: true
|
|
1314
|
-
scalars:
|
|
1315
|
-
DateTime: string
|
|
1316
|
-
`;
|
|
1317
1282
|
var KNEXFILE = `
|
|
1318
1283
|
const config = {
|
|
1319
1284
|
client: 'postgresql',
|
|
@@ -1346,8 +1311,13 @@ var DEFAULTS = {
|
|
|
1346
1311
|
ensureFileExists(`${path}/db/.gitkeep`, "");
|
|
1347
1312
|
ensureFileExists(`${path}/api/.gitkeep`, "");
|
|
1348
1313
|
ensureFileExists(`${path}/client/.gitkeep`, "");
|
|
1349
|
-
|
|
1350
|
-
|
|
1314
|
+
}
|
|
1315
|
+
},
|
|
1316
|
+
graphqlQueriesPath: {
|
|
1317
|
+
question: "Where to look for graphql queries?",
|
|
1318
|
+
defaultValue: "src/graphql/client/queries",
|
|
1319
|
+
init: (path) => {
|
|
1320
|
+
ensureDirectoryExists(path);
|
|
1351
1321
|
}
|
|
1352
1322
|
}
|
|
1353
1323
|
};
|
|
@@ -1381,13 +1351,13 @@ var getSetting = async (name2) => {
|
|
|
1381
1351
|
}
|
|
1382
1352
|
return settings[name2];
|
|
1383
1353
|
};
|
|
1384
|
-
var ensureDirectoryExists = (
|
|
1385
|
-
const dir = (0, import_path.dirname)(filePath);
|
|
1354
|
+
var ensureDirectoryExists = (dir) => {
|
|
1386
1355
|
if ((0, import_fs.existsSync)(dir)) {
|
|
1387
1356
|
return true;
|
|
1388
1357
|
}
|
|
1389
1358
|
ensureDirectoryExists(dir);
|
|
1390
1359
|
try {
|
|
1360
|
+
console.info(`Creating directory ${dir}`);
|
|
1391
1361
|
(0, import_fs.mkdirSync)(dir);
|
|
1392
1362
|
return true;
|
|
1393
1363
|
} catch (err) {
|
|
@@ -1400,12 +1370,12 @@ var ensureDirectoryExists = (filePath) => {
|
|
|
1400
1370
|
var ensureFileExists = (filePath, content) => {
|
|
1401
1371
|
if (!(0, import_fs.existsSync)(filePath)) {
|
|
1402
1372
|
console.info(`Creating ${filePath}`);
|
|
1403
|
-
ensureDirectoryExists(filePath);
|
|
1373
|
+
ensureDirectoryExists((0, import_path.dirname)(filePath));
|
|
1404
1374
|
(0, import_fs.writeFileSync)(filePath, content);
|
|
1405
1375
|
}
|
|
1406
1376
|
};
|
|
1407
1377
|
var writeToFile = (filePath, content) => {
|
|
1408
|
-
ensureDirectoryExists(filePath);
|
|
1378
|
+
ensureDirectoryExists((0, import_path.dirname)(filePath));
|
|
1409
1379
|
if ((0, import_fs.existsSync)(filePath)) {
|
|
1410
1380
|
const currentContent = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
1411
1381
|
if (content === currentContent) {
|
|
@@ -1425,7 +1395,7 @@ var generateGraphqlApiTypes = async () => {
|
|
|
1425
1395
|
await (0, import_cli.generate)({
|
|
1426
1396
|
overwrite: true,
|
|
1427
1397
|
schema: `${generatedFolderPath}/schema.graphql`,
|
|
1428
|
-
documents:
|
|
1398
|
+
documents: void 0,
|
|
1429
1399
|
generates: {
|
|
1430
1400
|
[`${generatedFolderPath}/api/index.ts`]: {
|
|
1431
1401
|
plugins: ["typescript", "typescript-resolvers", { add: { content: `import { DateTime } from 'luxon';` } }]
|
|
@@ -1440,9 +1410,10 @@ var generateGraphqlApiTypes = async () => {
|
|
|
1440
1410
|
};
|
|
1441
1411
|
var generateGraphqlClientTypes = async () => {
|
|
1442
1412
|
const generatedFolderPath = await getSetting("generatedFolderPath");
|
|
1413
|
+
const graphqlQueriesPath = await getSetting("graphqlQueriesPath");
|
|
1443
1414
|
await (0, import_cli.generate)({
|
|
1444
1415
|
schema: `${generatedFolderPath}/schema.graphql`,
|
|
1445
|
-
documents: [
|
|
1416
|
+
documents: [graphqlQueriesPath, `${generatedFolderPath}/client/mutations.ts`],
|
|
1446
1417
|
generates: {
|
|
1447
1418
|
[`${generatedFolderPath}/client/index.ts`]: {
|
|
1448
1419
|
plugins: ["typescript", "typescript-operations", "typescript-compatibility"]
|
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, `${generatedFolderPath}/client/mutations.ts`],
|
|
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) {
|
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',
|