stepzen 0.17.0-beta.1 → 0.17.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/README.md +2 -5
- package/lib/commands/import.d.ts +9 -3
- package/lib/commands/import.js +42 -4
- package/lib/commands/lint.js +2 -2
- package/lib/commands/start.js +8 -2
- package/lib/commands/transpile.d.ts +1 -1
- package/lib/commands/transpile.js +5 -5
- package/lib/commands/validate.js +3 -3
- package/lib/generate/curl2sdl.d.ts +1 -19
- package/lib/generate/curl2sdl.js +42 -113
- package/lib/generate/graphql2sdl.d.ts +23 -0
- package/lib/generate/graphql2sdl.js +62 -0
- package/lib/generate/helpers.d.ts +18 -0
- package/lib/generate/helpers.js +86 -1
- package/lib/shared/header-params-parser.d.ts +1 -1
- package/lib/shared/header.d.ts +21 -0
- package/lib/shared/header.js +13 -0
- package/lib/start/console.js +22 -7
- package/lib/start/deploy.d.ts +1 -1
- package/lib/start/deploy.js +20 -4
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ $ npm install -g stepzen
|
|
|
29
29
|
$ stepzen COMMAND
|
|
30
30
|
running command...
|
|
31
31
|
$ stepzen (-v|--version|version)
|
|
32
|
-
stepzen/0.17.0
|
|
32
|
+
stepzen/0.17.0 darwin-x64 node-v14.19.3
|
|
33
33
|
$ stepzen --help [COMMAND]
|
|
34
34
|
USAGE
|
|
35
35
|
$ stepzen COMMAND
|
|
@@ -126,9 +126,6 @@ OPTIONS
|
|
|
126
126
|
Subfolder inside the workspace folder to save the imported schema files to. Defaults to the name of the imported
|
|
127
127
|
schema.
|
|
128
128
|
|
|
129
|
-
--overwrite
|
|
130
|
-
Overwrite any existing schema with the same name. Cannot be used without also providing a --name flag.
|
|
131
|
-
|
|
132
129
|
--path-params=path-params
|
|
133
130
|
[curl] specifies path parameters in the URL path. Can be formed by taking the original path and replacing the
|
|
134
131
|
variable segments with $paramName placeholders.
|
|
@@ -137,7 +134,7 @@ OPTIONS
|
|
|
137
134
|
stepzen import curl https://example.com/users/jane/posts/12 --path-params '/users/$userId/posts/$postId'
|
|
138
135
|
|
|
139
136
|
--prefix=prefix
|
|
140
|
-
[curl] prefix to add every type in the generated schema.
|
|
137
|
+
[curl, graphql] prefix to add every type in the generated schema.
|
|
141
138
|
|
|
142
139
|
--query-name=query-name
|
|
143
140
|
[curl] property name to add to the Query type as a way to access the imported cURL endpoint.
|
package/lib/commands/import.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ import ZenCommand from '../shared/zen-command';
|
|
|
3
3
|
import { Workspace } from '../shared/types';
|
|
4
4
|
export default class Import extends ZenCommand {
|
|
5
5
|
static description: string;
|
|
6
|
-
static
|
|
6
|
+
static commonIntrospectionFlags: {
|
|
7
7
|
prefix: flags.IOptionFlag<string | undefined>;
|
|
8
|
+
};
|
|
9
|
+
static curlFlags: {
|
|
8
10
|
'query-name': flags.IOptionFlag<string | undefined>;
|
|
9
11
|
'query-type': flags.IOptionFlag<string | undefined>;
|
|
10
12
|
'path-params': flags.IOptionFlag<string | undefined>;
|
|
@@ -22,6 +24,10 @@ export default class Import extends ZenCommand {
|
|
|
22
24
|
static flagsForSchemas: ({
|
|
23
25
|
flags: {
|
|
24
26
|
prefix: flags.IOptionFlag<string | undefined>;
|
|
27
|
+
};
|
|
28
|
+
schemas: string[];
|
|
29
|
+
} | {
|
|
30
|
+
flags: {
|
|
25
31
|
'query-name': flags.IOptionFlag<string | undefined>;
|
|
26
32
|
'query-type': flags.IOptionFlag<string | undefined>;
|
|
27
33
|
'path-params': flags.IOptionFlag<string | undefined>;
|
|
@@ -48,11 +54,11 @@ export default class Import extends ZenCommand {
|
|
|
48
54
|
'db-user': flags.IOptionFlag<string | undefined>;
|
|
49
55
|
'db-password': flags.IOptionFlag<string | undefined>;
|
|
50
56
|
'db-database': flags.IOptionFlag<string | undefined>;
|
|
51
|
-
prefix: flags.IOptionFlag<string | undefined>;
|
|
52
57
|
'query-name': flags.IOptionFlag<string | undefined>;
|
|
53
58
|
'query-type': flags.IOptionFlag<string | undefined>;
|
|
54
59
|
'path-params': flags.IOptionFlag<string | undefined>;
|
|
55
60
|
'header-param': flags.IOptionFlag<string[]>;
|
|
61
|
+
prefix: flags.IOptionFlag<string | undefined>;
|
|
56
62
|
dir: flags.IOptionFlag<string | undefined>;
|
|
57
63
|
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
58
64
|
silent: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
@@ -76,11 +82,11 @@ export default class Import extends ZenCommand {
|
|
|
76
82
|
'db-user': string | undefined;
|
|
77
83
|
'db-password': string | undefined;
|
|
78
84
|
'db-database': string | undefined;
|
|
79
|
-
prefix: string | undefined;
|
|
80
85
|
'query-name': string | undefined;
|
|
81
86
|
'query-type': string | undefined;
|
|
82
87
|
'path-params': string | undefined;
|
|
83
88
|
'header-param': string[];
|
|
89
|
+
prefix: string | undefined;
|
|
84
90
|
dir: string | undefined;
|
|
85
91
|
help: void;
|
|
86
92
|
silent: boolean;
|
package/lib/commands/import.js
CHANGED
|
@@ -15,6 +15,7 @@ const helpers_1 = require("../generate/helpers");
|
|
|
15
15
|
const curl2sdl_1 = require("../generate/curl2sdl");
|
|
16
16
|
const curl_parser_1 = require("../shared/curl-parser");
|
|
17
17
|
const zen_command_1 = require("../shared/zen-command");
|
|
18
|
+
const graphql2sdl_1 = require("../generate/graphql2sdl");
|
|
18
19
|
const constants_1 = require("../shared/constants");
|
|
19
20
|
const path_params_parser_1 = require("../shared/path-params-parser");
|
|
20
21
|
const header_params_parser_1 = require("../shared/header-params-parser");
|
|
@@ -93,6 +94,35 @@ class Import extends zen_command_1.default {
|
|
|
93
94
|
}
|
|
94
95
|
result = resultOrError.outPath;
|
|
95
96
|
}
|
|
97
|
+
else if (schema === 'graphql') {
|
|
98
|
+
const editableOptions = {
|
|
99
|
+
typePrefix: flags.prefix,
|
|
100
|
+
};
|
|
101
|
+
let answers;
|
|
102
|
+
if (argv.length === 1) {
|
|
103
|
+
// interactive
|
|
104
|
+
answers = await graphql2sdl_1.askGraphQLQuestions(editableOptions);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// non-interactive
|
|
108
|
+
answers = Object.assign(Object.assign({}, editableOptions), { endpoint: argv[1] });
|
|
109
|
+
}
|
|
110
|
+
const fixedOptions = {
|
|
111
|
+
name: flags.name,
|
|
112
|
+
source: workspace.schema,
|
|
113
|
+
onConflict,
|
|
114
|
+
};
|
|
115
|
+
const options = Object.assign(Object.assign({}, fixedOptions), answers);
|
|
116
|
+
core_1.CliUx.ux.action.start('Starting');
|
|
117
|
+
const resultOrError = await graphql2sdl_1.graphql2sdl(options);
|
|
118
|
+
core_1.CliUx.ux.action.stop();
|
|
119
|
+
if ('error' in resultOrError) {
|
|
120
|
+
this.log('A problem occured while processing your import.');
|
|
121
|
+
this.log(resultOrError.error);
|
|
122
|
+
this.exit();
|
|
123
|
+
}
|
|
124
|
+
result = resultOrError.outPath;
|
|
125
|
+
}
|
|
96
126
|
else {
|
|
97
127
|
// Map flag names to the properties defined for sql engines in:
|
|
98
128
|
// https://github.com/steprz/generator-engines/blob/main/generator/src/shared/sql.ts
|
|
@@ -124,6 +154,10 @@ class Import extends zen_command_1.default {
|
|
|
124
154
|
this.log(chalk.green(`Successfully imported schema ${chalk.bold(schema)} from StepZen`));
|
|
125
155
|
}
|
|
126
156
|
async ensureOnConflictBehavior(workspace, schema, flags) {
|
|
157
|
+
const featureFlag = process.env.STEPZEN_DETECT_NAME_CONFLICTS;
|
|
158
|
+
if (featureFlag === undefined || featureFlag.toLowerCase() === 'false') {
|
|
159
|
+
return 'append';
|
|
160
|
+
}
|
|
127
161
|
const name = flags.name || schema;
|
|
128
162
|
const hasConflict = fs.existsSync(path.join(workspace.schema, name));
|
|
129
163
|
if (!hasConflict) {
|
|
@@ -217,10 +251,12 @@ class Import extends zen_command_1.default {
|
|
|
217
251
|
}
|
|
218
252
|
exports.default = Import;
|
|
219
253
|
Import.description = 'import a schema for an external data source or a API endpoint to your GraphQL API';
|
|
220
|
-
Import.
|
|
254
|
+
Import.commonIntrospectionFlags = {
|
|
221
255
|
prefix: command_1.flags.string({
|
|
222
|
-
description: '[curl] prefix to add every type in the generated schema.',
|
|
256
|
+
description: '[curl, graphql] prefix to add every type in the generated schema.',
|
|
223
257
|
}),
|
|
258
|
+
};
|
|
259
|
+
Import.curlFlags = {
|
|
224
260
|
'query-name': command_1.flags.string({
|
|
225
261
|
description: '[curl] property name to add to the Query type as a way to' +
|
|
226
262
|
' access the imported cURL endpoint.',
|
|
@@ -271,18 +307,20 @@ Import.postgresqlFlags = {
|
|
|
271
307
|
}),
|
|
272
308
|
};
|
|
273
309
|
Import.flagsForSchemas = [
|
|
310
|
+
{ flags: Import.commonIntrospectionFlags, schemas: ['curl', 'graphql'] },
|
|
274
311
|
{ flags: Import.curlFlags, schemas: ['curl'] },
|
|
275
312
|
{ flags: Import.sqlFlags, schemas: ['mysql', 'postgresql'] },
|
|
276
313
|
{ flags: Import.postgresqlFlags, schemas: ['postgresql'] },
|
|
277
314
|
];
|
|
278
|
-
Import.flags = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, zen_command_1.default.flags), { dir: command_1.flags.string({ description: 'working directory' }), help: command_1.flags.help({ char: 'h' }), silent: command_1.flags.boolean({ hidden: true }), name: command_1.flags.string({
|
|
315
|
+
Import.flags = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, zen_command_1.default.flags), { dir: command_1.flags.string({ description: 'working directory' }), help: command_1.flags.help({ char: 'h' }), silent: command_1.flags.boolean({ hidden: true }), name: command_1.flags.string({
|
|
279
316
|
description: 'Subfolder inside the workspace folder to save the imported' +
|
|
280
317
|
' schema files to. Defaults to the name of the imported schema.',
|
|
281
318
|
}), overwrite: command_1.flags.boolean({
|
|
282
319
|
description: 'Overwrite any existing schema with the same name. Cannot be used' +
|
|
283
320
|
' without also providing a --name flag.',
|
|
284
321
|
dependsOn: ['name'],
|
|
285
|
-
|
|
322
|
+
hidden: true,
|
|
323
|
+
}) }), Import.commonIntrospectionFlags), Import.curlFlags), Import.sqlFlags), Import.postgresqlFlags);
|
|
286
324
|
Import.args = [
|
|
287
325
|
{
|
|
288
326
|
name: 'schema',
|
package/lib/commands/lint.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const command_1 = require("@oclif/command");
|
|
5
|
+
const transpiler_1 = require("@stepzen/transpiler");
|
|
5
6
|
const utils_1 = require("../shared/utils");
|
|
6
7
|
const zen_command_1 = require("../shared/zen-command");
|
|
7
|
-
const { lint } = require('@stepzen/transpiler');
|
|
8
8
|
class Init extends zen_command_1.default {
|
|
9
9
|
async run() {
|
|
10
10
|
const { flags } = this.parse(Init);
|
|
@@ -18,7 +18,7 @@ class Init extends zen_command_1.default {
|
|
|
18
18
|
this.log(formatted);
|
|
19
19
|
};
|
|
20
20
|
// Lint
|
|
21
|
-
await lint(directory);
|
|
21
|
+
await transpiler_1.lint(directory);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.default = Init;
|
package/lib/commands/start.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const chokidar = require("chokidar");
|
|
5
|
+
const debug = require("debug");
|
|
5
6
|
const core_1 = require("@oclif/core");
|
|
6
7
|
const command_1 = require("@oclif/command");
|
|
7
8
|
const errors_1 = require("@oclif/errors");
|
|
@@ -33,6 +34,7 @@ class Start extends zen_command_1.default {
|
|
|
33
34
|
// This is the file watcher
|
|
34
35
|
if (!flags['no-watcher']) {
|
|
35
36
|
const redeploy = throttle_debounce_1.debounce(500, (path) => {
|
|
37
|
+
debug('stepzen:start')(`chokidar decected change to ${path}`);
|
|
36
38
|
start_1.changed({ workspace, file: path });
|
|
37
39
|
start_1.deploy({ workspace, flags });
|
|
38
40
|
});
|
|
@@ -45,15 +47,18 @@ class Start extends zen_command_1.default {
|
|
|
45
47
|
.on('change', redeploy)
|
|
46
48
|
.on('add', redeploy)
|
|
47
49
|
.on('unlink', redeploy);
|
|
50
|
+
debug('stepzen:start')(`chokidar started watching ${workspace.schema}`);
|
|
48
51
|
}
|
|
49
52
|
// Start!
|
|
50
53
|
core_1.CliUx.ux.action.start('Starting...');
|
|
54
|
+
let didDeploy = false;
|
|
51
55
|
// Unless explicitly disabled, auto-init
|
|
52
56
|
if (!flags['no-init']) {
|
|
53
|
-
await start_1.deploy({ workspace, flags });
|
|
57
|
+
didDeploy = await start_1.deploy({ workspace, flags });
|
|
54
58
|
}
|
|
55
59
|
// Create the dashboard
|
|
56
60
|
if (!flags['no-dashboard']) {
|
|
61
|
+
debug('stepzen:start')(`starting the dashboard server on ${flags.port}`);
|
|
57
62
|
const ui = await dashboard({
|
|
58
63
|
account: configuration.account,
|
|
59
64
|
adminkey: configuration.adminkey,
|
|
@@ -71,11 +76,12 @@ class Start extends zen_command_1.default {
|
|
|
71
76
|
workspace,
|
|
72
77
|
});
|
|
73
78
|
await ui.start();
|
|
79
|
+
debug('stepzen:start')(`dashboard server on ${flags.port} started`);
|
|
74
80
|
}
|
|
75
81
|
// Done
|
|
76
82
|
core_1.CliUx.ux.action.stop();
|
|
77
83
|
if (!flags['no-console']) {
|
|
78
|
-
if (
|
|
84
|
+
if (didDeploy) {
|
|
79
85
|
start_1.success({
|
|
80
86
|
workspace,
|
|
81
87
|
account: configuration.account,
|
|
@@ -6,26 +6,26 @@ const command_1 = require("@oclif/command");
|
|
|
6
6
|
const errors_1 = require("@oclif/errors");
|
|
7
7
|
const fs = require("fs-extra");
|
|
8
8
|
const path = require("path");
|
|
9
|
+
const transpiler_1 = require("@stepzen/transpiler");
|
|
9
10
|
const utils_1 = require("../shared/utils");
|
|
10
11
|
const zen_command_1 = require("../shared/zen-command");
|
|
11
|
-
const { configure, stitch, validate } = require('@stepzen/transpiler');
|
|
12
12
|
class Transpile extends zen_command_1.default {
|
|
13
13
|
async run() {
|
|
14
14
|
const { args, flags } = this.parse(Transpile);
|
|
15
15
|
const folder = utils_1.getDirectory(args.folder);
|
|
16
16
|
// CONFIG
|
|
17
17
|
if (flags['output-configuration']) {
|
|
18
|
-
const config = await configure(folder, flags.silent);
|
|
18
|
+
const config = await transpiler_1.configure(folder, flags.silent);
|
|
19
19
|
if (flags['hide-output']) {
|
|
20
20
|
return config;
|
|
21
21
|
}
|
|
22
|
-
this.log(config);
|
|
22
|
+
this.log(`${config}`);
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
// SCHEMA
|
|
26
26
|
try {
|
|
27
|
-
const schema = stitch(folder);
|
|
28
|
-
validate(schema, {
|
|
27
|
+
const schema = transpiler_1.stitch(folder);
|
|
28
|
+
transpiler_1.validate(schema, {
|
|
29
29
|
extensions: await utils_1.getStepZenExtensions(),
|
|
30
30
|
});
|
|
31
31
|
const file = path.join(schema, 'index.graphql');
|
package/lib/commands/validate.js
CHANGED
|
@@ -4,16 +4,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const chalk = require("chalk");
|
|
5
5
|
const command_1 = require("@oclif/command");
|
|
6
6
|
const errors_1 = require("@oclif/errors");
|
|
7
|
+
const transpiler_1 = require("@stepzen/transpiler");
|
|
7
8
|
const utils_1 = require("../shared/utils");
|
|
8
9
|
const zen_command_1 = require("../shared/zen-command");
|
|
9
|
-
const { stitch, validate } = require('@stepzen/transpiler');
|
|
10
10
|
class Validate extends zen_command_1.default {
|
|
11
11
|
async run() {
|
|
12
12
|
const { args } = this.parse(Validate);
|
|
13
13
|
const folder = utils_1.getDirectory(args.folder);
|
|
14
14
|
try {
|
|
15
|
-
const schema = stitch(folder);
|
|
16
|
-
validate(schema, {
|
|
15
|
+
const schema = transpiler_1.stitch(folder);
|
|
16
|
+
transpiler_1.validate(schema, {
|
|
17
17
|
extensions: await utils_1.getStepZenExtensions(),
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -1,24 +1,6 @@
|
|
|
1
1
|
import { CurlArguments } from '../shared/curl-parser';
|
|
2
2
|
import { PathParam } from '../shared/path-params-parser';
|
|
3
|
-
|
|
4
|
-
name: string;
|
|
5
|
-
value: string;
|
|
6
|
-
};
|
|
7
|
-
export declare type NamePartsHeaderInput = {
|
|
8
|
-
name: string;
|
|
9
|
-
parts: HeaderInputValuePart[];
|
|
10
|
-
};
|
|
11
|
-
export declare type HeaderInput = NameValueHeaderInput | NamePartsHeaderInput;
|
|
12
|
-
export declare type HeaderInputConstantValuePart = {
|
|
13
|
-
kind: 'Constant';
|
|
14
|
-
value: string;
|
|
15
|
-
};
|
|
16
|
-
export declare type HeaderInputVariableValuePart = {
|
|
17
|
-
kind: 'Variable';
|
|
18
|
-
value: string;
|
|
19
|
-
name: string;
|
|
20
|
-
};
|
|
21
|
-
export declare type HeaderInputValuePart = HeaderInputConstantValuePart | HeaderInputVariableValuePart;
|
|
3
|
+
import { HeaderInput } from '../shared/header';
|
|
22
4
|
export declare type Curl2SdlOptions = {
|
|
23
5
|
curlArgs: CurlArguments;
|
|
24
6
|
name?: string;
|
package/lib/generate/curl2sdl.js
CHANGED
|
@@ -2,22 +2,13 @@
|
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.curl2sdl = exports.askCurlQuestions = exports.makeDuplicateParamsMessage = exports.compileParameterList = void 0;
|
|
5
|
-
const errors_1 = require("@oclif/errors");
|
|
6
5
|
const chalk = require("chalk");
|
|
7
|
-
const fs = require("fs-extra");
|
|
8
6
|
const inquirer = require("inquirer");
|
|
9
7
|
const lodash_1 = require("lodash");
|
|
10
|
-
const os = require("os");
|
|
11
|
-
const path = require("path");
|
|
12
8
|
const string_argv_1 = require("string-argv");
|
|
13
|
-
const node_fetch_1 = require("node-fetch");
|
|
14
|
-
const debug = require("debug");
|
|
15
|
-
const prettier = require("prettier");
|
|
16
|
-
const transpiler_1 = require("@stepzen/transpiler");
|
|
17
9
|
const curl_parser_1 = require("../shared/curl-parser");
|
|
18
10
|
const path_params_parser_1 = require("../shared/path-params-parser");
|
|
19
|
-
const
|
|
20
|
-
const errors_2 = require("../shared/errors");
|
|
11
|
+
const helpers_1 = require("./helpers");
|
|
21
12
|
/**
|
|
22
13
|
* Collect together all query parameters from HTTP headers and from the
|
|
23
14
|
* pathname, and return them as a uniform list.
|
|
@@ -116,7 +107,7 @@ exports.askCurlQuestions = async (defaultAnswers = {}) => {
|
|
|
116
107
|
},
|
|
117
108
|
{
|
|
118
109
|
name: 'typePrefix',
|
|
119
|
-
message: 'Prefix to add to all generated type
|
|
110
|
+
message: 'Prefix to add to all generated type names (leave blank to use defaults)',
|
|
120
111
|
},
|
|
121
112
|
];
|
|
122
113
|
questions = questions.map(question => (Object.assign(Object.assign({}, question), { default: lodash_1.get(defaultAnswers, question.name) })));
|
|
@@ -152,107 +143,45 @@ exports.askCurlQuestions = async (defaultAnswers = {}) => {
|
|
|
152
143
|
};
|
|
153
144
|
};
|
|
154
145
|
exports.curl2sdl = async ({ curlArgs, name, source, queryName, rootType, typePrefix, pathParams, headers, onConflict, }) => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
};
|
|
192
|
-
debug('stepzen:curl2sdl')(url);
|
|
193
|
-
debug('stepzen:curl2sdl')(query);
|
|
194
|
-
debug('stepzen:curl2sdl')(variables);
|
|
195
|
-
const payload = JSON.stringify({
|
|
196
|
-
query,
|
|
197
|
-
variables,
|
|
198
|
-
});
|
|
199
|
-
debug('stepzen:curl2sdl')(payload);
|
|
200
|
-
const response = await node_fetch_1.default(url, {
|
|
201
|
-
method: 'POST',
|
|
202
|
-
headers: { 'Content-Type': 'application/json' },
|
|
203
|
-
body: JSON.stringify({
|
|
204
|
-
query,
|
|
205
|
-
variables,
|
|
206
|
-
}),
|
|
207
|
-
});
|
|
208
|
-
const text = await response.text();
|
|
209
|
-
debug('stepzen:curl2sdl')(text);
|
|
210
|
-
json = JSON.parse(text);
|
|
211
|
-
}
|
|
212
|
-
catch (error) {
|
|
213
|
-
debug('stepzen:curl2sdl')(error);
|
|
214
|
-
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
215
|
-
}
|
|
216
|
-
if (!json.data && !json.errors) {
|
|
217
|
-
debug('stepzen:curl2sdl')('expected the response from the JSON introspection service ' +
|
|
218
|
-
'to contain either `data` or `errors`');
|
|
219
|
-
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
220
|
-
}
|
|
221
|
-
if (json.errors) {
|
|
222
|
-
return { error: json.errors.map((error) => error.message).join('\n') };
|
|
223
|
-
}
|
|
224
|
-
const { getSDLFromCurl } = json.data;
|
|
225
|
-
if (!getSDLFromCurl) {
|
|
226
|
-
debug('stepzen:curl2sdl')('expected the response from the JSON introspection service ' +
|
|
227
|
-
'to contain a `getSDLFromCurl` object');
|
|
228
|
-
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
229
|
-
}
|
|
230
|
-
const { config, sdl } = getSDLFromCurl;
|
|
231
|
-
if (!config && !sdl) {
|
|
232
|
-
debug('stepzen:curl2sdl')('expected the response from the JSON introspection service ' +
|
|
233
|
-
'to contain at least one of `getSDLFromCurl.config` or ' +
|
|
234
|
-
'`getSDLFromCurl.sdl` properties');
|
|
235
|
-
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
236
|
-
}
|
|
237
|
-
// write out the generated config and schema files
|
|
238
|
-
const tmp = path.join(os.tmpdir(), `stepzen-curl2sdl-${Date.now()}`);
|
|
239
|
-
fs.ensureDirSync(tmp);
|
|
240
|
-
// fs.ensureDirSync(path.join(tmp, subfolder))
|
|
241
|
-
if (config) {
|
|
242
|
-
fs.writeFileSync(path.join(tmp, 'config.yaml'), prettier.format(config, { parser: 'yaml' }));
|
|
243
|
-
}
|
|
244
|
-
if (sdl) {
|
|
245
|
-
fs.writeFileSync(path.join(tmp, 'index.graphql'), prettier.format(sdl, { parser: 'graphql' }));
|
|
246
|
-
}
|
|
247
|
-
const result = await transpiler_1.merge(source, {
|
|
248
|
-
name: name || 'curl',
|
|
249
|
-
source: tmp,
|
|
250
|
-
}, {
|
|
251
|
-
answers: {},
|
|
252
|
-
output: null,
|
|
253
|
-
silent: true,
|
|
254
|
-
mergeTypes: false,
|
|
255
|
-
onConflict,
|
|
146
|
+
const response = await helpers_1.queryIntrospectionService({
|
|
147
|
+
operation: 'getSDLFromCurl',
|
|
148
|
+
variables: {
|
|
149
|
+
command: {
|
|
150
|
+
type: 'String!',
|
|
151
|
+
value: curlArgs.url,
|
|
152
|
+
},
|
|
153
|
+
queryName: {
|
|
154
|
+
type: 'String',
|
|
155
|
+
value: queryName || null,
|
|
156
|
+
},
|
|
157
|
+
rootType: {
|
|
158
|
+
type: 'String',
|
|
159
|
+
value: rootType || null,
|
|
160
|
+
},
|
|
161
|
+
typePrefix: {
|
|
162
|
+
type: 'String',
|
|
163
|
+
value: typePrefix || null,
|
|
164
|
+
},
|
|
165
|
+
headers: {
|
|
166
|
+
type: '[HeaderInput!]',
|
|
167
|
+
value: headers && headers.length > 0 ? headers : null,
|
|
168
|
+
},
|
|
169
|
+
data: {
|
|
170
|
+
type: 'String',
|
|
171
|
+
value: curlArgs.data || null,
|
|
172
|
+
},
|
|
173
|
+
method: {
|
|
174
|
+
type: 'HTTPMethod!',
|
|
175
|
+
value: curlArgs.method,
|
|
176
|
+
},
|
|
177
|
+
pathParams: {
|
|
178
|
+
type: '[PathParamInput!]',
|
|
179
|
+
value: pathParams.length > 0 ? pathParams : null,
|
|
180
|
+
},
|
|
181
|
+
},
|
|
256
182
|
});
|
|
257
|
-
|
|
183
|
+
if (response.error) {
|
|
184
|
+
return { error: response.error };
|
|
185
|
+
}
|
|
186
|
+
return helpers_1.writeSdlAndConfig(name || 'curl', source, onConflict, response);
|
|
258
187
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HeaderInput } from '../shared/header';
|
|
2
|
+
export declare type GraphQL2SdlOptions = {
|
|
3
|
+
name?: string;
|
|
4
|
+
source: string;
|
|
5
|
+
endpoint: string;
|
|
6
|
+
typePrefix?: string;
|
|
7
|
+
includeRootOperations?: boolean;
|
|
8
|
+
header?: string;
|
|
9
|
+
onConflict: 'overwrite' | 'append';
|
|
10
|
+
};
|
|
11
|
+
export declare type EditableGraphQL2SdlOptions = Pick<GraphQL2SdlOptions, 'endpoint' | 'typePrefix' | 'includeRootOperations' | 'header'>;
|
|
12
|
+
export declare type GraphQLAnswers = {
|
|
13
|
+
endpoint: string;
|
|
14
|
+
typePrefix: string;
|
|
15
|
+
includeRootOperations: boolean;
|
|
16
|
+
headers: readonly HeaderInput[];
|
|
17
|
+
};
|
|
18
|
+
export declare const askGraphQLQuestions: (defaultAnswers?: Partial<GraphQLAnswers>) => Promise<EditableGraphQL2SdlOptions>;
|
|
19
|
+
export declare const graphql2sdl: ({ name, source, endpoint, typePrefix, includeRootOperations, header, onConflict, }: GraphQL2SdlOptions) => Promise<{
|
|
20
|
+
error: string;
|
|
21
|
+
} | {
|
|
22
|
+
outPath: string;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.graphql2sdl = exports.askGraphQLQuestions = void 0;
|
|
5
|
+
const inquirer = require("inquirer");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const header_1 = require("../shared/header");
|
|
8
|
+
const helpers_1 = require("./helpers");
|
|
9
|
+
exports.askGraphQLQuestions = async (defaultAnswers = {}) => {
|
|
10
|
+
let questions = [
|
|
11
|
+
{
|
|
12
|
+
name: 'endpoint',
|
|
13
|
+
message: 'What is the GraphQL endpoint URL?',
|
|
14
|
+
validate: input => input.trim() !== '',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'typePrefix',
|
|
18
|
+
message: 'Prefix to add to all generated type names (leave blank for none)',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'includeRootOperations',
|
|
22
|
+
type: 'confirm',
|
|
23
|
+
message: 'Should type prefix be added to query and mutation fields as well?',
|
|
24
|
+
when: answers => Boolean(answers.typePrefix),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'header',
|
|
28
|
+
type: 'input',
|
|
29
|
+
message: 'Add an HTTP header, e.g. Header-Name: header value (leave blank for none)',
|
|
30
|
+
validate: input => input === '' || header_1.HEADER_REGEX.test(input.trim()) || 'invalid header',
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
questions = questions.map(question => (Object.assign(Object.assign({}, question), { default: lodash_1.get(defaultAnswers, question.name) })));
|
|
34
|
+
return inquirer.prompt(questions);
|
|
35
|
+
};
|
|
36
|
+
exports.graphql2sdl = async ({ name, source, endpoint, typePrefix, includeRootOperations, header, onConflict, }) => {
|
|
37
|
+
const response = await helpers_1.queryIntrospectionService({
|
|
38
|
+
operation: 'getSDLFromGraphQL',
|
|
39
|
+
variables: {
|
|
40
|
+
endpoint: {
|
|
41
|
+
type: 'String!',
|
|
42
|
+
value: endpoint,
|
|
43
|
+
},
|
|
44
|
+
typePrefix: {
|
|
45
|
+
type: 'String',
|
|
46
|
+
value: typePrefix || null,
|
|
47
|
+
},
|
|
48
|
+
includeRootOperations: {
|
|
49
|
+
type: 'Boolean',
|
|
50
|
+
value: includeRootOperations || null,
|
|
51
|
+
},
|
|
52
|
+
headers: {
|
|
53
|
+
type: '[HeaderInput!]',
|
|
54
|
+
value: header ? [header_1.parseHeaderNameValue(header)] : null,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
if (response.error) {
|
|
59
|
+
return { error: response.error };
|
|
60
|
+
}
|
|
61
|
+
return helpers_1.writeSdlAndConfig(name || 'graphql', source, onConflict, response);
|
|
62
|
+
};
|
|
@@ -11,3 +11,21 @@ export declare const getSchema: (arg: string) => string;
|
|
|
11
11
|
export declare const getTemplates: () => Promise<string>;
|
|
12
12
|
export declare const askGeneratorQuestions: (id: string, settings: any, state: any) => Promise<any>;
|
|
13
13
|
export declare const askTemplateQuestions: (id: string, settings: any, state: any) => Promise<any>;
|
|
14
|
+
export declare type IntrospectionServiceQuery = {
|
|
15
|
+
operation: string;
|
|
16
|
+
variables: {
|
|
17
|
+
[id: string]: {
|
|
18
|
+
type: string;
|
|
19
|
+
value: any | null;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export declare type IntrospectionServiceResponse = {
|
|
24
|
+
sdl?: string;
|
|
25
|
+
config?: string;
|
|
26
|
+
error?: string;
|
|
27
|
+
};
|
|
28
|
+
export declare const queryIntrospectionService: (query: IntrospectionServiceQuery) => Promise<IntrospectionServiceResponse>;
|
|
29
|
+
export declare const writeSdlAndConfig: (name: string, source: string, onConflict: 'overwrite' | 'append', { config, sdl }: IntrospectionServiceResponse) => Promise<{
|
|
30
|
+
outPath: string;
|
|
31
|
+
}>;
|
package/lib/generate/helpers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.askTemplateQuestions = exports.askGeneratorQuestions = exports.getTemplates = exports.getSchema = exports.getConfiguration = exports.createGeneratorFiles = void 0;
|
|
4
|
+
exports.writeSdlAndConfig = exports.queryIntrospectionService = exports.askTemplateQuestions = exports.askGeneratorQuestions = exports.getTemplates = exports.getSchema = exports.getConfiguration = exports.createGeneratorFiles = void 0;
|
|
5
5
|
const errors_1 = require("@oclif/errors");
|
|
6
6
|
const chalk = require("chalk");
|
|
7
7
|
const debug = require("debug");
|
|
@@ -12,6 +12,8 @@ const lodash_1 = require("lodash");
|
|
|
12
12
|
const os = require("os");
|
|
13
13
|
const path = require("path");
|
|
14
14
|
const shell = require("shelljs");
|
|
15
|
+
const transpiler = require("@stepzen/transpiler");
|
|
16
|
+
const prettier = require("prettier");
|
|
15
17
|
const constants_1 = require("../shared/constants");
|
|
16
18
|
const errors_2 = require("../shared/errors");
|
|
17
19
|
const { version } = require('../../package.json');
|
|
@@ -159,3 +161,86 @@ exports.askTemplateQuestions = async (id, settings, state) => {
|
|
|
159
161
|
const answers = await inquirer.prompt(questions);
|
|
160
162
|
return Object.assign(Object.assign({}, state), answers);
|
|
161
163
|
};
|
|
164
|
+
exports.queryIntrospectionService = async (query) => {
|
|
165
|
+
let json;
|
|
166
|
+
try {
|
|
167
|
+
const url = `${constants_1.STEPZEN_JSON2SDL_SERVER_URL}/api/graphql`;
|
|
168
|
+
debug('stepzen:introspection')(url);
|
|
169
|
+
const queryString = `query (
|
|
170
|
+
${Object.entries(query.variables).map(([id, { type }]) => `$${id}: ${type}`)}
|
|
171
|
+
) {
|
|
172
|
+
${query.operation}(${Object.keys(query.variables).map(id => `${id}: $${id}`)}) {
|
|
173
|
+
sdl
|
|
174
|
+
config
|
|
175
|
+
}
|
|
176
|
+
}`;
|
|
177
|
+
debug('stepzen:introspection')(queryString);
|
|
178
|
+
debug('stepzen:introspection')(query.variables);
|
|
179
|
+
const payload = JSON.stringify({
|
|
180
|
+
query: queryString,
|
|
181
|
+
variables: lodash_1.mapValues(query.variables, ({ value }) => value),
|
|
182
|
+
});
|
|
183
|
+
debug('stepzen:introspection')(payload);
|
|
184
|
+
const response = await node_fetch_1.default(url, {
|
|
185
|
+
method: 'POST',
|
|
186
|
+
headers: { 'Content-Type': 'application/json' },
|
|
187
|
+
body: payload,
|
|
188
|
+
});
|
|
189
|
+
const text = await response.text();
|
|
190
|
+
debug('stepzen:introspection')(text);
|
|
191
|
+
json = JSON.parse(text);
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
debug('stepzen:introspection')(error);
|
|
195
|
+
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
196
|
+
}
|
|
197
|
+
if (!json.data && !json.errors) {
|
|
198
|
+
debug('stepzen:introspection')('expected the response from the JSON introspection service ' +
|
|
199
|
+
'to contain either `data` or `errors`');
|
|
200
|
+
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
201
|
+
}
|
|
202
|
+
if (json.errors) {
|
|
203
|
+
const compileError = (error) => {
|
|
204
|
+
var _a;
|
|
205
|
+
return error.message +
|
|
206
|
+
(((_a = error.extensions) === null || _a === void 0 ? void 0 : _a.details) ? `: ${error.extensions.details}` : '');
|
|
207
|
+
};
|
|
208
|
+
return { error: json.errors.map(compileError).join('\n') };
|
|
209
|
+
}
|
|
210
|
+
if (!json.data[query.operation]) {
|
|
211
|
+
debug('stepzen:graphql2sdl')('expected the response from the JSON introspection service ' +
|
|
212
|
+
`to contain a \`${query.operation}\` object`);
|
|
213
|
+
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
214
|
+
}
|
|
215
|
+
const { config, sdl } = json.data[query.operation];
|
|
216
|
+
if (!config && !sdl) {
|
|
217
|
+
debug('stepzen:curl2sdl')('expected the response from the JSON introspection service ' +
|
|
218
|
+
`to contain at least one of \`${query.operation}.config\` or ` +
|
|
219
|
+
`\`${query.operation}.sdl\` properties`);
|
|
220
|
+
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
221
|
+
}
|
|
222
|
+
return { config, sdl };
|
|
223
|
+
};
|
|
224
|
+
exports.writeSdlAndConfig = async (name, source, onConflict, { config, sdl }) => {
|
|
225
|
+
// write out the generated config and schema files
|
|
226
|
+
const tmp = path.join(os.tmpdir(), `stepzen-introspection-${Date.now()}`);
|
|
227
|
+
fs.ensureDirSync(tmp);
|
|
228
|
+
// fs.ensureDirSync(path.join(tmp, subfolder))
|
|
229
|
+
if (config) {
|
|
230
|
+
fs.writeFileSync(path.join(tmp, 'config.yaml'), prettier.format(config, { parser: 'yaml' }));
|
|
231
|
+
}
|
|
232
|
+
if (sdl) {
|
|
233
|
+
fs.writeFileSync(path.join(tmp, 'index.graphql'), prettier.format(sdl, { parser: 'graphql' }));
|
|
234
|
+
}
|
|
235
|
+
const result = await transpiler.merge(source, {
|
|
236
|
+
name: name,
|
|
237
|
+
source: tmp,
|
|
238
|
+
}, {
|
|
239
|
+
answers: {},
|
|
240
|
+
output: null,
|
|
241
|
+
silent: true,
|
|
242
|
+
mergeTypes: false,
|
|
243
|
+
onConflict,
|
|
244
|
+
});
|
|
245
|
+
return { outPath: result };
|
|
246
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HeaderInput } from '
|
|
1
|
+
import { HeaderInput } from './header';
|
|
2
2
|
import { ParseError, CurlHeader } from './curl-parser';
|
|
3
3
|
export declare const parseHeaderParam: (headers: readonly CurlHeader[], headerParam: string) => {
|
|
4
4
|
header: HeaderInput;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare type NameValueHeaderInput = {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
};
|
|
5
|
+
export declare type NamePartsHeaderInput = {
|
|
6
|
+
name: string;
|
|
7
|
+
parts: HeaderInputValuePart[];
|
|
8
|
+
};
|
|
9
|
+
export declare type HeaderInput = NameValueHeaderInput | NamePartsHeaderInput;
|
|
10
|
+
export declare type HeaderInputConstantValuePart = {
|
|
11
|
+
kind: 'Constant';
|
|
12
|
+
value: string;
|
|
13
|
+
};
|
|
14
|
+
export declare type HeaderInputVariableValuePart = {
|
|
15
|
+
kind: 'Variable';
|
|
16
|
+
value: string;
|
|
17
|
+
name: string;
|
|
18
|
+
};
|
|
19
|
+
export declare type HeaderInputValuePart = HeaderInputConstantValuePart | HeaderInputVariableValuePart;
|
|
20
|
+
export declare const HEADER_REGEX: RegExp;
|
|
21
|
+
export declare const parseHeaderNameValue: (input: string) => NameValueHeaderInput | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.parseHeaderNameValue = exports.HEADER_REGEX = void 0;
|
|
5
|
+
exports.HEADER_REGEX = /([\w-]+): (.*)/;
|
|
6
|
+
exports.parseHeaderNameValue = (input) => {
|
|
7
|
+
const match = input.match(exports.HEADER_REGEX);
|
|
8
|
+
if (match) {
|
|
9
|
+
const [name, value] = match.splice(1, 2);
|
|
10
|
+
return { name, value };
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
};
|
package/lib/start/console.js
CHANGED
|
@@ -15,19 +15,34 @@ exports.success = ({ workspace, account, port, }) => {
|
|
|
15
15
|
const domain = constants_1.STEPZEN_DOMAIN.replace('.io', '.net');
|
|
16
16
|
const url = `https://${account}.${domain}/${workspace.endpoint}/__graphql`;
|
|
17
17
|
console.log();
|
|
18
|
-
console.log(chalk.grey(`Your API url is`, chalk.green(` ${url}`)));
|
|
19
|
-
console.log();
|
|
20
18
|
if (process.platform === 'win32') {
|
|
21
|
-
console.log(chalk.grey(`
|
|
19
|
+
console.log(chalk.grey(`In PowerShell you can test your hosted API with Invoke-WebRequest:`));
|
|
20
|
+
console.log();
|
|
21
|
+
console.log(`Invoke-WebRequest \``);
|
|
22
|
+
console.log(` -Uri ${url} \``);
|
|
23
|
+
console.log(` -Method "POST" \``);
|
|
24
|
+
console.log(` -Headers @{`);
|
|
25
|
+
console.log(` "Content-Type" = "application/json"`);
|
|
26
|
+
if (!account.startsWith('public')) {
|
|
27
|
+
console.log(` "Authorization" = "APIKey $(stepzen whoami --apikey)"`);
|
|
28
|
+
}
|
|
29
|
+
console.log(` } \``);
|
|
30
|
+
console.log(` -Body (@{`);
|
|
31
|
+
console.log(` "query" = '${chalk.bgYellow.black('your graphql query')}'`);
|
|
32
|
+
console.log(` } | ConvertTo-Json)`);
|
|
22
33
|
}
|
|
23
34
|
else {
|
|
24
35
|
console.log(chalk.grey(`You can test your hosted API with cURL:`));
|
|
25
36
|
console.log();
|
|
26
37
|
console.log(`curl ${url} \\`);
|
|
27
|
-
|
|
38
|
+
if (!account.startsWith('public')) {
|
|
39
|
+
console.log(` --header "Authorization: Apikey $(stepzen whoami --apikey)" \\`);
|
|
40
|
+
}
|
|
28
41
|
console.log(` --header "Content-Type: application/json" \\`);
|
|
29
|
-
console.log(` --data '{"query": "your graphql query"}'`);
|
|
30
|
-
console.log();
|
|
31
|
-
console.log(chalk.grey(`or explore it with GraphiQL at`), chalk.green(` http://localhost:${port}/${workspace.endpoint}`));
|
|
42
|
+
console.log(` --data '{"query": "${chalk.bgYellow.black('your graphql query')}"}'`);
|
|
32
43
|
}
|
|
44
|
+
console.log();
|
|
45
|
+
console.log(chalk.grey(`or explore it with GraphiQL at http://localhost:${port}/${workspace.endpoint}`));
|
|
46
|
+
console.log();
|
|
47
|
+
console.log(chalk.grey(`Your API url is ${chalk.green(url)}`));
|
|
33
48
|
};
|
package/lib/start/deploy.d.ts
CHANGED
package/lib/start/deploy.js
CHANGED
|
@@ -3,27 +3,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
5
5
|
const chalk = require("chalk");
|
|
6
|
+
const debug = require("debug");
|
|
6
7
|
const core_1 = require("@oclif/core");
|
|
8
|
+
const dotenv = require("dotenv");
|
|
7
9
|
const fs = require("fs-extra");
|
|
8
10
|
const path = require("path");
|
|
9
11
|
const prettyMilliseconds = require("pretty-ms");
|
|
10
12
|
const deploy_1 = require("../commands/deploy");
|
|
11
13
|
const upload_1 = require("../commands/upload");
|
|
12
14
|
const validate_1 = require("../commands/validate");
|
|
13
|
-
const dotenv = require('dotenv');
|
|
14
15
|
exports.default = async ({ workspace, flags, }) => {
|
|
15
16
|
var e_1, _a;
|
|
16
17
|
dotenv.config({ path: path.join(workspace.directory, '.env') });
|
|
17
18
|
if (!flags['no-validate']) {
|
|
19
|
+
const validateCmd = `stepzen validate ${workspace.schema}`;
|
|
18
20
|
try {
|
|
21
|
+
debug('stepzen:start')(`starting $(${validateCmd})`);
|
|
19
22
|
await validate_1.default.run([workspace.schema]);
|
|
23
|
+
debug('stepzen:start')(`$(${validateCmd}) completed successfully`);
|
|
20
24
|
}
|
|
21
25
|
catch (error) {
|
|
26
|
+
debug('stepzen:start')(`$(${validateCmd}) failed with`, error);
|
|
22
27
|
console.log();
|
|
23
28
|
console.log(chalk.red('Your local schema has the following GraphQL errors:'));
|
|
24
29
|
console.log();
|
|
25
30
|
console.log(error.message);
|
|
26
|
-
return;
|
|
31
|
+
return false;
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
core_1.CliUx.ux.action.start(`Deploying ${chalk.yellow(workspace.endpoint)} to StepZen`);
|
|
@@ -69,12 +74,17 @@ exports.default = async ({ workspace, flags, }) => {
|
|
|
69
74
|
try {
|
|
70
75
|
for (var uploadCmds_1 = tslib_1.__asyncValues(uploadCmds), uploadCmds_1_1; uploadCmds_1_1 = await uploadCmds_1.next(), !uploadCmds_1_1.done;) {
|
|
71
76
|
const cmd = uploadCmds_1_1.value;
|
|
77
|
+
const commandCmd = `stepzen upload '${cmd.join("' '")}'`;
|
|
72
78
|
try {
|
|
79
|
+
debug('stepzen:start')(`starting $(${commandCmd})`);
|
|
73
80
|
await upload_1.default.run(cmd);
|
|
81
|
+
debug('stepzen:start')(`$(${commandCmd}) completed successfully`);
|
|
74
82
|
}
|
|
75
83
|
catch (error) {
|
|
84
|
+
debug('stepzen:start')(`$(${commandCmd}) failed with`, error);
|
|
85
|
+
core_1.CliUx.ux.action.stop(chalk.red('fail'));
|
|
76
86
|
logError(error);
|
|
77
|
-
return;
|
|
87
|
+
return false;
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
}
|
|
@@ -85,14 +95,20 @@ exports.default = async ({ workspace, flags, }) => {
|
|
|
85
95
|
}
|
|
86
96
|
finally { if (e_1) throw e_1.error; }
|
|
87
97
|
}
|
|
98
|
+
const deployCmd = `stepzen deploy '${deployArgs.join("' '")}'`;
|
|
88
99
|
try {
|
|
100
|
+
debug('stepzen:start')(`starting $(${deployCmd})`);
|
|
89
101
|
await deploy_1.default.run(deployArgs);
|
|
102
|
+
debug('stepzen:start')(`$(${deployCmd}) completed successfully`);
|
|
90
103
|
}
|
|
91
104
|
catch (error) {
|
|
105
|
+
debug('stepzen:start')(`$(${deployCmd}) failed with`, error);
|
|
106
|
+
core_1.CliUx.ux.action.stop(chalk.red('fail'));
|
|
92
107
|
logError(error);
|
|
93
|
-
return;
|
|
108
|
+
return false;
|
|
94
109
|
}
|
|
95
110
|
const deployEnd = new Date().getTime();
|
|
96
111
|
const deployTime = deployEnd - deployStart;
|
|
97
112
|
core_1.CliUx.ux.action.stop(`${chalk.grey('done in')} ${prettyMilliseconds(deployTime)} 🚀`);
|
|
113
|
+
return true;
|
|
98
114
|
};
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.17.0-beta.1","commands":{"deploy":{"id":"deploy","description":"deploy to stepzen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"configurationsets":{"name":"configurationsets","type":"option","description":"Configurationsets to use","default":""},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"schema":{"name":"schema","type":"option","description":"Schema to use","required":true},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"destination","description":"destination","required":true}]},"import":{"id":"import","description":"import a schema for an external data source or a API endpoint to your GraphQL API","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"dir":{"name":"dir","type":"option","description":"working directory"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"silent":{"name":"silent","type":"boolean","hidden":true,"allowNo":false},"name":{"name":"name","type":"option","description":"Subfolder inside the workspace folder to save the imported schema files to. Defaults to the name of the imported schema."},"overwrite":{"name":"overwrite","type":"boolean","description":"Overwrite any existing schema with the same name. Cannot be used without also providing a --name flag.","allowNo":false},"prefix":{"name":"prefix","type":"option","description":"[curl] prefix to add every type in the generated schema."},"query-name":{"name":"query-name","type":"option","description":"[curl] property name to add to the Query type as a way to access the imported cURL endpoint."},"query-type":{"name":"query-type","type":"option","description":"[curl] name for the type returned by the cURL endpoint in the generated schema. The name specified by --query-type is not prefixed by --prefix if both flags are present."},"path-params":{"name":"path-params","type":"option","description":"[curl] specifies path parameters in the URL path. Can be formed by taking the original path and replacing the variable segments with $paramName placeholders.\n\nExample:\nstepzen import curl https://example.com/users/jane/posts/12 --path-params '/users/$userId/posts/$postId'"},"header-param":{"name":"header-param","type":"option","description":"[curl] specifies a parameter in a header value. Can be formed by taking a -H, --header flag and replacing the variable part of the header value with a $paramName placeholder. Repeat this flag once for each header with a parameter.\n\nExample:\nstepzen import curl https://example.com/api/customers \\\n\t-H \"Authorization: apikey SecretAPIKeyValue\" \\\n\t--header-param 'Authorization: apikey $apikey'"},"db-host":{"name":"db-host","type":"option","description":"[mysql, postgresql] database host"},"db-user":{"name":"db-user","type":"option","description":"[mysql, postgresql] database user name"},"db-password":{"name":"db-password","type":"option","description":"[mysql, postgresql] database password"},"db-database":{"name":"db-database","type":"option","description":"[mysql, postgresql] name of database to import"},"db-schema":{"name":"db-schema","type":"option","description":"[postgresql] database schema"}},"args":[{"name":"schema","required":true}]},"init":{"id":"init","description":"stepzen init","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"endpoint":{"name":"endpoint","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"yes":{"name":"yes","type":"boolean","hidden":true,"allowNo":false}},"args":[{"name":"directory","hidden":true}]},"lint":{"id":"lint","description":"StepZen lint","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"dir":{"name":"dir","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"list":{"id":"list","description":"list your items","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"type","description":"type","required":true,"options":["configurationsets","schemas"]}]},"login":{"id":"login","description":"log in to StepZen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"account":{"name":"account","type":"option","char":"a","hidden":true},"adminkey":{"name":"adminkey","type":"option","char":"k","hidden":true},"public":{"name":"public","type":"boolean","description":"Create a public anonymous StepZen account and use it. This is handy for trying StepZen out, but it not suitable for handling private data as all endpoints created with a public account will be public.","allowNo":false},"config":{"name":"config","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"logout":{"id":"logout","description":"log out of StepZen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"start":{"id":"start","description":"upload and deploy your schema","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"dir":{"name":"dir","type":"option","description":"working directory"},"endpoint":{"name":"endpoint","type":"option","description":"Override workspace endpoint"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"no-console":{"name":"no-console","type":"boolean","hidden":true,"allowNo":false},"no-dashboard":{"name":"no-dashboard","type":"boolean","hidden":true,"allowNo":false},"no-init":{"name":"no-init","type":"boolean","hidden":true,"allowNo":false},"no-validate":{"name":"no-validate","type":"boolean","hidden":true,"allowNo":false},"no-watcher":{"name":"no-watcher","type":"boolean","hidden":true,"allowNo":false},"port":{"name":"port","type":"option","default":5001}},"args":[]},"transpile":{"id":"transpile","description":"transpile a graphql schema","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"config":{"name":"config","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"hide-output":{"name":"hide-output","type":"boolean","hidden":true,"allowNo":false},"inspect":{"name":"inspect","type":"boolean","char":"i","hidden":true,"allowNo":false},"inspect-after":{"name":"inspect-after","type":"boolean","hidden":true,"allowNo":false},"output-configuration":{"name":"output-configuration","type":"boolean","allowNo":false},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"folder","required":true}]},"upload":{"id":"upload","description":"upload to StepZen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"dir":{"name":"dir","type":"option","description":"A directory to upload"},"file":{"name":"file","type":"option","description":"A file to upload"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"type","description":"type","required":true,"options":["configurationset","schema"]},{"name":"destination","description":"destination","required":true}]},"validate":{"id":"validate","description":"validate a graphql schema","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"folder","required":true}]},"whoami":{"id":"whoami","description":"display your credentials with StepZen whoami","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"showkeys":{"name":"showkeys","type":"boolean","allowNo":false},"apikey":{"name":"apikey","type":"boolean","allowNo":false},"adminkey":{"name":"adminkey","type":"boolean","allowNo":false}},"args":[]}}}
|
|
1
|
+
{"version":"0.17.0","commands":{"deploy":{"id":"deploy","description":"deploy to stepzen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"configurationsets":{"name":"configurationsets","type":"option","description":"Configurationsets to use","default":""},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"schema":{"name":"schema","type":"option","description":"Schema to use","required":true},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"destination","description":"destination","required":true}]},"import":{"id":"import","description":"import a schema for an external data source or a API endpoint to your GraphQL API","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"dir":{"name":"dir","type":"option","description":"working directory"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"silent":{"name":"silent","type":"boolean","hidden":true,"allowNo":false},"name":{"name":"name","type":"option","description":"Subfolder inside the workspace folder to save the imported schema files to. Defaults to the name of the imported schema."},"overwrite":{"name":"overwrite","type":"boolean","description":"Overwrite any existing schema with the same name. Cannot be used without also providing a --name flag.","hidden":true,"allowNo":false},"prefix":{"name":"prefix","type":"option","description":"[curl, graphql] prefix to add every type in the generated schema."},"query-name":{"name":"query-name","type":"option","description":"[curl] property name to add to the Query type as a way to access the imported cURL endpoint."},"query-type":{"name":"query-type","type":"option","description":"[curl] name for the type returned by the cURL endpoint in the generated schema. The name specified by \u001b[1m--query-type\u001b[22m is not prefixed by \u001b[1m--prefix\u001b[22m if both flags are present."},"path-params":{"name":"path-params","type":"option","description":"[curl] specifies path parameters in the URL path. Can be formed by taking the original path and replacing the variable segments with \u001b[1m$paramName\u001b[22m placeholders.\n\nExample:\nstepzen import curl https://example.com/users/jane/posts/12 --path-params '/users/\u001b[1m$userId\u001b[22m/posts/\u001b[1m$postId\u001b[22m'"},"header-param":{"name":"header-param","type":"option","description":"[curl] specifies a parameter in a header value. Can be formed by taking a \u001b[1m-H, --header\u001b[22m flag and replacing the variable part of the header value with a \u001b[1m$paramName\u001b[22m placeholder. Repeat this flag once for each header with a parameter.\n\nExample:\nstepzen import curl https://example.com/api/customers \\\n\t-H \"Authorization: apikey SecretAPIKeyValue\" \\\n\t--header-param 'Authorization: apikey \u001b[1m$apikey\u001b[22m'"},"db-host":{"name":"db-host","type":"option","description":"[mysql, postgresql] database host"},"db-user":{"name":"db-user","type":"option","description":"[mysql, postgresql] database user name"},"db-password":{"name":"db-password","type":"option","description":"[mysql, postgresql] database password"},"db-database":{"name":"db-database","type":"option","description":"[mysql, postgresql] name of database to import"},"db-schema":{"name":"db-schema","type":"option","description":"[postgresql] database schema"}},"args":[{"name":"schema","required":true}]},"init":{"id":"init","description":"stepzen init","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"endpoint":{"name":"endpoint","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"yes":{"name":"yes","type":"boolean","hidden":true,"allowNo":false}},"args":[{"name":"directory","hidden":true}]},"lint":{"id":"lint","description":"StepZen lint","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"dir":{"name":"dir","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"list":{"id":"list","description":"list your items","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"type","description":"type","required":true,"options":["configurationsets","schemas"]}]},"login":{"id":"login","description":"log in to StepZen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"account":{"name":"account","type":"option","char":"a","hidden":true},"adminkey":{"name":"adminkey","type":"option","char":"k","hidden":true},"public":{"name":"public","type":"boolean","description":"Create a public anonymous StepZen account and use it. This is handy for trying StepZen out, but it not suitable for handling private data as all endpoints created with a public account will be public.","allowNo":false},"config":{"name":"config","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"logout":{"id":"logout","description":"log out of StepZen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"start":{"id":"start","description":"upload and deploy your schema","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"dir":{"name":"dir","type":"option","description":"working directory"},"endpoint":{"name":"endpoint","type":"option","description":"Override workspace endpoint"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"no-console":{"name":"no-console","type":"boolean","hidden":true,"allowNo":false},"no-dashboard":{"name":"no-dashboard","type":"boolean","hidden":true,"allowNo":false},"no-init":{"name":"no-init","type":"boolean","hidden":true,"allowNo":false},"no-validate":{"name":"no-validate","type":"boolean","hidden":true,"allowNo":false},"no-watcher":{"name":"no-watcher","type":"boolean","hidden":true,"allowNo":false},"port":{"name":"port","type":"option","default":5001}},"args":[]},"transpile":{"id":"transpile","description":"transpile a graphql schema","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"config":{"name":"config","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"hide-output":{"name":"hide-output","type":"boolean","hidden":true,"allowNo":false},"inspect":{"name":"inspect","type":"boolean","char":"i","hidden":true,"allowNo":false},"inspect-after":{"name":"inspect-after","type":"boolean","hidden":true,"allowNo":false},"output-configuration":{"name":"output-configuration","type":"boolean","allowNo":false},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"folder","required":true}]},"upload":{"id":"upload","description":"upload to StepZen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"dir":{"name":"dir","type":"option","description":"A directory to upload"},"file":{"name":"file","type":"option","description":"A file to upload"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"type","description":"type","required":true,"options":["configurationset","schema"]},{"name":"destination","description":"destination","required":true}]},"validate":{"id":"validate","description":"validate a graphql schema","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"folder","required":true}]},"whoami":{"id":"whoami","description":"display your credentials with StepZen whoami","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"non-interactive":{"name":"non-interactive","type":"boolean","description":"disable all interactive prompts","hidden":true,"allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"showkeys":{"name":"showkeys","type":"boolean","allowNo":false},"apikey":{"name":"apikey","type":"boolean","allowNo":false},"adminkey":{"name":"adminkey","type":"boolean","allowNo":false}},"args":[]}}}
|