1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 | "use strict";
|
5 |
|
6 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
7 |
|
8 | var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
9 |
|
10 | var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
11 |
|
12 | require('@babel/register')({
|
13 | ignore: [/node_modules\/(?!@kiwicom)/],
|
14 | rootMode: 'upward'
|
15 | });
|
16 |
|
17 | var fs = require('fs');
|
18 |
|
19 | var path = require('path');
|
20 |
|
21 | var program = require('commander');
|
22 |
|
23 | var fetch = require('@kiwicom/fetch').default;
|
24 |
|
25 | var logger = require('@kiwicom/logger').default;
|
26 |
|
27 | var SignedSource = require('@kiwicom/signed-source').default;
|
28 |
|
29 | var _require = require('graphql'),
|
30 | lexicographicSortSchema = _require.lexicographicSortSchema;
|
31 |
|
32 | var _require2 = require('graphql/utilities'),
|
33 | buildClientSchema = _require2.buildClientSchema,
|
34 | getIntrospectionQuery = _require2.getIntrospectionQuery,
|
35 | printSchema = _require2.printSchema;
|
36 |
|
37 | program.option('--resource <url>', undefined, 'https://graphql.kiwi.com/').option('--filename <path>', undefined, 'schema.graphql').parse(process.argv);
|
38 | var filename = path.join(process.cwd(), program.filename);
|
39 | (0, _asyncToGenerator2.default)(
|
40 |
|
41 | _regenerator.default.mark(function _callee() {
|
42 | var response, schemaJSON, clientSchema, schema;
|
43 | return _regenerator.default.wrap(function _callee$(_context) {
|
44 | while (1) {
|
45 | switch (_context.prev = _context.next) {
|
46 | case 0:
|
47 | _context.next = 2;
|
48 | return fetch(program.resource, {
|
49 | method: 'POST',
|
50 | headers: {
|
51 | Accept: 'application/json',
|
52 | 'Content-Type': 'application/json',
|
53 | 'X-Client': '@kiwicom/relay schema fetcher'
|
54 | },
|
55 | body: JSON.stringify({
|
56 | query: getIntrospectionQuery()
|
57 | })
|
58 | });
|
59 |
|
60 | case 2:
|
61 | response = _context.sent;
|
62 | _context.next = 5;
|
63 | return response.json();
|
64 |
|
65 | case 5:
|
66 | schemaJSON = _context.sent;
|
67 | clientSchema = printSchema(lexicographicSortSchema(buildClientSchema(schemaJSON.data)));
|
68 | schema = SignedSource.signFile("# ".concat(SignedSource.getSigningToken(), "\n\n").concat(clientSchema, "\n"));
|
69 | fs.writeFileSync(filename, schema);
|
70 | logger.log('GraphQL schema saved to: %s', filename);
|
71 |
|
72 | case 10:
|
73 | case "end":
|
74 | return _context.stop();
|
75 | }
|
76 | }
|
77 | }, _callee);
|
78 | }))(); |
\ | No newline at end of file |