UNPKG

graphql-mocks

Version:
39 lines (28 loc) 933 B
import { isUnionType } from 'graphql'; import { HIGHLIGHT_ALL } from './constants.js'; class UnionHighlighter { constructor(targets) { if (targets.length === 0) { targets = [HIGHLIGHT_ALL]; } this.targets = targets; } mark(schema) { return UnionHighlighter.expandTargets(schema, this.targets); } static expandTargets(schema, targets) { var unionTypeNames = Object.values(schema.getTypeMap()).filter(isUnionType).map(union => union.name); if (targets.includes(HIGHLIGHT_ALL)) { return unionTypeNames; } return unionTypeNames.filter(unionName => targets.includes(unionName)); } } var union = function type() { for (var _len = arguments.length, unionNames = new Array(_len), _key = 0; _key < _len; _key++) { unionNames[_key] = arguments[_key]; } return new UnionHighlighter(unionNames); }; export { UnionHighlighter, union }; //# sourceMappingURL=union.js.map