@graphql-tools/executor
Version:
Fork of GraphQL.js' execute function
28 lines (27 loc) • 626 B
JavaScript
/**
* Given [A, B, C] return 'A, B, or C'.
*
* @internal
*/
export function orList(items) {
return formatList('or', items);
}
/**
* Given [A, B, C] return 'A, B, and C'.
*
* @internal
*/
export function andList(items) {
return formatList('and', items);
}
function formatList(conjunction, items) {
switch (items.length) {
case 1:
return items[0];
case 2:
return items[0] + ' ' + conjunction + ' ' + items[1];
}
const allButLast = items.slice(0, -1);
const lastItem = items.at(-1);
return allButLast.join(', ') + ', ' + conjunction + ' ' + lastItem;
}