1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | function writeForSchema(schema, licenseHeader, codegenDir, moduleName) {
|
13 | var typeMap = schema.getTypeMap();
|
14 | var stableTypeNames = Object.keys(typeMap).sort();
|
15 | var types = [];
|
16 | var _iteratorNormalCompletion = true;
|
17 | var _didIteratorError = false;
|
18 | var _iteratorError = undefined;
|
19 |
|
20 | try {
|
21 | for (var _iterator = stableTypeNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
22 | var name = _step.value;
|
23 | var type = typeMap[name];
|
24 |
|
25 | if (type instanceof require("graphql").GraphQLEnumType) {
|
26 | var values = type.getValues().map(function (_ref) {
|
27 | var value = _ref.value;
|
28 | return value;
|
29 | });
|
30 | values.sort();
|
31 | types.push("export type ".concat(name, " =\n | '") + values.join("'\n | '") + "'\n | '%future added value';");
|
32 | }
|
33 | }
|
34 | } catch (err) {
|
35 | _didIteratorError = true;
|
36 | _iteratorError = err;
|
37 | } finally {
|
38 | try {
|
39 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
40 | _iterator["return"]();
|
41 | }
|
42 | } finally {
|
43 | if (_didIteratorError) {
|
44 | throw _iteratorError;
|
45 | }
|
46 | }
|
47 | }
|
48 |
|
49 | var content = '/**\n' + licenseHeader.map(function (line) {
|
50 | return " * ".concat(line, "\n");
|
51 | }).join('') + ' *\n' + " * ".concat(require("signedsource").getSigningToken(), "\n") + ' * @flow\n' + ' */\n' + '\n' +
|
52 | '/*::\n' + types.join('\n\n') + '\n*/\n';
|
53 | codegenDir.writeFile(moduleName + '.js', require("signedsource").signFile(content));
|
54 | }
|
55 |
|
56 | module.exports = {
|
57 | writeForSchema: writeForSchema
|
58 | }; |
\ | No newline at end of file |