UNPKG

graphql-mocks

Version:
58 lines (41 loc) 1.72 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var constants = require('./constants.js'); class TypeHighlighter { constructor(targets) { if (targets.length === 0) { targets = [constants.HIGHLIGHT_ALL]; } this.targets = targets; } mark(schema) { return TypeHighlighter.expandTargets(schema, this.targets); } static expandTargets(schema, targets) { var _schema$getQueryType, _schema$getMutationTy; const allTypeNames = Object.keys(schema.getTypeMap()); if (targets.includes(constants.HIGHLIGHT_ALL)) { return allTypeNames; } const hasSpecialQueryTarget = targets.includes(constants.HIGHLIGHT_ROOT_QUERY); const hasSpecialMutationTarget = targets.includes(constants.HIGHLIGHT_ROOT_MUTATION); targets = targets.filter(target => target !== constants.HIGHLIGHT_ROOT_QUERY && target !== constants.HIGHLIGHT_ROOT_MUTATION); const queryTypeName = (_schema$getQueryType = schema.getQueryType()) === null || _schema$getQueryType === void 0 ? void 0 : _schema$getQueryType.name; if (queryTypeName && hasSpecialQueryTarget) { targets.push(queryTypeName); } const queryMutationName = (_schema$getMutationTy = schema.getMutationType()) === null || _schema$getMutationTy === void 0 ? void 0 : _schema$getMutationTy.name; if (queryMutationName && hasSpecialMutationTarget) { targets.push(queryMutationName); } return targets.filter(target => allTypeNames.includes(target)); } } const type = function type(...targetReferences) { return new TypeHighlighter(targetReferences); }; exports.TypeHighlighter = TypeHighlighter; exports.type = type; //# sourceMappingURL=type.js.map