@graphql-codegen/java-common
Version:
GraphQL Code Generator utils library for developing Java plugins
34 lines (33 loc) • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stripIndent = exports.wrapTypeWithModifiers = exports.buildPackageNameFromPath = void 0;
const tslib_1 = require("tslib");
const graphql_1 = require("graphql");
const min_indent_1 = tslib_1.__importDefault(require("min-indent"));
const unixify_1 = tslib_1.__importDefault(require("unixify"));
function buildPackageNameFromPath(path) {
return (0, unixify_1.default)(path || '')
.replace(/src\/main\/.*?\//, '')
.replace(/\//g, '.');
}
exports.buildPackageNameFromPath = buildPackageNameFromPath;
function wrapTypeWithModifiers(baseType, typeNode, listType = 'Iterable') {
if (typeNode.kind === graphql_1.Kind.NON_NULL_TYPE) {
return wrapTypeWithModifiers(baseType, typeNode.type, listType);
}
if (typeNode.kind === graphql_1.Kind.LIST_TYPE) {
const innerType = wrapTypeWithModifiers(baseType, typeNode.type, listType);
return `${listType}<${innerType}>`;
}
return baseType;
}
exports.wrapTypeWithModifiers = wrapTypeWithModifiers;
function stripIndent(string) {
const indent = (0, min_indent_1.default)(string);
if (indent === 0) {
return string;
}
const regex = new RegExp(`^[ \\t]{${indent}}`, 'gm');
return string.replace(regex, '');
}
exports.stripIndent = stripIndent;