graphql-typescript-definitions
Version:
Generate TypeScript definition files from .graphql documents
55 lines (48 loc) • 2.11 kB
JavaScript
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
import { upperCaseFirst } from 'upper-case-first';
export var ObjectStack = /*#__PURE__*/function () {
function ObjectStack(type, field, parent) {
var isFragment = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
_classCallCheck(this, ObjectStack);
this.type = type;
this.field = field;
this.parent = parent;
this.isFragment = isFragment;
this.seenFields = new Set();
}
_createClass(ObjectStack, [{
key: "name",
get: function get() {
var parent = this.parent,
field = this.field,
isFragment = this.isFragment,
type = this.type;
var fieldName = field ? upperCaseFirst(field.responseName) : '';
var name = "".concat(parent ? parent.name : '').concat(fieldName);
return isFragment ? "".concat(name).concat(type ? type.name : 'Other') : name;
}
}, {
key: "nested",
value: function nested(field, type) {
return new ObjectStack(type, field, this);
}
}, {
key: "fragment",
value: function fragment(type) {
return new ObjectStack(type, this.field, this.parent, true);
}
}, {
key: "sawField",
value: function sawField(field) {
this.seenFields.add(field.responseName);
}
}, {
key: "hasSeenField",
value: function hasSeenField(field) {
return this.seenFields.has(field.responseName);
}
}]);
return ObjectStack;
}();