Skip to content

Commit 98cbdd9

Browse files
author
Travis CI
committed
Deploy 4124b61 to NPM branch
1 parent 5b17cf9 commit 98cbdd9

File tree

3 files changed

+187
-163
lines changed

3 files changed

+187
-163
lines changed

type/definition.js

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,6 @@ function () {
494494

495495
_defineProperty(this, "isTypeOf", void 0);
496496

497-
_defineProperty(this, "_typeConfig", void 0);
498-
499497
_defineProperty(this, "_fields", void 0);
500498

501499
_defineProperty(this, "_interfaces", void 0);
@@ -505,7 +503,8 @@ function () {
505503
this.astNode = config.astNode;
506504
this.extensionASTNodes = config.extensionASTNodes;
507505
this.isTypeOf = config.isTypeOf;
508-
this._typeConfig = config;
506+
this._fields = defineFieldMap.bind(undefined, config);
507+
this._interfaces = defineInterfaces.bind(undefined, config);
509508
!(typeof config.name === 'string') ? (0, _invariant.default)(0, 'Must provide name.') : void 0;
510509

511510
if (config.isTypeOf) {
@@ -516,11 +515,19 @@ function () {
516515
var _proto2 = GraphQLObjectType.prototype;
517516

518517
_proto2.getFields = function getFields() {
519-
return this._fields || (this._fields = defineFieldMap(this, this._typeConfig.fields));
518+
if (typeof this._fields === 'function') {
519+
this._fields = this._fields();
520+
}
521+
522+
return this._fields;
520523
};
521524

522525
_proto2.getInterfaces = function getInterfaces() {
523-
return this._interfaces || (this._interfaces = defineInterfaces(this, this._typeConfig.interfaces));
526+
if (typeof this._interfaces === 'function') {
527+
this._interfaces = this._interfaces();
528+
}
529+
530+
return this._interfaces;
524531
};
525532

526533
_proto2.toString = function toString() {
@@ -535,33 +542,33 @@ exports.GraphQLObjectType = GraphQLObjectType;
535542
(0, _defineToStringTag.default)(GraphQLObjectType);
536543
(0, _defineToJSON.default)(GraphQLObjectType);
537544

538-
function defineInterfaces(type, interfacesThunk) {
539-
var interfaces = resolveThunk(interfacesThunk) || [];
540-
!Array.isArray(interfaces) ? (0, _invariant.default)(0, "".concat(type.name, " interfaces must be an Array or a function which returns ") + 'an Array.') : void 0;
545+
function defineInterfaces(config) {
546+
var interfaces = resolveThunk(config.interfaces) || [];
547+
!Array.isArray(interfaces) ? (0, _invariant.default)(0, "".concat(config.name, " interfaces must be an Array or a function which returns ") + 'an Array.') : void 0;
541548
return interfaces;
542549
}
543550

544-
function defineFieldMap(type, fieldsThunk) {
545-
var fieldMap = resolveThunk(fieldsThunk) || {};
546-
!isPlainObj(fieldMap) ? (0, _invariant.default)(0, "".concat(type.name, " fields must be an object with field names as keys or a ") + 'function which returns such an object.') : void 0;
551+
function defineFieldMap(config) {
552+
var fieldMap = resolveThunk(config.fields) || {};
553+
!isPlainObj(fieldMap) ? (0, _invariant.default)(0, "".concat(config.name, " fields must be an object with field names as keys or a ") + 'function which returns such an object.') : void 0;
547554
var resultFieldMap = Object.create(null);
548555
Object.keys(fieldMap).forEach(function (fieldName) {
549556
var fieldConfig = fieldMap[fieldName];
550-
!isPlainObj(fieldConfig) ? (0, _invariant.default)(0, "".concat(type.name, ".").concat(fieldName, " field config must be an object")) : void 0;
551-
!!fieldConfig.hasOwnProperty('isDeprecated') ? (0, _invariant.default)(0, "".concat(type.name, ".").concat(fieldName, " should provide \"deprecationReason\" instead ") + 'of "isDeprecated".') : void 0;
557+
!isPlainObj(fieldConfig) ? (0, _invariant.default)(0, "".concat(config.name, ".").concat(fieldName, " field config must be an object")) : void 0;
558+
!!fieldConfig.hasOwnProperty('isDeprecated') ? (0, _invariant.default)(0, "".concat(config.name, ".").concat(fieldName, " should provide \"deprecationReason\" ") + 'instead of "isDeprecated".') : void 0;
552559

553560
var field = _objectSpread({}, fieldConfig, {
554561
isDeprecated: Boolean(fieldConfig.deprecationReason),
555562
name: fieldName
556563
});
557564

558-
!isValidResolver(field.resolve) ? (0, _invariant.default)(0, "".concat(type.name, ".").concat(fieldName, " field resolver must be a function if ") + "provided, but got: ".concat((0, _inspect.default)(field.resolve), ".")) : void 0;
565+
!isValidResolver(field.resolve) ? (0, _invariant.default)(0, "".concat(config.name, ".").concat(fieldName, " field resolver must be a function if ") + "provided, but got: ".concat((0, _inspect.default)(field.resolve), ".")) : void 0;
559566
var argsConfig = fieldConfig.args;
560567

561568
if (!argsConfig) {
562569
field.args = [];
563570
} else {
564-
!isPlainObj(argsConfig) ? (0, _invariant.default)(0, "".concat(type.name, ".").concat(fieldName, " args must be an object with argument ") + 'names as keys.') : void 0;
571+
!isPlainObj(argsConfig) ? (0, _invariant.default)(0, "".concat(config.name, ".").concat(fieldName, " args must be an object with argument ") + 'names as keys.') : void 0;
565572
field.args = Object.keys(argsConfig).map(function (argName) {
566573
var arg = argsConfig[argName];
567574
return {
@@ -620,16 +627,14 @@ function () {
620627

621628
_defineProperty(this, "resolveType", void 0);
622629

623-
_defineProperty(this, "_typeConfig", void 0);
624-
625630
_defineProperty(this, "_fields", void 0);
626631

627632
this.name = config.name;
628633
this.description = config.description;
629634
this.astNode = config.astNode;
630635
this.extensionASTNodes = config.extensionASTNodes;
631636
this.resolveType = config.resolveType;
632-
this._typeConfig = config;
637+
this._fields = defineFieldMap.bind(undefined, config);
633638
!(typeof config.name === 'string') ? (0, _invariant.default)(0, 'Must provide name.') : void 0;
634639

635640
if (config.resolveType) {
@@ -640,7 +645,11 @@ function () {
640645
var _proto3 = GraphQLInterfaceType.prototype;
641646

642647
_proto3.getFields = function getFields() {
643-
return this._fields || (this._fields = defineFieldMap(this, this._typeConfig.fields));
648+
if (typeof this._fields === 'function') {
649+
this._fields = this._fields();
650+
}
651+
652+
return this._fields;
644653
};
645654

646655
_proto3.toString = function toString() {
@@ -692,16 +701,14 @@ function () {
692701

693702
_defineProperty(this, "resolveType", void 0);
694703

695-
_defineProperty(this, "_typeConfig", void 0);
696-
697704
_defineProperty(this, "_types", void 0);
698705

699706
this.name = config.name;
700707
this.description = config.description;
701708
this.astNode = config.astNode;
702709
this.extensionASTNodes = config.extensionASTNodes;
703710
this.resolveType = config.resolveType;
704-
this._typeConfig = config;
711+
this._types = defineTypes.bind(undefined, config);
705712
!(typeof config.name === 'string') ? (0, _invariant.default)(0, 'Must provide name.') : void 0;
706713

707714
if (config.resolveType) {
@@ -712,7 +719,11 @@ function () {
712719
var _proto4 = GraphQLUnionType.prototype;
713720

714721
_proto4.getTypes = function getTypes() {
715-
return this._types || (this._types = defineTypes(this, this._typeConfig.types));
722+
if (typeof this._types === 'function') {
723+
this._types = this._types();
724+
}
725+
726+
return this._types;
716727
};
717728

718729
_proto4.toString = function toString() {
@@ -727,9 +738,9 @@ exports.GraphQLUnionType = GraphQLUnionType;
727738
(0, _defineToStringTag.default)(GraphQLUnionType);
728739
(0, _defineToJSON.default)(GraphQLUnionType);
729740

730-
function defineTypes(unionType, typesThunk) {
731-
var types = resolveThunk(typesThunk) || [];
732-
!Array.isArray(types) ? (0, _invariant.default)(0, 'Must provide Array of types or a function which returns ' + "such an array for Union ".concat(unionType.name, ".")) : void 0;
741+
function defineTypes(config) {
742+
var types = resolveThunk(config.types) || [];
743+
!Array.isArray(types) ? (0, _invariant.default)(0, 'Must provide Array of types or a function which returns ' + "such an array for Union ".concat(config.name, ".")) : void 0;
733744
return types;
734745
}
735746

@@ -898,39 +909,24 @@ function () {
898909

899910
_defineProperty(this, "extensionASTNodes", void 0);
900911

901-
_defineProperty(this, "_typeConfig", void 0);
902-
903912
_defineProperty(this, "_fields", void 0);
904913

905914
this.name = config.name;
906915
this.description = config.description;
907916
this.astNode = config.astNode;
908917
this.extensionASTNodes = config.extensionASTNodes;
909-
this._typeConfig = config;
918+
this._fields = defineInputFieldMap.bind(undefined, config);
910919
!(typeof config.name === 'string') ? (0, _invariant.default)(0, 'Must provide name.') : void 0;
911920
}
912921

913922
var _proto6 = GraphQLInputObjectType.prototype;
914923

915924
_proto6.getFields = function getFields() {
916-
return this._fields || (this._fields = this._defineFieldMap());
917-
};
918-
919-
_proto6._defineFieldMap = function _defineFieldMap() {
920-
var _this = this;
921-
922-
var fieldMap = resolveThunk(this._typeConfig.fields) || {};
923-
!isPlainObj(fieldMap) ? (0, _invariant.default)(0, "".concat(this.name, " fields must be an object with field names as keys or a ") + 'function which returns such an object.') : void 0;
924-
var resultFieldMap = Object.create(null);
925-
Object.keys(fieldMap).forEach(function (fieldName) {
926-
var field = _objectSpread({}, fieldMap[fieldName], {
927-
name: fieldName
928-
});
925+
if (typeof this._fields === 'function') {
926+
this._fields = this._fields();
927+
}
929928

930-
!!field.hasOwnProperty('resolve') ? (0, _invariant.default)(0, "".concat(_this.name, ".").concat(fieldName, " field type has a resolve property, but ") + 'Input Types cannot define resolvers.') : void 0;
931-
resultFieldMap[fieldName] = field;
932-
});
933-
return resultFieldMap;
929+
return this._fields;
934930
};
935931

936932
_proto6.toString = function toString() {
@@ -943,4 +939,19 @@ function () {
943939

944940
exports.GraphQLInputObjectType = GraphQLInputObjectType;
945941
(0, _defineToStringTag.default)(GraphQLInputObjectType);
946-
(0, _defineToJSON.default)(GraphQLInputObjectType);
942+
(0, _defineToJSON.default)(GraphQLInputObjectType);
943+
944+
function defineInputFieldMap(config) {
945+
var fieldMap = resolveThunk(config.fields) || {};
946+
!isPlainObj(fieldMap) ? (0, _invariant.default)(0, "".concat(config.name, " fields must be an object with field names as keys or a ") + 'function which returns such an object.') : void 0;
947+
var resultFieldMap = Object.create(null);
948+
Object.keys(fieldMap).forEach(function (fieldName) {
949+
var field = _objectSpread({}, fieldMap[fieldName], {
950+
name: fieldName
951+
});
952+
953+
!!field.hasOwnProperty('resolve') ? (0, _invariant.default)(0, "".concat(config.name, ".").concat(fieldName, " field type has a resolve property, but ") + 'Input Types cannot define resolvers.') : void 0;
954+
resultFieldMap[fieldName] = field;
955+
});
956+
return resultFieldMap;
957+
}

0 commit comments

Comments
 (0)