@toptal/davinci-graphql-codegen 0.4.0 → 0.4.2-alpha-chore-improve-packages-building-4fb91e1f.10
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/davinci-graphql-codegen.js +2 -2
- package/dist/commands/generate-operations.d.ts +9 -0
- package/dist/commands/generate-operations.js +117 -0
- package/dist/commands/generate-schema.d.ts +9 -0
- package/dist/commands/generate-schema.js +117 -0
- package/dist/config/config.d.ts +33 -0
- package/dist/config/config.js +47 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +3 -0
- package/dist/generate/index.d.ts +3 -0
- package/dist/generate/index.js +4 -0
- package/dist/generate/operations.d.ts +7 -0
- package/dist/generate/operations.js +134 -0
- package/dist/generate/schema.d.ts +6 -0
- package/dist/generate/schema.js +132 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +8 -0
- package/dist/read-config/index.d.ts +2 -0
- package/dist/read-config/index.js +3 -0
- package/dist/read-config/read-config.d.ts +2 -0
- package/dist/read-config/read-config.js +62 -0
- package/dist/services/get-monolith-schema-path.d.ts +6 -0
- package/dist/services/get-monolith-schema-path.js +7 -0
- package/dist/services/get-monorepo-schema-path.d.ts +6 -0
- package/dist/services/get-monorepo-schema-path.js +10 -0
- package/dist/services/get-schema-path.d.ts +6 -0
- package/dist/services/get-schema-path.js +10 -0
- package/dist/services/gs-schema-loader.d.ts +2 -0
- package/dist/services/gs-schema-loader.js +60 -0
- package/dist/services/schema-loader.d.ts +5 -0
- package/dist/services/schema-loader.js +76 -0
- package/dist/utils/detect-schema-source.d.ts +3 -0
- package/dist/utils/detect-schema-source.js +15 -0
- package/dist/utils/get-relative-file-path.d.ts +2 -0
- package/dist/utils/get-relative-file-path.js +5 -0
- package/dist/utils/parse-gs-uri.d.ts +5 -0
- package/dist/utils/parse-gs-uri.js +14 -0
- package/dist/utils/process-args.d.ts +2 -0
- package/dist/utils/process-args.js +17 -0
- package/dist/utils/to-array.d.ts +2 -0
- package/dist/utils/to-array.js +8 -0
- package/package.json +14 -9
- package/CHANGELOG.md +0 -252
- package/dist-package/package.json +0 -43
- package/esbuild.js +0 -16
- package/src/commands/generate-operations.js +0 -43
- package/src/commands/generate-schema.js +0 -39
- package/src/config/config.js +0 -50
- package/src/config/index.js +0 -3
- package/src/generate/index.js +0 -4
- package/src/generate/operations.js +0 -68
- package/src/generate/schema.js +0 -67
- package/src/index.js +0 -8
- package/src/read-config/index.js +0 -3
- package/src/read-config/read-config.js +0 -33
- package/src/services/get-monolith-schema-path.js +0 -11
- package/src/services/get-monorepo-schema-path.js +0 -14
- package/src/services/get-schema-path.js +0 -14
- package/src/services/get-schema-path.test.js +0 -71
- package/src/services/gs-schema-loader.js +0 -20
- package/src/services/schema-loader.js +0 -44
- package/src/utils/detect-schema-source.js +0 -17
- package/src/utils/detect-schema-source.test.js +0 -29
- package/src/utils/get-relative-file-path.js +0 -5
- package/src/utils/parse-gs-uri.js +0 -16
- package/src/utils/parse-gs-uri.test.js +0 -12
- package/src/utils/process-args.js +0 -22
- package/src/utils/process-args.test.js +0 -10
- package/src/utils/to-array.js +0 -9
- package/src/utils/to-array.test.js +0 -15
- package/tsconfig.json +0 -8
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const cliEngine = require('@toptal/davinci-cli-shared')
|
|
4
4
|
|
|
5
|
-
const codegenGenerateSchemaCreator = require('../
|
|
6
|
-
const codegenGenerateOperationsCreator = require('../
|
|
5
|
+
const codegenGenerateSchemaCreator = require('../dist/commands/generate-schema')
|
|
6
|
+
const codegenGenerateOperationsCreator = require('../dist/commands/generate-operations')
|
|
7
7
|
|
|
8
8
|
cliEngine.loadCommands(
|
|
9
9
|
[codegenGenerateSchemaCreator, codegenGenerateOperationsCreator],
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
39
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
40
|
+
var m = o[Symbol.asyncIterator], i;
|
|
41
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
42
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
43
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
44
|
+
};
|
|
45
|
+
var chalk = require('chalk');
|
|
46
|
+
var generateOperations = require('../generate').generateOperations;
|
|
47
|
+
var readConfig = require('../read-config');
|
|
48
|
+
var codegenGenerateOperations = function (_a) {
|
|
49
|
+
var config = _a.config, _b = _a.extension, extension = _b === void 0 ? '.ts' : _b;
|
|
50
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
51
|
+
var codegen, codegen_1, codegen_1_1, _c, schema, documents, _d, customConfig, e_1_1;
|
|
52
|
+
var e_1, _e;
|
|
53
|
+
return __generator(this, function (_f) {
|
|
54
|
+
switch (_f.label) {
|
|
55
|
+
case 0: return [4 /*yield*/, readConfig(config)];
|
|
56
|
+
case 1:
|
|
57
|
+
codegen = _f.sent();
|
|
58
|
+
_f.label = 2;
|
|
59
|
+
case 2:
|
|
60
|
+
_f.trys.push([2, 8, 9, 14]);
|
|
61
|
+
codegen_1 = __asyncValues(codegen);
|
|
62
|
+
_f.label = 3;
|
|
63
|
+
case 3: return [4 /*yield*/, codegen_1.next()];
|
|
64
|
+
case 4:
|
|
65
|
+
if (!(codegen_1_1 = _f.sent(), !codegen_1_1.done)) return [3 /*break*/, 7];
|
|
66
|
+
_c = codegen_1_1.value, schema = _c.schema, documents = _c.documents, _d = _c.config, customConfig = _d === void 0 ? {} : _d;
|
|
67
|
+
return [4 /*yield*/, generateOperations({
|
|
68
|
+
schema: schema,
|
|
69
|
+
documents: documents,
|
|
70
|
+
extension: extension,
|
|
71
|
+
config: customConfig,
|
|
72
|
+
})];
|
|
73
|
+
case 5:
|
|
74
|
+
_f.sent();
|
|
75
|
+
_f.label = 6;
|
|
76
|
+
case 6: return [3 /*break*/, 3];
|
|
77
|
+
case 7: return [3 /*break*/, 14];
|
|
78
|
+
case 8:
|
|
79
|
+
e_1_1 = _f.sent();
|
|
80
|
+
e_1 = { error: e_1_1 };
|
|
81
|
+
return [3 /*break*/, 14];
|
|
82
|
+
case 9:
|
|
83
|
+
_f.trys.push([9, , 12, 13]);
|
|
84
|
+
if (!(codegen_1_1 && !codegen_1_1.done && (_e = codegen_1.return))) return [3 /*break*/, 11];
|
|
85
|
+
return [4 /*yield*/, _e.call(codegen_1)];
|
|
86
|
+
case 10:
|
|
87
|
+
_f.sent();
|
|
88
|
+
_f.label = 11;
|
|
89
|
+
case 11: return [3 /*break*/, 13];
|
|
90
|
+
case 12:
|
|
91
|
+
if (e_1) throw e_1.error;
|
|
92
|
+
return [7 /*endfinally*/];
|
|
93
|
+
case 13: return [7 /*endfinally*/];
|
|
94
|
+
case 14: return [2 /*return*/];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
var codegenGenerateOperationsCreator = {
|
|
100
|
+
command: 'generate-operations',
|
|
101
|
+
description: 'generate graphql operation types based off generated schemas',
|
|
102
|
+
options: [
|
|
103
|
+
{
|
|
104
|
+
label: "Path to your custom ".concat(chalk.green('codegen.json'), " config file"),
|
|
105
|
+
name: '--config <config-path>',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
label: "Custom extension that generated files will have. Defaults to ".concat(chalk.green('.ts')),
|
|
109
|
+
name: '--extension <extension>',
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
action: function (_a) {
|
|
113
|
+
var options = _a.options;
|
|
114
|
+
return codegenGenerateOperations(options);
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
module.exports = codegenGenerateOperationsCreator;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
39
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
40
|
+
var m = o[Symbol.asyncIterator], i;
|
|
41
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
42
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
43
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
44
|
+
};
|
|
45
|
+
var chalk = require('chalk');
|
|
46
|
+
var generateSchema = require('../generate').generateSchema;
|
|
47
|
+
var readConfig = require('../read-config');
|
|
48
|
+
var codegenGenerateSchema = function (_a) {
|
|
49
|
+
var _b = _a.projectId, projectId = _b === void 0 ? 'toptal-hub' : _b, config = _a.config;
|
|
50
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
51
|
+
var codegen, codegen_1, codegen_1_1, _c, schema, documents, target, e_1_1;
|
|
52
|
+
var e_1, _d;
|
|
53
|
+
return __generator(this, function (_e) {
|
|
54
|
+
switch (_e.label) {
|
|
55
|
+
case 0: return [4 /*yield*/, readConfig(config)];
|
|
56
|
+
case 1:
|
|
57
|
+
codegen = _e.sent();
|
|
58
|
+
_e.label = 2;
|
|
59
|
+
case 2:
|
|
60
|
+
_e.trys.push([2, 8, 9, 14]);
|
|
61
|
+
codegen_1 = __asyncValues(codegen);
|
|
62
|
+
_e.label = 3;
|
|
63
|
+
case 3: return [4 /*yield*/, codegen_1.next()];
|
|
64
|
+
case 4:
|
|
65
|
+
if (!(codegen_1_1 = _e.sent(), !codegen_1_1.done)) return [3 /*break*/, 7];
|
|
66
|
+
_c = codegen_1_1.value, schema = _c.schema, documents = _c.documents, target = _c.target;
|
|
67
|
+
return [4 /*yield*/, generateSchema({
|
|
68
|
+
schema: schema,
|
|
69
|
+
documents: documents,
|
|
70
|
+
target: target,
|
|
71
|
+
projectId: projectId,
|
|
72
|
+
})];
|
|
73
|
+
case 5:
|
|
74
|
+
_e.sent();
|
|
75
|
+
_e.label = 6;
|
|
76
|
+
case 6: return [3 /*break*/, 3];
|
|
77
|
+
case 7: return [3 /*break*/, 14];
|
|
78
|
+
case 8:
|
|
79
|
+
e_1_1 = _e.sent();
|
|
80
|
+
e_1 = { error: e_1_1 };
|
|
81
|
+
return [3 /*break*/, 14];
|
|
82
|
+
case 9:
|
|
83
|
+
_e.trys.push([9, , 12, 13]);
|
|
84
|
+
if (!(codegen_1_1 && !codegen_1_1.done && (_d = codegen_1.return))) return [3 /*break*/, 11];
|
|
85
|
+
return [4 /*yield*/, _d.call(codegen_1)];
|
|
86
|
+
case 10:
|
|
87
|
+
_e.sent();
|
|
88
|
+
_e.label = 11;
|
|
89
|
+
case 11: return [3 /*break*/, 13];
|
|
90
|
+
case 12:
|
|
91
|
+
if (e_1) throw e_1.error;
|
|
92
|
+
return [7 /*endfinally*/];
|
|
93
|
+
case 13: return [7 /*endfinally*/];
|
|
94
|
+
case 14: return [2 /*return*/];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
var codegenGenerateSchemaCreator = {
|
|
100
|
+
command: 'generate-schema',
|
|
101
|
+
description: 'generate graphql schemas',
|
|
102
|
+
options: [
|
|
103
|
+
{
|
|
104
|
+
label: "roject ID inside Google Storage Bucket. Defaults to ".concat(chalk.green('toptal-hub')),
|
|
105
|
+
name: '--projectId <id>',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
label: "Path to your custom ".concat(chalk.green('codegen.json'), " config file"),
|
|
109
|
+
name: '--config <file-path>',
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
action: function (_a) {
|
|
113
|
+
var options = _a.options;
|
|
114
|
+
return codegenGenerateSchema(options);
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
module.exports = codegenGenerateSchemaCreator;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export namespace commonOperationTypesConfig {
|
|
2
|
+
const dedupeFragments: boolean;
|
|
3
|
+
const skipTypename: boolean;
|
|
4
|
+
const exportFragmentSpreadSubTypes: boolean;
|
|
5
|
+
namespace avoidOptionals {
|
|
6
|
+
const field: boolean;
|
|
7
|
+
const inputValue: boolean;
|
|
8
|
+
const object: boolean;
|
|
9
|
+
}
|
|
10
|
+
namespace namingConvention {
|
|
11
|
+
const enumValues: string;
|
|
12
|
+
}
|
|
13
|
+
namespace scalars {
|
|
14
|
+
const BigDecimal: string;
|
|
15
|
+
const Date: string;
|
|
16
|
+
const ISO8601Date: string;
|
|
17
|
+
const ISO8601DateTime: string;
|
|
18
|
+
const JobTypeEnum: string;
|
|
19
|
+
const JSON: string;
|
|
20
|
+
const PageSize: string;
|
|
21
|
+
const Time: string;
|
|
22
|
+
const TimeOfDay: string;
|
|
23
|
+
const Upload: string;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export namespace commonSchemaTypesConfig {
|
|
27
|
+
const resolverTypeWrapperSignature: string;
|
|
28
|
+
const allowParentTypeOverride: boolean;
|
|
29
|
+
const noSchemaStitching: boolean;
|
|
30
|
+
const optionalInfoArgument: boolean;
|
|
31
|
+
const optionalResolveType: boolean;
|
|
32
|
+
}
|
|
33
|
+
export const autoGenerationComments: string[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var commonTypesConfig = {
|
|
14
|
+
skipTypename: true,
|
|
15
|
+
exportFragmentSpreadSubTypes: true,
|
|
16
|
+
avoidOptionals: {
|
|
17
|
+
field: true,
|
|
18
|
+
inputValue: false,
|
|
19
|
+
object: true,
|
|
20
|
+
},
|
|
21
|
+
namingConvention: {
|
|
22
|
+
enumValues: 'upper-case#upperCase',
|
|
23
|
+
},
|
|
24
|
+
scalars: {
|
|
25
|
+
BigDecimal: 'string',
|
|
26
|
+
Date: 'string',
|
|
27
|
+
ISO8601Date: 'string',
|
|
28
|
+
ISO8601DateTime: 'string',
|
|
29
|
+
JobTypeEnum: 'string',
|
|
30
|
+
JSON: 'string',
|
|
31
|
+
PageSize: 'number',
|
|
32
|
+
Time: 'string',
|
|
33
|
+
TimeOfDay: 'string',
|
|
34
|
+
Upload: 'unknown',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
var commonSchemaTypesConfig = __assign(__assign({}, commonTypesConfig), { resolverTypeWrapperSignature: '(parent: unknown, args: any) => ({ [K in keyof Partial<T>]: TypeOrMockList<T[K]> }) | null', allowParentTypeOverride: false, noSchemaStitching: true, optionalInfoArgument: true, optionalResolveType: true });
|
|
38
|
+
var commonOperationTypesConfig = __assign(__assign({}, commonTypesConfig), { dedupeFragments: true });
|
|
39
|
+
var autoGenerationComments = [
|
|
40
|
+
'/* eslint-disable */',
|
|
41
|
+
'/* ⚠️ THIS IS AN AUTOGENERATED FILE, DO NOT EDIT ⚠️ */',
|
|
42
|
+
];
|
|
43
|
+
module.exports = {
|
|
44
|
+
commonOperationTypesConfig: commonOperationTypesConfig,
|
|
45
|
+
commonSchemaTypesConfig: commonSchemaTypesConfig,
|
|
46
|
+
autoGenerationComments: autoGenerationComments,
|
|
47
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var chalk = require('chalk');
|
|
50
|
+
var generate = require('@graphql-codegen/cli').generate;
|
|
51
|
+
var _a = require('fs-extra'), readFileSync = _a.readFileSync, writeFileSync = _a.writeFileSync;
|
|
52
|
+
var prettier = require('prettier');
|
|
53
|
+
var dirname = require('path').dirname;
|
|
54
|
+
var merge = require('deepmerge');
|
|
55
|
+
var _b = require('../config/config'), commonOperationTypesConfig = _b.commonOperationTypesConfig, autoGenerationComments = _b.autoGenerationComments;
|
|
56
|
+
var getSchemaPath = require('../services/get-schema-path');
|
|
57
|
+
var getRelativeFilePath = require('../utils/get-relative-file-path');
|
|
58
|
+
var generateOperations = function (_a) {
|
|
59
|
+
var schema = _a.schema, documents = _a.documents, extension = _a.extension, config = _a.config;
|
|
60
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
61
|
+
var docsPath, _b, target, schemaPath, schemaPathResolution;
|
|
62
|
+
var _c;
|
|
63
|
+
return __generator(this, function (_d) {
|
|
64
|
+
switch (_d.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
docsPath = getRelativeFilePath(documents);
|
|
67
|
+
_b = getSchemaPath(schema), target = _b.target, schemaPath = _b.schemaPath, schemaPathResolution = _b.schemaPathResolution;
|
|
68
|
+
console.log("\u2139\uFE0F Generating [".concat(chalk.green(target), "] operations"));
|
|
69
|
+
console.log("\u2139\uFE0F Documents pattern: [".concat(chalk.green(documents), "]"));
|
|
70
|
+
return [4 /*yield*/, generate({
|
|
71
|
+
documents: docsPath,
|
|
72
|
+
config: merge(commonOperationTypesConfig, config),
|
|
73
|
+
generates: (_c = {},
|
|
74
|
+
_c[schemaPath] = {
|
|
75
|
+
schema: schemaPathResolution,
|
|
76
|
+
preset: 'near-operation-file',
|
|
77
|
+
presetConfig: {
|
|
78
|
+
extension: extension,
|
|
79
|
+
baseTypesPath: "~".concat(schema, "/schema"),
|
|
80
|
+
},
|
|
81
|
+
plugins: [
|
|
82
|
+
'typescript-operations',
|
|
83
|
+
'typed-document-node',
|
|
84
|
+
{
|
|
85
|
+
add: {
|
|
86
|
+
content: autoGenerationComments,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
_c),
|
|
92
|
+
hooks: {
|
|
93
|
+
afterAllFileWrite: [
|
|
94
|
+
function () {
|
|
95
|
+
var filePaths = [];
|
|
96
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
97
|
+
filePaths[_i] = arguments[_i];
|
|
98
|
+
}
|
|
99
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
100
|
+
var _a, filePaths_1, path, rawText, options, formattedText;
|
|
101
|
+
return __generator(this, function (_b) {
|
|
102
|
+
switch (_b.label) {
|
|
103
|
+
case 0:
|
|
104
|
+
_a = 0, filePaths_1 = filePaths;
|
|
105
|
+
_b.label = 1;
|
|
106
|
+
case 1:
|
|
107
|
+
if (!(_a < filePaths_1.length)) return [3 /*break*/, 4];
|
|
108
|
+
path = filePaths_1[_a];
|
|
109
|
+
rawText = readFileSync(path, 'utf8');
|
|
110
|
+
return [4 /*yield*/, prettier.resolveConfig(dirname(path))];
|
|
111
|
+
case 2:
|
|
112
|
+
options = _b.sent();
|
|
113
|
+
formattedText = prettier.format(rawText, __assign({ parser: 'typescript' }, options));
|
|
114
|
+
writeFileSync(path, formattedText);
|
|
115
|
+
_b.label = 3;
|
|
116
|
+
case 3:
|
|
117
|
+
_a++;
|
|
118
|
+
return [3 /*break*/, 1];
|
|
119
|
+
case 4: return [2 /*return*/];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
}, true)];
|
|
127
|
+
case 1:
|
|
128
|
+
_d.sent();
|
|
129
|
+
return [2 /*return*/];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
module.exports = generateOperations;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var generate = require('@graphql-codegen/cli').generate;
|
|
50
|
+
var chalk = require('chalk');
|
|
51
|
+
var _a = require('fs'), readFileSync = _a.readFileSync, writeFileSync = _a.writeFileSync;
|
|
52
|
+
var prettier = require('prettier');
|
|
53
|
+
var dirname = require('path').dirname;
|
|
54
|
+
var _b = require('../config/config'), commonSchemaTypesConfig = _b.commonSchemaTypesConfig, autoGenerationComments = _b.autoGenerationComments;
|
|
55
|
+
var schemaLoader = require('../services/schema-loader');
|
|
56
|
+
var isSchemaFromHttp = require('../utils/detect-schema-source').isSchemaFromHttp;
|
|
57
|
+
var generateSchema = function (_a) {
|
|
58
|
+
var schema = _a.schema, target = _a.target, projectId = _a.projectId;
|
|
59
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
+
var _b, schemaPath, destinationPathTs;
|
|
61
|
+
var _c;
|
|
62
|
+
return __generator(this, function (_d) {
|
|
63
|
+
switch (_d.label) {
|
|
64
|
+
case 0: return [4 /*yield*/, schemaLoader(schema, target, projectId)];
|
|
65
|
+
case 1:
|
|
66
|
+
_b = _d.sent(), schemaPath = _b.schema, destinationPathTs = _b.destination;
|
|
67
|
+
console.log("\u2139\uFE0F Generating [".concat(chalk.green(target), "] schema"));
|
|
68
|
+
return [4 /*yield*/, generate({
|
|
69
|
+
schema: schemaPath,
|
|
70
|
+
generates: (_c = {},
|
|
71
|
+
// [destinationPath]: {
|
|
72
|
+
// plugins: ['introspection']
|
|
73
|
+
// },
|
|
74
|
+
_c[destinationPathTs] = {
|
|
75
|
+
schema: isSchemaFromHttp(schema)
|
|
76
|
+
? schema
|
|
77
|
+
: require.resolve(schemaPath),
|
|
78
|
+
plugins: [
|
|
79
|
+
'typescript',
|
|
80
|
+
'typescript-resolvers',
|
|
81
|
+
{
|
|
82
|
+
add: {
|
|
83
|
+
content: autoGenerationComments,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
_c),
|
|
89
|
+
hooks: {
|
|
90
|
+
afterAllFileWrite: [
|
|
91
|
+
function () {
|
|
92
|
+
var filePaths = [];
|
|
93
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
94
|
+
filePaths[_i] = arguments[_i];
|
|
95
|
+
}
|
|
96
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
+
var _a, filePaths_1, path, rawText, options, formattedText;
|
|
98
|
+
return __generator(this, function (_b) {
|
|
99
|
+
switch (_b.label) {
|
|
100
|
+
case 0:
|
|
101
|
+
_a = 0, filePaths_1 = filePaths;
|
|
102
|
+
_b.label = 1;
|
|
103
|
+
case 1:
|
|
104
|
+
if (!(_a < filePaths_1.length)) return [3 /*break*/, 4];
|
|
105
|
+
path = filePaths_1[_a];
|
|
106
|
+
rawText = readFileSync(path, 'utf8');
|
|
107
|
+
return [4 /*yield*/, prettier.resolveConfig(dirname(path))];
|
|
108
|
+
case 2:
|
|
109
|
+
options = _b.sent();
|
|
110
|
+
formattedText = prettier.format(rawText, __assign({ parser: 'typescript' }, options));
|
|
111
|
+
writeFileSync(path, formattedText);
|
|
112
|
+
_b.label = 3;
|
|
113
|
+
case 3:
|
|
114
|
+
_a++;
|
|
115
|
+
return [3 /*break*/, 1];
|
|
116
|
+
case 4: return [2 /*return*/];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
config: __assign({}, commonSchemaTypesConfig),
|
|
124
|
+
}, true)];
|
|
125
|
+
case 2:
|
|
126
|
+
_d.sent();
|
|
127
|
+
return [2 /*return*/];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
module.exports = generateSchema;
|