UNPKG

graphql-mocks

Version:

Tools for setting up graphql test resolvers

33 lines (31 loc) 1.51 kB
'use strict'; 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); } var graphql = require('graphql'); var constants = require('./constants.js'); class UnionHighlighter { constructor(targets) { _defineProperty(this, "targets", void 0); if (targets.length === 0) { targets = [constants.HIGHLIGHT_ALL]; } this.targets = targets; } mark(schema) { return UnionHighlighter.expandTargets(schema, this.targets); } static expandTargets(schema, targets) { const unionTypeNames = Object.values(schema.getTypeMap()).filter(graphql.isUnionType).map(union => union.name); if (targets.includes(constants.HIGHLIGHT_ALL)) { return unionTypeNames; } return unionTypeNames.filter(unionName => targets.includes(unionName)); } } const union = function type(...unionNames) { return new UnionHighlighter(unionNames); }; exports.UnionHighlighter = UnionHighlighter; exports.union = union; //# sourceMappingURL=union.js.map