UNPKG

graphql-codegen

Version:

Generate client code based on a GraphQL schema and query documents

40 lines (35 loc) 1.09 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.join = join; exports.block = block; exports.wrap = wrap; exports.indent = indent; // Code generation helper functions copied from graphql-js (https://github.com/graphql/graphql-js) /** * Given maybeArray, print an empty string if it is null or empty, otherwise * print all items together separated by separator if provided */ function join(maybeArray, separator) { return maybeArray ? maybeArray.filter(function (x) { return x; }).join(separator || '') : ''; } /** * Given array, print each item on its own line, wrapped in an * indented "{ }" block. */ function block(array) { return array && array.length !== 0 ? indent('{\n' + join(array, '\n')) + '\n}' : '{}'; } /** * If maybeString is not null or empty, then wrap with start and end, otherwise * print an empty string. */ function wrap(start, maybeString, end) { return maybeString ? start + maybeString + (end || '') : ''; } function indent(maybeString) { return maybeString && maybeString.replace(/\n/g, '\n '); }