UNPKG

graphql-mocks

Version:

Tools for setting up graphql test resolvers

33 lines (32 loc) 1.57 kB
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import { isUnionType } from 'graphql'; import { HIGHLIGHT_ALL } from './constants.mjs'; class UnionHighlighter { constructor(targets) { _defineProperty(this, "targets", void 0); 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.mjs.map