import { GraphQLList, GraphQLNamedType, GraphQLNonNull, GraphQLOutputType, isListType, isNonNullType, } from 'graphql'; import { Types } from './types.js'; export function mergeOutputs(content: Types.PluginOutput | Array): string { let mergedContent = ''; const prepend: Array = []; const append: Array = []; if (Array.isArray(content)) { for (const item of content) { if (typeof item === 'string') { mergedContent += item; } else { mergedContent += item.content; prepend.push(...(item.prepend || [])); append.push(...(item.append || [])); } } } return [...prepend, mergedContent, ...append].join('\n'); } export function isWrapperType(t: GraphQLOutputType): t is GraphQLNonNull | GraphQLList { return isListType(t) || isNonNullType(t); } export function getBaseType(type: GraphQLOutputType): GraphQLNamedType { if (isWrapperType(type)) { return getBaseType(type.ofType); } return type; } export function removeNonNullWrapper(type: GraphQLOutputType): GraphQLOutputType { return isNonNullType(type) ? type.ofType : type; }