UNPKG

1.45 kBJavaScriptView Raw
1Object.defineProperty(exports, "__esModule", { value: true });
2var graphql_1 = require("graphql");
3var _1 = require(".");
4function concatenateTypeDefs(typeDefinitionsAry, calledFunctionRefs) {
5 if (calledFunctionRefs === void 0) { calledFunctionRefs = []; }
6 var resolvedTypeDefinitions = [];
7 typeDefinitionsAry.forEach(function (typeDef) {
8 if (typeDef.kind !== undefined) {
9 typeDef = graphql_1.print(typeDef);
10 }
11 if (typeof typeDef === 'function') {
12 if (calledFunctionRefs.indexOf(typeDef) === -1) {
13 calledFunctionRefs.push(typeDef);
14 resolvedTypeDefinitions = resolvedTypeDefinitions.concat(concatenateTypeDefs(typeDef(), calledFunctionRefs));
15 }
16 }
17 else if (typeof typeDef === 'string') {
18 resolvedTypeDefinitions.push(typeDef.trim());
19 }
20 else {
21 var type = typeof typeDef;
22 throw new _1.SchemaError("typeDef array must contain only strings and functions, got " + type);
23 }
24 });
25 return uniq(resolvedTypeDefinitions.map(function (x) { return x.trim(); })).join('\n');
26}
27function uniq(array) {
28 return array.reduce(function (accumulator, currentValue) {
29 return accumulator.indexOf(currentValue) === -1
30 ? accumulator.concat([currentValue]) : accumulator;
31 }, []);
32}
33exports.default = concatenateTypeDefs;
34//# sourceMappingURL=concatenateTypeDefs.js.map
\No newline at end of file