UNPKG

1.61 kBJavaScriptView Raw
1"use strict";
2var graphql_1 = require("graphql");
3var model_handler_1 = require("./model-handler");
4var operation_handler_1 = require("./operation-handler");
5var fragment_handler_1 = require("./fragment-handler");
6exports.prepareCodegen = function (schema, document, primitivesMap, config) {
7 if (primitivesMap === void 0) { primitivesMap = {}; }
8 if (config === void 0) { config = {}; }
9 var models = [];
10 var documents = [];
11 var typesMap = schema.getTypeMap();
12 Object.keys(typesMap).forEach(function (typeName) {
13 models.push.apply(models, model_handler_1.handleType(schema, primitivesMap, typesMap[typeName]));
14 });
15 if (!config.noDocuments) {
16 document.definitions.forEach(function (definition) {
17 switch (definition.kind) {
18 case graphql_1.Kind.OPERATION_DEFINITION:
19 documents.push(operation_handler_1.handleOperation(schema, definition, primitivesMap, config.flattenInnerTypes));
20 break;
21 case graphql_1.Kind.FRAGMENT_DEFINITION:
22 documents.push(fragment_handler_1.handleFragment(schema, definition, primitivesMap, config.flattenInnerTypes));
23 break;
24 default:
25 break;
26 }
27 });
28 }
29 return {
30 models: models.filter(function (item) {
31 if (item) {
32 return !(config.noSchema && !item.isEnum);
33 }
34 return false;
35 }),
36 documents: documents.filter(function (item) { return item; })
37 };
38};
39//# sourceMappingURL=codegen.js.map
\No newline at end of file