@graphql-inspector/introspect-command 0.0.0-PLACEHOLDER
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/index.d.ts +14 -0
- package/index.js +83 -0
- package/index.mjs +79 -0
- package/package.json +48 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GlobalArgs, CommandFactory } from '@graphql-inspector/commands';
|
|
2
|
+
import { GraphQLSchema } from 'graphql';
|
|
3
|
+
export { CommandFactory };
|
|
4
|
+
export declare function handler({ schema: unsortedSchema, output, comments, }: {
|
|
5
|
+
schema: GraphQLSchema;
|
|
6
|
+
output: string;
|
|
7
|
+
comments: boolean;
|
|
8
|
+
}): void;
|
|
9
|
+
declare const _default: CommandFactory<{}, {
|
|
10
|
+
schema: string;
|
|
11
|
+
write?: string | undefined;
|
|
12
|
+
comments?: boolean | undefined;
|
|
13
|
+
} & GlobalArgs>;
|
|
14
|
+
export default _default;
|
package/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const tslib = require('tslib');
|
|
6
|
+
const commands = require('@graphql-inspector/commands');
|
|
7
|
+
const logger = require('@graphql-inspector/logger');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const graphql = require('graphql');
|
|
11
|
+
|
|
12
|
+
function handler({ schema: unsortedSchema, output, comments, }) {
|
|
13
|
+
const schema = graphql.lexicographicSortSchema(unsortedSchema);
|
|
14
|
+
const introspection = graphql.introspectionFromSchema(schema);
|
|
15
|
+
const filepath = path.resolve(process.cwd(), output);
|
|
16
|
+
let content;
|
|
17
|
+
switch (path.extname(output.toLowerCase())) {
|
|
18
|
+
case '.graphql':
|
|
19
|
+
case '.gql':
|
|
20
|
+
case '.gqls':
|
|
21
|
+
case '.graphqls':
|
|
22
|
+
content = graphql.printSchema(schema, {
|
|
23
|
+
commentDescriptions: comments,
|
|
24
|
+
});
|
|
25
|
+
break;
|
|
26
|
+
case '.json':
|
|
27
|
+
content = JSON.stringify(introspection, null, 2);
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
throw new Error('Only .graphql, .gql and .json files are supported');
|
|
31
|
+
}
|
|
32
|
+
fs.writeFileSync(output, content, {
|
|
33
|
+
encoding: 'utf-8',
|
|
34
|
+
});
|
|
35
|
+
logger.Logger.success(`Saved to ${filepath}`);
|
|
36
|
+
}
|
|
37
|
+
const index = commands.createCommand((api) => {
|
|
38
|
+
const { loaders } = api;
|
|
39
|
+
return {
|
|
40
|
+
command: 'introspect <schema>',
|
|
41
|
+
describe: 'Introspect a schema',
|
|
42
|
+
builder(yargs) {
|
|
43
|
+
return yargs
|
|
44
|
+
.positional('schema', {
|
|
45
|
+
describe: 'Point to a schema',
|
|
46
|
+
type: 'string',
|
|
47
|
+
demandOption: true,
|
|
48
|
+
})
|
|
49
|
+
.options({
|
|
50
|
+
w: {
|
|
51
|
+
alias: 'write',
|
|
52
|
+
describe: 'Write to a file',
|
|
53
|
+
type: 'string',
|
|
54
|
+
},
|
|
55
|
+
comments: {
|
|
56
|
+
describe: 'Use preceding comments as the description',
|
|
57
|
+
type: 'boolean',
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
.default('w', 'graphql.schema.json');
|
|
61
|
+
},
|
|
62
|
+
handler(args) {
|
|
63
|
+
var _a;
|
|
64
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const { headers, token } = commands.parseGlobalArgs(args);
|
|
66
|
+
const output = args.write;
|
|
67
|
+
const comments = args.comments || false;
|
|
68
|
+
const apolloFederation = args.federation || false;
|
|
69
|
+
const aws = args.aws || false;
|
|
70
|
+
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
|
|
71
|
+
const schema = yield loaders.loadSchema(args.schema, {
|
|
72
|
+
token,
|
|
73
|
+
headers,
|
|
74
|
+
method,
|
|
75
|
+
}, apolloFederation, aws);
|
|
76
|
+
return handler({ schema, output, comments });
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
exports.default = index;
|
|
83
|
+
exports.handler = handler;
|
package/index.mjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { createCommand, parseGlobalArgs } from '@graphql-inspector/commands';
|
|
3
|
+
import { Logger } from '@graphql-inspector/logger';
|
|
4
|
+
import { writeFileSync } from 'fs';
|
|
5
|
+
import { resolve, extname } from 'path';
|
|
6
|
+
import { lexicographicSortSchema, introspectionFromSchema, printSchema } from 'graphql';
|
|
7
|
+
|
|
8
|
+
function handler({ schema: unsortedSchema, output, comments, }) {
|
|
9
|
+
const schema = lexicographicSortSchema(unsortedSchema);
|
|
10
|
+
const introspection = introspectionFromSchema(schema);
|
|
11
|
+
const filepath = resolve(process.cwd(), output);
|
|
12
|
+
let content;
|
|
13
|
+
switch (extname(output.toLowerCase())) {
|
|
14
|
+
case '.graphql':
|
|
15
|
+
case '.gql':
|
|
16
|
+
case '.gqls':
|
|
17
|
+
case '.graphqls':
|
|
18
|
+
content = printSchema(schema, {
|
|
19
|
+
commentDescriptions: comments,
|
|
20
|
+
});
|
|
21
|
+
break;
|
|
22
|
+
case '.json':
|
|
23
|
+
content = JSON.stringify(introspection, null, 2);
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error('Only .graphql, .gql and .json files are supported');
|
|
27
|
+
}
|
|
28
|
+
writeFileSync(output, content, {
|
|
29
|
+
encoding: 'utf-8',
|
|
30
|
+
});
|
|
31
|
+
Logger.success(`Saved to ${filepath}`);
|
|
32
|
+
}
|
|
33
|
+
const index = createCommand((api) => {
|
|
34
|
+
const { loaders } = api;
|
|
35
|
+
return {
|
|
36
|
+
command: 'introspect <schema>',
|
|
37
|
+
describe: 'Introspect a schema',
|
|
38
|
+
builder(yargs) {
|
|
39
|
+
return yargs
|
|
40
|
+
.positional('schema', {
|
|
41
|
+
describe: 'Point to a schema',
|
|
42
|
+
type: 'string',
|
|
43
|
+
demandOption: true,
|
|
44
|
+
})
|
|
45
|
+
.options({
|
|
46
|
+
w: {
|
|
47
|
+
alias: 'write',
|
|
48
|
+
describe: 'Write to a file',
|
|
49
|
+
type: 'string',
|
|
50
|
+
},
|
|
51
|
+
comments: {
|
|
52
|
+
describe: 'Use preceding comments as the description',
|
|
53
|
+
type: 'boolean',
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
.default('w', 'graphql.schema.json');
|
|
57
|
+
},
|
|
58
|
+
handler(args) {
|
|
59
|
+
var _a;
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const { headers, token } = parseGlobalArgs(args);
|
|
62
|
+
const output = args.write;
|
|
63
|
+
const comments = args.comments || false;
|
|
64
|
+
const apolloFederation = args.federation || false;
|
|
65
|
+
const aws = args.aws || false;
|
|
66
|
+
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
|
|
67
|
+
const schema = yield loaders.loadSchema(args.schema, {
|
|
68
|
+
token,
|
|
69
|
+
headers,
|
|
70
|
+
method,
|
|
71
|
+
}, apolloFederation, aws);
|
|
72
|
+
return handler({ schema, output, comments });
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export default index;
|
|
79
|
+
export { handler };
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphql-inspector/introspect-command",
|
|
3
|
+
"version": "0.0.0-PLACEHOLDER",
|
|
4
|
+
"description": "Introspects GraphQL Schema",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@graphql-inspector/commands": "0.0.0-PLACEHOLDER",
|
|
11
|
+
"@graphql-inspector/core": "0.0.0-PLACEHOLDER",
|
|
12
|
+
"@graphql-inspector/logger": "0.0.0-PLACEHOLDER",
|
|
13
|
+
"tslib": "^2.0.0"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "kamilkisiela/graphql-inspector",
|
|
18
|
+
"directory": "packages/commands/introspect"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"graphql",
|
|
22
|
+
"graphql-inspector",
|
|
23
|
+
"graphql-inspector-command",
|
|
24
|
+
"tools"
|
|
25
|
+
],
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "Kamil Kisiela",
|
|
28
|
+
"email": "kamil.kisiela@gmail.com",
|
|
29
|
+
"url": "https://github.com/kamilkisiela"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"main": "index.js",
|
|
33
|
+
"module": "index.mjs",
|
|
34
|
+
"typings": "index.d.ts",
|
|
35
|
+
"typescript": {
|
|
36
|
+
"definition": "index.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"require": "./index.js",
|
|
41
|
+
"import": "./index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./*": {
|
|
44
|
+
"require": "./*.js",
|
|
45
|
+
"import": "./*.mjs"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|