UNPKG

1.1 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const graphql_tools_fork_1 = require("graphql-tools-fork");
4exports.prefixTransform = async ({ apiName, schema, config }) => {
5 let prefix = null;
6 if (config.prefix) {
7 prefix = config.prefix;
8 }
9 else if (apiName) {
10 prefix = `${apiName}_`;
11 }
12 if (!prefix) {
13 throw new Error(`Transform 'prefix' has missing config: prefix`);
14 }
15 const ignoreList = config.ignore || [];
16 const transforms = [];
17 transforms.push(new graphql_tools_fork_1.RenameTypes(typeName => ignoreList.includes(typeName) ? typeName : `${prefix}${typeName}`));
18 if (config.includeRootOperations) {
19 transforms.push(new graphql_tools_fork_1.RenameRootFields((typeName, fieldName) => ignoreList.includes(typeName) ||
20 ignoreList.includes(`${typeName}.${fieldName}`)
21 ? fieldName
22 : `${prefix}${fieldName}`));
23 }
24 return graphql_tools_fork_1.transformSchema(schema, transforms);
25};
26exports.default = exports.prefixTransform;
27//# sourceMappingURL=index.js.map
\No newline at end of file