UNPKG

936 BJavaScriptView Raw
1import { isListType, isNonNullType } from 'graphql';
2export function mergeOutputs(content) {
3 const result = { content: '', prepend: [], append: [] };
4 if (Array.isArray(content)) {
5 content.forEach(item => {
6 if (typeof item === 'string') {
7 result.content += item;
8 }
9 else {
10 result.content += item.content;
11 result.prepend.push(...(item.prepend || []));
12 result.append.push(...(item.append || []));
13 }
14 });
15 }
16 return [...result.prepend, result.content, ...result.append].join('\n');
17}
18export function isWrapperType(t) {
19 return isListType(t) || isNonNullType(t);
20}
21export function getBaseType(type) {
22 if (isWrapperType(type)) {
23 return getBaseType(type.ofType);
24 }
25 return type;
26}
27export function removeNonNullWrapper(type) {
28 return isNonNullType(type) ? type.ofType : type;
29}