@graphql-codegen/plugin-helpers
Version:
GraphQL Code Generator common utils and types
30 lines (29 loc) • 938 B
JavaScript
import { isListType, isNonNullType } from 'graphql';
export function mergeOutputs(content) {
const result = { content: '', prepend: [], append: [] };
if (Array.isArray(content)) {
for (const item of content) {
if (typeof item === 'string') {
result.content += item;
}
else {
result.content += item.content;
result.prepend.push(...(item.prepend || []));
result.append.push(...(item.append || []));
}
}
}
return [...result.prepend, result.content, ...result.append].join('\n');
}
export function isWrapperType(t) {
return isListType(t) || isNonNullType(t);
}
export function getBaseType(type) {
if (isWrapperType(type)) {
return getBaseType(type.ofType);
}
return type;
}
export function removeNonNullWrapper(type) {
return isNonNullType(type) ? type.ofType : type;
}