| "use strict"; |
| |
| Object.defineProperty(exports, "__esModule", { |
| value: true |
| }); |
| exports.isType = isType; |
| exports.assertType = assertType; |
| exports.isScalarType = isScalarType; |
| exports.assertScalarType = assertScalarType; |
| exports.isObjectType = isObjectType; |
| exports.assertObjectType = assertObjectType; |
| exports.isInterfaceType = isInterfaceType; |
| exports.assertInterfaceType = assertInterfaceType; |
| exports.isUnionType = isUnionType; |
| exports.assertUnionType = assertUnionType; |
| exports.isEnumType = isEnumType; |
| exports.assertEnumType = assertEnumType; |
| exports.isInputObjectType = isInputObjectType; |
| exports.assertInputObjectType = assertInputObjectType; |
| exports.isListType = isListType; |
| exports.assertListType = assertListType; |
| exports.isNonNullType = isNonNullType; |
| exports.assertNonNullType = assertNonNullType; |
| exports.isInputType = isInputType; |
| exports.assertInputType = assertInputType; |
| exports.isOutputType = isOutputType; |
| exports.assertOutputType = assertOutputType; |
| exports.isLeafType = isLeafType; |
| exports.assertLeafType = assertLeafType; |
| exports.isCompositeType = isCompositeType; |
| exports.assertCompositeType = assertCompositeType; |
| exports.isAbstractType = isAbstractType; |
| exports.assertAbstractType = assertAbstractType; |
| exports.GraphQLList = GraphQLList; |
| exports.GraphQLNonNull = GraphQLNonNull; |
| exports.isWrappingType = isWrappingType; |
| exports.assertWrappingType = assertWrappingType; |
| exports.isNullableType = isNullableType; |
| exports.assertNullableType = assertNullableType; |
| exports.getNullableType = getNullableType; |
| exports.isNamedType = isNamedType; |
| exports.assertNamedType = assertNamedType; |
| exports.getNamedType = getNamedType; |
| exports.argsToArgsConfig = argsToArgsConfig; |
| exports.isRequiredArgument = isRequiredArgument; |
| exports.isRequiredInputField = isRequiredInputField; |
| exports.GraphQLInputObjectType = exports.GraphQLEnumType = exports.GraphQLUnionType = exports.GraphQLInterfaceType = exports.GraphQLObjectType = exports.GraphQLScalarType = void 0; |
| |
| var _objectEntries = _interopRequireDefault(require("../polyfills/objectEntries")); |
| |
| var _symbols = require("../polyfills/symbols"); |
| |
| var _inspect = _interopRequireDefault(require("../jsutils/inspect")); |
| |
| var _keyMap = _interopRequireDefault(require("../jsutils/keyMap")); |
| |
| var _mapValue = _interopRequireDefault(require("../jsutils/mapValue")); |
| |
| var _toObjMap = _interopRequireDefault(require("../jsutils/toObjMap")); |
| |
| var _devAssert = _interopRequireDefault(require("../jsutils/devAssert")); |
| |
| var _keyValMap = _interopRequireDefault(require("../jsutils/keyValMap")); |
| |
| var _instanceOf = _interopRequireDefault(require("../jsutils/instanceOf")); |
| |
| var _didYouMean = _interopRequireDefault(require("../jsutils/didYouMean")); |
| |
| var _isObjectLike = _interopRequireDefault(require("../jsutils/isObjectLike")); |
| |
| var _identityFunc = _interopRequireDefault(require("../jsutils/identityFunc")); |
| |
| var _defineToJSON = _interopRequireDefault(require("../jsutils/defineToJSON")); |
| |
| var _suggestionList = _interopRequireDefault(require("../jsutils/suggestionList")); |
| |
| var _kinds = require("../language/kinds"); |
| |
| var _printer = require("../language/printer"); |
| |
| var _GraphQLError = require("../error/GraphQLError"); |
| |
| var _valueFromASTUntyped = require("../utilities/valueFromASTUntyped"); |
| |
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
| |
| 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; } |
| |
| function isType(type) { |
| return isScalarType(type) || isObjectType(type) || isInterfaceType(type) || isUnionType(type) || isEnumType(type) || isInputObjectType(type) || isListType(type) || isNonNullType(type); |
| } |
| |
| function assertType(type) { |
| if (!isType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL type.")); |
| } |
| |
| return type; |
| } |
| /** |
| * There are predicates for each kind of GraphQL type. |
| */ |
| |
| |
| // eslint-disable-next-line no-redeclare |
| function isScalarType(type) { |
| return (0, _instanceOf.default)(type, GraphQLScalarType); |
| } |
| |
| function assertScalarType(type) { |
| if (!isScalarType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Scalar type.")); |
| } |
| |
| return type; |
| } |
| |
| // eslint-disable-next-line no-redeclare |
| function isObjectType(type) { |
| return (0, _instanceOf.default)(type, GraphQLObjectType); |
| } |
| |
| function assertObjectType(type) { |
| if (!isObjectType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Object type.")); |
| } |
| |
| return type; |
| } |
| |
| // eslint-disable-next-line no-redeclare |
| function isInterfaceType(type) { |
| return (0, _instanceOf.default)(type, GraphQLInterfaceType); |
| } |
| |
| function assertInterfaceType(type) { |
| if (!isInterfaceType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Interface type.")); |
| } |
| |
| return type; |
| } |
| |
| // eslint-disable-next-line no-redeclare |
| function isUnionType(type) { |
| return (0, _instanceOf.default)(type, GraphQLUnionType); |
| } |
| |
| function assertUnionType(type) { |
| if (!isUnionType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Union type.")); |
| } |
| |
| return type; |
| } |
| |
| // eslint-disable-next-line no-redeclare |
| function isEnumType(type) { |
| return (0, _instanceOf.default)(type, GraphQLEnumType); |
| } |
| |
| function assertEnumType(type) { |
| if (!isEnumType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Enum type.")); |
| } |
| |
| return type; |
| } |
| |
| // eslint-disable-next-line no-redeclare |
| function isInputObjectType(type) { |
| return (0, _instanceOf.default)(type, GraphQLInputObjectType); |
| } |
| |
| function assertInputObjectType(type) { |
| if (!isInputObjectType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Input Object type.")); |
| } |
| |
| return type; |
| } |
| |
| // eslint-disable-next-line no-redeclare |
| function isListType(type) { |
| return (0, _instanceOf.default)(type, GraphQLList); |
| } |
| |
| function assertListType(type) { |
| if (!isListType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL List type.")); |
| } |
| |
| return type; |
| } |
| |
| // eslint-disable-next-line no-redeclare |
| function isNonNullType(type) { |
| return (0, _instanceOf.default)(type, GraphQLNonNull); |
| } |
| |
| function assertNonNullType(type) { |
| if (!isNonNullType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Non-Null type.")); |
| } |
| |
| return type; |
| } |
| /** |
| * These types may be used as input types for arguments and directives. |
| */ |
| |
| |
| function isInputType(type) { |
| return isScalarType(type) || isEnumType(type) || isInputObjectType(type) || isWrappingType(type) && isInputType(type.ofType); |
| } |
| |
| function assertInputType(type) { |
| if (!isInputType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL input type.")); |
| } |
| |
| return type; |
| } |
| /** |
| * These types may be used as output types as the result of fields. |
| */ |
| |
| |
| function isOutputType(type) { |
| return isScalarType(type) || isObjectType(type) || isInterfaceType(type) || isUnionType(type) || isEnumType(type) || isWrappingType(type) && isOutputType(type.ofType); |
| } |
| |
| function assertOutputType(type) { |
| if (!isOutputType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL output type.")); |
| } |
| |
| return type; |
| } |
| /** |
| * These types may describe types which may be leaf values. |
| */ |
| |
| |
| function isLeafType(type) { |
| return isScalarType(type) || isEnumType(type); |
| } |
| |
| function assertLeafType(type) { |
| if (!isLeafType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL leaf type.")); |
| } |
| |
| return type; |
| } |
| /** |
| * These types may describe the parent context of a selection set. |
| */ |
| |
| |
| function isCompositeType(type) { |
| return isObjectType(type) || isInterfaceType(type) || isUnionType(type); |
| } |
| |
| function assertCompositeType(type) { |
| if (!isCompositeType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL composite type.")); |
| } |
| |
| return type; |
| } |
| /** |
| * These types may describe the parent context of a selection set. |
| */ |
| |
| |
| function isAbstractType(type) { |
| return isInterfaceType(type) || isUnionType(type); |
| } |
| |
| function assertAbstractType(type) { |
| if (!isAbstractType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL abstract type.")); |
| } |
| |
| return type; |
| } |
| /** |
| * List Type Wrapper |
| * |
| * A list is a wrapping type which points to another type. |
| * Lists are often created within the context of defining the fields of |
| * an object type. |
| * |
| * Example: |
| * |
| * const PersonType = new GraphQLObjectType({ |
| * name: 'Person', |
| * fields: () => ({ |
| * parents: { type: GraphQLList(PersonType) }, |
| * children: { type: GraphQLList(PersonType) }, |
| * }) |
| * }) |
| * |
| */ |
| // FIXME: workaround to fix issue with Babel parser |
| |
| /* :: |
| declare class GraphQLList<+T: GraphQLType> { |
| +ofType: T; |
| static <T>(ofType: T): GraphQLList<T>; |
| // Note: constructors cannot be used for covariant types. Drop the "new". |
| constructor(ofType: GraphQLType): void; |
| } |
| */ |
| |
| |
| function GraphQLList(ofType) { |
| if (this instanceof GraphQLList) { |
| this.ofType = assertType(ofType); |
| } else { |
| return new GraphQLList(ofType); |
| } |
| } // Need to cast through any to alter the prototype. |
| |
| |
| GraphQLList.prototype.toString = function toString() { |
| return '[' + String(this.ofType) + ']'; |
| }; |
| |
| Object.defineProperty(GraphQLList.prototype, _symbols.SYMBOL_TO_STRING_TAG, { |
| get: function get() { |
| return 'GraphQLList'; |
| } |
| }); |
| (0, _defineToJSON.default)(GraphQLList); |
| /** |
| * Non-Null Type Wrapper |
| * |
| * A non-null is a wrapping type which points to another type. |
| * Non-null types enforce that their values are never null and can ensure |
| * an error is raised if this ever occurs during a request. It is useful for |
| * fields which you can make a strong guarantee on non-nullability, for example |
| * usually the id field of a database row will never be null. |
| * |
| * Example: |
| * |
| * const RowType = new GraphQLObjectType({ |
| * name: 'Row', |
| * fields: () => ({ |
| * id: { type: GraphQLNonNull(GraphQLString) }, |
| * }) |
| * }) |
| * |
| * Note: the enforcement of non-nullability occurs within the executor. |
| */ |
| // FIXME: workaround to fix issue with Babel parser |
| |
| /* :: |
| declare class GraphQLNonNull<+T: GraphQLNullableType> { |
| +ofType: T; |
| static <T>(ofType: T): GraphQLNonNull<T>; |
| // Note: constructors cannot be used for covariant types. Drop the "new". |
| constructor(ofType: GraphQLType): void; |
| } |
| */ |
| |
| function GraphQLNonNull(ofType) { |
| if (this instanceof GraphQLNonNull) { |
| this.ofType = assertNullableType(ofType); |
| } else { |
| return new GraphQLNonNull(ofType); |
| } |
| } // Need to cast through any to alter the prototype. |
| |
| |
| GraphQLNonNull.prototype.toString = function toString() { |
| return String(this.ofType) + '!'; |
| }; |
| |
| Object.defineProperty(GraphQLNonNull.prototype, _symbols.SYMBOL_TO_STRING_TAG, { |
| get: function get() { |
| return 'GraphQLNonNull'; |
| } |
| }); |
| (0, _defineToJSON.default)(GraphQLNonNull); |
| /** |
| * These types wrap and modify other types |
| */ |
| |
| function isWrappingType(type) { |
| return isListType(type) || isNonNullType(type); |
| } |
| |
| function assertWrappingType(type) { |
| if (!isWrappingType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL wrapping type.")); |
| } |
| |
| return type; |
| } |
| /** |
| * These types can all accept null as a value. |
| */ |
| |
| |
| function isNullableType(type) { |
| return isType(type) && !isNonNullType(type); |
| } |
| |
| function assertNullableType(type) { |
| if (!isNullableType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL nullable type.")); |
| } |
| |
| return type; |
| } |
| /* eslint-disable no-redeclare */ |
| |
| |
| function getNullableType(type) { |
| /* eslint-enable no-redeclare */ |
| if (type) { |
| return isNonNullType(type) ? type.ofType : type; |
| } |
| } |
| /** |
| * These named types do not include modifiers like List or NonNull. |
| */ |
| |
| |
| function isNamedType(type) { |
| return isScalarType(type) || isObjectType(type) || isInterfaceType(type) || isUnionType(type) || isEnumType(type) || isInputObjectType(type); |
| } |
| |
| function assertNamedType(type) { |
| if (!isNamedType(type)) { |
| throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL named type.")); |
| } |
| |
| return type; |
| } |
| /* eslint-disable no-redeclare */ |
| |
| |
| function getNamedType(type) { |
| /* eslint-enable no-redeclare */ |
| if (type) { |
| var unwrappedType = type; |
| |
| while (isWrappingType(unwrappedType)) { |
| unwrappedType = unwrappedType.ofType; |
| } |
| |
| return unwrappedType; |
| } |
| } |
| /** |
| * Used while defining GraphQL types to allow for circular references in |
| * otherwise immutable type definitions. |
| */ |
| |
| |
| function resolveThunk(thunk) { |
| // $FlowFixMe(>=0.90.0) |
| return typeof thunk === 'function' ? thunk() : thunk; |
| } |
| |
| function undefineIfEmpty(arr) { |
| return arr && arr.length > 0 ? arr : undefined; |
| } |
| /** |
| * Scalar Type Definition |
| * |
| * The leaf values of any request and input values to arguments are |
| * Scalars (or Enums) and are defined with a name and a series of functions |
| * used to parse input from ast or variables and to ensure validity. |
| * |
| * If a type's serialize function does not return a value (i.e. it returns |
| * `undefined`) then an error will be raised and a `null` value will be returned |
| * in the response. If the serialize function returns `null`, then no error will |
| * be included in the response. |
| * |
| * Example: |
| * |
| * const OddType = new GraphQLScalarType({ |
| * name: 'Odd', |
| * serialize(value) { |
| * if (value % 2 === 1) { |
| * return value; |
| * } |
| * } |
| * }); |
| * |
| */ |
| |
| |
| var GraphQLScalarType = |
| /*#__PURE__*/ |
| function () { |
| function GraphQLScalarType(config) { |
| var _config$parseValue, _config$serialize, _config$parseLiteral; |
| |
| var parseValue = (_config$parseValue = config.parseValue) !== null && _config$parseValue !== void 0 ? _config$parseValue : _identityFunc.default; |
| this.name = config.name; |
| this.description = config.description; |
| this.serialize = (_config$serialize = config.serialize) !== null && _config$serialize !== void 0 ? _config$serialize : _identityFunc.default; |
| this.parseValue = parseValue; |
| this.parseLiteral = (_config$parseLiteral = config.parseLiteral) !== null && _config$parseLiteral !== void 0 ? _config$parseLiteral : function (node) { |
| return parseValue((0, _valueFromASTUntyped.valueFromASTUntyped)(node)); |
| }; |
| this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions); |
| this.astNode = config.astNode; |
| this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes); |
| typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.'); |
| config.serialize == null || typeof config.serialize === 'function' || (0, _devAssert.default)(0, "".concat(this.name, " must provide \"serialize\" function. If this custom Scalar is also used as an input type, ensure \"parseValue\" and \"parseLiteral\" functions are also provided.")); |
| |
| if (config.parseLiteral) { |
| typeof config.parseValue === 'function' && typeof config.parseLiteral === 'function' || (0, _devAssert.default)(0, "".concat(this.name, " must provide both \"parseValue\" and \"parseLiteral\" functions.")); |
| } |
| } |
| |
| var _proto = GraphQLScalarType.prototype; |
| |
| _proto.toConfig = function toConfig() { |
| var _this$extensionASTNod; |
| |
| return { |
| name: this.name, |
| description: this.description, |
| serialize: this.serialize, |
| parseValue: this.parseValue, |
| parseLiteral: this.parseLiteral, |
| extensions: this.extensions, |
| astNode: this.astNode, |
| extensionASTNodes: (_this$extensionASTNod = this.extensionASTNodes) !== null && _this$extensionASTNod !== void 0 ? _this$extensionASTNod : [] |
| }; |
| }; |
| |
| _proto.toString = function toString() { |
| return this.name; |
| } // $FlowFixMe Flow doesn't support computed properties yet |
| ; |
| |
| _createClass(GraphQLScalarType, [{ |
| key: _symbols.SYMBOL_TO_STRING_TAG, |
| get: function get() { |
| return 'GraphQLScalarType'; |
| } |
| }]); |
| |
| return GraphQLScalarType; |
| }(); |
| |
| exports.GraphQLScalarType = GraphQLScalarType; |
| (0, _defineToJSON.default)(GraphQLScalarType); |
| |
| /** |
| * Object Type Definition |
| * |
| * Almost all of the GraphQL types you define will be object types. Object types |
| * have a name, but most importantly describe their fields. |
| * |
| * Example: |
| * |
| * const AddressType = new GraphQLObjectType({ |
| * name: 'Address', |
| * fields: { |
| * street: { type: GraphQLString }, |
| * number: { type: GraphQLInt }, |
| * formatted: { |
| * type: GraphQLString, |
| * resolve(obj) { |
| * return obj.number + ' ' + obj.street |
| * } |
| * } |
| * } |
| * }); |
| * |
| * When two types need to refer to each other, or a type needs to refer to |
| * itself in a field, you can use a function expression (aka a closure or a |
| * thunk) to supply the fields lazily. |
| * |
| * Example: |
| * |
| * const PersonType = new GraphQLObjectType({ |
| * name: 'Person', |
| * fields: () => ({ |
| * name: { type: GraphQLString }, |
| * bestFriend: { type: PersonType }, |
| * }) |
| * }); |
| * |
| */ |
| var GraphQLObjectType = |
| /*#__PURE__*/ |
| function () { |
| function GraphQLObjectType(config) { |
| this.name = config.name; |
| this.description = config.description; |
| this.isTypeOf = config.isTypeOf; |
| this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions); |
| this.astNode = config.astNode; |
| this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes); |
| this._fields = defineFieldMap.bind(undefined, config); |
| this._interfaces = defineInterfaces.bind(undefined, config); |
| typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.'); |
| config.isTypeOf == null || typeof config.isTypeOf === 'function' || (0, _devAssert.default)(0, "".concat(this.name, " must provide \"isTypeOf\" as a function, ") + "but got: ".concat((0, _inspect.default)(config.isTypeOf), ".")); |
| } |
| |
| var _proto2 = GraphQLObjectType.prototype; |
| |
| _proto2.getFields = function getFields() { |
| if (typeof this._fields === 'function') { |
| this._fields = this._fields(); |
| } |
| |
| return this._fields; |
| }; |
| |
| _proto2.getInterfaces = function getInterfaces() { |
| if (typeof this._interfaces === 'function') { |
| this._interfaces = this._interfaces(); |
| } |
| |
| return this._interfaces; |
| }; |
| |
| _proto2.toConfig = function toConfig() { |
| return { |
| name: this.name, |
| description: this.description, |
| interfaces: this.getInterfaces(), |
| fields: fieldsToFieldsConfig(this.getFields()), |
| isTypeOf: this.isTypeOf, |
| extensions: this.extensions, |
| astNode: this.astNode, |
| extensionASTNodes: this.extensionASTNodes || [] |
| }; |
| }; |
| |
| _proto2.toString = function toString() { |
| return this.name; |
| } // $FlowFixMe Flow doesn't support computed properties yet |
| ; |
| |
| _createClass(GraphQLObjectType, [{ |
| key: _symbols.SYMBOL_TO_STRING_TAG, |
| get: function get() { |
| return 'GraphQLObjectType'; |
| } |
| }]); |
| |
| return GraphQLObjectType; |
| }(); |
| |
| exports.GraphQLObjectType = GraphQLObjectType; |
| (0, _defineToJSON.default)(GraphQLObjectType); |
| |
| function defineInterfaces(config) { |
| var _resolveThunk; |
| |
| var interfaces = (_resolveThunk = resolveThunk(config.interfaces)) !== null && _resolveThunk !== void 0 ? _resolveThunk : []; |
| Array.isArray(interfaces) || (0, _devAssert.default)(0, "".concat(config.name, " interfaces must be an Array or a function which returns an Array.")); |
| return interfaces; |
| } |
| |
| function defineFieldMap(config) { |
| var fieldMap = resolveThunk(config.fields); |
| isPlainObj(fieldMap) || (0, _devAssert.default)(0, "".concat(config.name, " fields must be an object with field names as keys or a function which returns such an object.")); |
| return (0, _mapValue.default)(fieldMap, function (fieldConfig, fieldName) { |
| var _fieldConfig$args; |
| |
| isPlainObj(fieldConfig) || (0, _devAssert.default)(0, "".concat(config.name, ".").concat(fieldName, " field config must be an object.")); |
| !('isDeprecated' in fieldConfig) || (0, _devAssert.default)(0, "".concat(config.name, ".").concat(fieldName, " should provide \"deprecationReason\" instead of \"isDeprecated\".")); |
| fieldConfig.resolve == null || typeof fieldConfig.resolve === 'function' || (0, _devAssert.default)(0, "".concat(config.name, ".").concat(fieldName, " field resolver must be a function if ") + "provided, but got: ".concat((0, _inspect.default)(fieldConfig.resolve), ".")); |
| var argsConfig = (_fieldConfig$args = fieldConfig.args) !== null && _fieldConfig$args !== void 0 ? _fieldConfig$args : {}; |
| isPlainObj(argsConfig) || (0, _devAssert.default)(0, "".concat(config.name, ".").concat(fieldName, " args must be an object with argument names as keys.")); |
| var args = (0, _objectEntries.default)(argsConfig).map(function (_ref) { |
| var argName = _ref[0], |
| argConfig = _ref[1]; |
| return { |
| name: argName, |
| description: argConfig.description, |
| type: argConfig.type, |
| defaultValue: argConfig.defaultValue, |
| extensions: argConfig.extensions && (0, _toObjMap.default)(argConfig.extensions), |
| astNode: argConfig.astNode |
| }; |
| }); |
| return { |
| name: fieldName, |
| description: fieldConfig.description, |
| type: fieldConfig.type, |
| args: args, |
| resolve: fieldConfig.resolve, |
| subscribe: fieldConfig.subscribe, |
| isDeprecated: fieldConfig.deprecationReason != null, |
| deprecationReason: fieldConfig.deprecationReason, |
| extensions: fieldConfig.extensions && (0, _toObjMap.default)(fieldConfig.extensions), |
| astNode: fieldConfig.astNode |
| }; |
| }); |
| } |
| |
| function isPlainObj(obj) { |
| return (0, _isObjectLike.default)(obj) && !Array.isArray(obj); |
| } |
| |
| function fieldsToFieldsConfig(fields) { |
| return (0, _mapValue.default)(fields, function (field) { |
| return { |
| description: field.description, |
| type: field.type, |
| args: argsToArgsConfig(field.args), |
| resolve: field.resolve, |
| subscribe: field.subscribe, |
| deprecationReason: field.deprecationReason, |
| extensions: field.extensions, |
| astNode: field.astNode |
| }; |
| }); |
| } |
| /** |
| * @internal |
| */ |
| |
| |
| function argsToArgsConfig(args) { |
| return (0, _keyValMap.default)(args, function (arg) { |
| return arg.name; |
| }, function (arg) { |
| return { |
| description: arg.description, |
| type: arg.type, |
| defaultValue: arg.defaultValue, |
| extensions: arg.extensions, |
| astNode: arg.astNode |
| }; |
| }); |
| } |
| |
| function isRequiredArgument(arg) { |
| return isNonNullType(arg.type) && arg.defaultValue === undefined; |
| } |
| |
| /** |
| * Interface Type Definition |
| * |
| * When a field can return one of a heterogeneous set of types, a Interface type |
| * is used to describe what types are possible, what fields are in common across |
| * all types, as well as a function to determine which type is actually used |
| * when the field is resolved. |
| * |
| * Example: |
| * |
| * const EntityType = new GraphQLInterfaceType({ |
| * name: 'Entity', |
| * fields: { |
| * name: { type: GraphQLString } |
| * } |
| * }); |
| * |
| */ |
| var GraphQLInterfaceType = |
| /*#__PURE__*/ |
| function () { |
| function GraphQLInterfaceType(config) { |
| this.name = config.name; |
| this.description = config.description; |
| this.resolveType = config.resolveType; |
| this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions); |
| this.astNode = config.astNode; |
| this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes); |
| this._fields = defineFieldMap.bind(undefined, config); |
| this._interfaces = defineInterfaces.bind(undefined, config); |
| typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.'); |
| config.resolveType == null || typeof config.resolveType === 'function' || (0, _devAssert.default)(0, "".concat(this.name, " must provide \"resolveType\" as a function, ") + "but got: ".concat((0, _inspect.default)(config.resolveType), ".")); |
| } |
| |
| var _proto3 = GraphQLInterfaceType.prototype; |
| |
| _proto3.getFields = function getFields() { |
| if (typeof this._fields === 'function') { |
| this._fields = this._fields(); |
| } |
| |
| return this._fields; |
| }; |
| |
| _proto3.getInterfaces = function getInterfaces() { |
| if (typeof this._interfaces === 'function') { |
| this._interfaces = this._interfaces(); |
| } |
| |
| return this._interfaces; |
| }; |
| |
| _proto3.toConfig = function toConfig() { |
| var _this$extensionASTNod2; |
| |
| return { |
| name: this.name, |
| description: this.description, |
| interfaces: this.getInterfaces(), |
| fields: fieldsToFieldsConfig(this.getFields()), |
| resolveType: this.resolveType, |
| extensions: this.extensions, |
| astNode: this.astNode, |
| extensionASTNodes: (_this$extensionASTNod2 = this.extensionASTNodes) !== null && _this$extensionASTNod2 !== void 0 ? _this$extensionASTNod2 : [] |
| }; |
| }; |
| |
| _proto3.toString = function toString() { |
| return this.name; |
| } // $FlowFixMe Flow doesn't support computed properties yet |
| ; |
| |
| _createClass(GraphQLInterfaceType, [{ |
| key: _symbols.SYMBOL_TO_STRING_TAG, |
| get: function get() { |
| return 'GraphQLInterfaceType'; |
| } |
| }]); |
| |
| return GraphQLInterfaceType; |
| }(); |
| |
| exports.GraphQLInterfaceType = GraphQLInterfaceType; |
| (0, _defineToJSON.default)(GraphQLInterfaceType); |
| |
| /** |
| * Union Type Definition |
| * |
| * When a field can return one of a heterogeneous set of types, a Union type |
| * is used to describe what types are possible as well as providing a function |
| * to determine which type is actually used when the field is resolved. |
| * |
| * Example: |
| * |
| * const PetType = new GraphQLUnionType({ |
| * name: 'Pet', |
| * types: [ DogType, CatType ], |
| * resolveType(value) { |
| * if (value instanceof Dog) { |
| * return DogType; |
| * } |
| * if (value instanceof Cat) { |
| * return CatType; |
| * } |
| * } |
| * }); |
| * |
| */ |
| var GraphQLUnionType = |
| /*#__PURE__*/ |
| function () { |
| function GraphQLUnionType(config) { |
| this.name = config.name; |
| this.description = config.description; |
| this.resolveType = config.resolveType; |
| this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions); |
| this.astNode = config.astNode; |
| this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes); |
| this._types = defineTypes.bind(undefined, config); |
| typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.'); |
| config.resolveType == null || typeof config.resolveType === 'function' || (0, _devAssert.default)(0, "".concat(this.name, " must provide \"resolveType\" as a function, ") + "but got: ".concat((0, _inspect.default)(config.resolveType), ".")); |
| } |
| |
| var _proto4 = GraphQLUnionType.prototype; |
| |
| _proto4.getTypes = function getTypes() { |
| if (typeof this._types === 'function') { |
| this._types = this._types(); |
| } |
| |
| return this._types; |
| }; |
| |
| _proto4.toConfig = function toConfig() { |
| var _this$extensionASTNod3; |
| |
| return { |
| name: this.name, |
| description: this.description, |
| types: this.getTypes(), |
| resolveType: this.resolveType, |
| extensions: this.extensions, |
| astNode: this.astNode, |
| extensionASTNodes: (_this$extensionASTNod3 = this.extensionASTNodes) !== null && _this$extensionASTNod3 !== void 0 ? _this$extensionASTNod3 : [] |
| }; |
| }; |
| |
| _proto4.toString = function toString() { |
| return this.name; |
| } // $FlowFixMe Flow doesn't support computed properties yet |
| ; |
| |
| _createClass(GraphQLUnionType, [{ |
| key: _symbols.SYMBOL_TO_STRING_TAG, |
| get: function get() { |
| return 'GraphQLUnionType'; |
| } |
| }]); |
| |
| return GraphQLUnionType; |
| }(); |
| |
| exports.GraphQLUnionType = GraphQLUnionType; |
| (0, _defineToJSON.default)(GraphQLUnionType); |
| |
| function defineTypes(config) { |
| var types = resolveThunk(config.types); |
| Array.isArray(types) || (0, _devAssert.default)(0, "Must provide Array of types or a function which returns such an array for Union ".concat(config.name, ".")); |
| return types; |
| } |
| |
| /** |
| * Enum Type Definition |
| * |
| * Some leaf values of requests and input values are Enums. GraphQL serializes |
| * Enum values as strings, however internally Enums can be represented by any |
| * kind of type, often integers. |
| * |
| * Example: |
| * |
| * const RGBType = new GraphQLEnumType({ |
| * name: 'RGB', |
| * values: { |
| * RED: { value: 0 }, |
| * GREEN: { value: 1 }, |
| * BLUE: { value: 2 } |
| * } |
| * }); |
| * |
| * Note: If a value is not provided in a definition, the name of the enum value |
| * will be used as its internal value. |
| */ |
| var GraphQLEnumType |
| /* <T> */ |
| = |
| /*#__PURE__*/ |
| function () { |
| function GraphQLEnumType(config) { |
| this.name = config.name; |
| this.description = config.description; |
| this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions); |
| this.astNode = config.astNode; |
| this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes); |
| this._values = defineEnumValues(this.name, config.values); |
| this._valueLookup = new Map(this._values.map(function (enumValue) { |
| return [enumValue.value, enumValue]; |
| })); |
| this._nameLookup = (0, _keyMap.default)(this._values, function (value) { |
| return value.name; |
| }); |
| typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.'); |
| } |
| |
| var _proto5 = GraphQLEnumType.prototype; |
| |
| _proto5.getValues = function getValues() { |
| return this._values; |
| }; |
| |
| _proto5.getValue = function getValue(name) { |
| return this._nameLookup[name]; |
| }; |
| |
| _proto5.serialize = function serialize(outputValue) { |
| var enumValue = this._valueLookup.get(outputValue); |
| |
| if (enumValue === undefined) { |
| throw new _GraphQLError.GraphQLError("Enum \"".concat(this.name, "\" cannot represent value: ").concat((0, _inspect.default)(outputValue))); |
| } |
| |
| return enumValue.name; |
| }; |
| |
| _proto5.parseValue = function parseValue(inputValue) |
| /* T */ |
| { |
| if (typeof inputValue !== 'string') { |
| var valueStr = (0, _inspect.default)(inputValue); |
| throw new _GraphQLError.GraphQLError("Enum \"".concat(this.name, "\" cannot represent non-string value: ").concat(valueStr, ".") + didYouMeanEnumValue(this, valueStr)); |
| } |
| |
| var enumValue = this.getValue(inputValue); |
| |
| if (enumValue == null) { |
| throw new _GraphQLError.GraphQLError("Value \"".concat(inputValue, "\" does not exist in \"").concat(this.name, "\" enum.") + didYouMeanEnumValue(this, inputValue)); |
| } |
| |
| return enumValue.value; |
| }; |
| |
| _proto5.parseLiteral = function parseLiteral(valueNode, _variables) |
| /* T */ |
| { |
| // Note: variables will be resolved to a value before calling this function. |
| if (valueNode.kind !== _kinds.Kind.ENUM) { |
| var valueStr = (0, _printer.print)(valueNode); |
| throw new _GraphQLError.GraphQLError("Enum \"".concat(this.name, "\" cannot represent non-enum value: ").concat(valueStr, ".") + didYouMeanEnumValue(this, valueStr), valueNode); |
| } |
| |
| var enumValue = this.getValue(valueNode.value); |
| |
| if (enumValue == null) { |
| var _valueStr = (0, _printer.print)(valueNode); |
| |
| throw new _GraphQLError.GraphQLError("Value \"".concat(_valueStr, "\" does not exist in \"").concat(this.name, "\" enum.") + didYouMeanEnumValue(this, _valueStr), valueNode); |
| } |
| |
| return enumValue.value; |
| }; |
| |
| _proto5.toConfig = function toConfig() { |
| var _this$extensionASTNod4; |
| |
| var values = (0, _keyValMap.default)(this.getValues(), function (value) { |
| return value.name; |
| }, function (value) { |
| return { |
| description: value.description, |
| value: value.value, |
| deprecationReason: value.deprecationReason, |
| extensions: value.extensions, |
| astNode: value.astNode |
| }; |
| }); |
| return { |
| name: this.name, |
| description: this.description, |
| values: values, |
| extensions: this.extensions, |
| astNode: this.astNode, |
| extensionASTNodes: (_this$extensionASTNod4 = this.extensionASTNodes) !== null && _this$extensionASTNod4 !== void 0 ? _this$extensionASTNod4 : [] |
| }; |
| }; |
| |
| _proto5.toString = function toString() { |
| return this.name; |
| } // $FlowFixMe Flow doesn't support computed properties yet |
| ; |
| |
| _createClass(GraphQLEnumType, [{ |
| key: _symbols.SYMBOL_TO_STRING_TAG, |
| get: function get() { |
| return 'GraphQLEnumType'; |
| } |
| }]); |
| |
| return GraphQLEnumType; |
| }(); |
| |
| exports.GraphQLEnumType = GraphQLEnumType; |
| (0, _defineToJSON.default)(GraphQLEnumType); |
| |
| function didYouMeanEnumValue(enumType, unknownValueStr) { |
| var allNames = enumType.getValues().map(function (value) { |
| return value.name; |
| }); |
| var suggestedValues = (0, _suggestionList.default)(unknownValueStr, allNames); |
| return (0, _didYouMean.default)('the enum value', suggestedValues); |
| } |
| |
| function defineEnumValues(typeName, valueMap) { |
| isPlainObj(valueMap) || (0, _devAssert.default)(0, "".concat(typeName, " values must be an object with value names as keys.")); |
| return (0, _objectEntries.default)(valueMap).map(function (_ref2) { |
| var valueName = _ref2[0], |
| valueConfig = _ref2[1]; |
| isPlainObj(valueConfig) || (0, _devAssert.default)(0, "".concat(typeName, ".").concat(valueName, " must refer to an object with a \"value\" key ") + "representing an internal value but got: ".concat((0, _inspect.default)(valueConfig), ".")); |
| !('isDeprecated' in valueConfig) || (0, _devAssert.default)(0, "".concat(typeName, ".").concat(valueName, " should provide \"deprecationReason\" instead of \"isDeprecated\".")); |
| return { |
| name: valueName, |
| description: valueConfig.description, |
| value: valueConfig.value !== undefined ? valueConfig.value : valueName, |
| isDeprecated: valueConfig.deprecationReason != null, |
| deprecationReason: valueConfig.deprecationReason, |
| extensions: valueConfig.extensions && (0, _toObjMap.default)(valueConfig.extensions), |
| astNode: valueConfig.astNode |
| }; |
| }); |
| } |
| |
| /** |
| * Input Object Type Definition |
| * |
| * An input object defines a structured collection of fields which may be |
| * supplied to a field argument. |
| * |
| * Using `NonNull` will ensure that a value must be provided by the query |
| * |
| * Example: |
| * |
| * const GeoPoint = new GraphQLInputObjectType({ |
| * name: 'GeoPoint', |
| * fields: { |
| * lat: { type: GraphQLNonNull(GraphQLFloat) }, |
| * lon: { type: GraphQLNonNull(GraphQLFloat) }, |
| * alt: { type: GraphQLFloat, defaultValue: 0 }, |
| * } |
| * }); |
| * |
| */ |
| var GraphQLInputObjectType = |
| /*#__PURE__*/ |
| function () { |
| function GraphQLInputObjectType(config) { |
| this.name = config.name; |
| this.description = config.description; |
| this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions); |
| this.astNode = config.astNode; |
| this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes); |
| this._fields = defineInputFieldMap.bind(undefined, config); |
| typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.'); |
| } |
| |
| var _proto6 = GraphQLInputObjectType.prototype; |
| |
| _proto6.getFields = function getFields() { |
| if (typeof this._fields === 'function') { |
| this._fields = this._fields(); |
| } |
| |
| return this._fields; |
| }; |
| |
| _proto6.toConfig = function toConfig() { |
| var _this$extensionASTNod5; |
| |
| var fields = (0, _mapValue.default)(this.getFields(), function (field) { |
| return { |
| description: field.description, |
| type: field.type, |
| defaultValue: field.defaultValue, |
| extensions: field.extensions, |
| astNode: field.astNode |
| }; |
| }); |
| return { |
| name: this.name, |
| description: this.description, |
| fields: fields, |
| extensions: this.extensions, |
| astNode: this.astNode, |
| extensionASTNodes: (_this$extensionASTNod5 = this.extensionASTNodes) !== null && _this$extensionASTNod5 !== void 0 ? _this$extensionASTNod5 : [] |
| }; |
| }; |
| |
| _proto6.toString = function toString() { |
| return this.name; |
| } // $FlowFixMe Flow doesn't support computed properties yet |
| ; |
| |
| _createClass(GraphQLInputObjectType, [{ |
| key: _symbols.SYMBOL_TO_STRING_TAG, |
| get: function get() { |
| return 'GraphQLInputObjectType'; |
| } |
| }]); |
| |
| return GraphQLInputObjectType; |
| }(); |
| |
| exports.GraphQLInputObjectType = GraphQLInputObjectType; |
| (0, _defineToJSON.default)(GraphQLInputObjectType); |
| |
| function defineInputFieldMap(config) { |
| var fieldMap = resolveThunk(config.fields); |
| isPlainObj(fieldMap) || (0, _devAssert.default)(0, "".concat(config.name, " fields must be an object with field names as keys or a function which returns such an object.")); |
| return (0, _mapValue.default)(fieldMap, function (fieldConfig, fieldName) { |
| !('resolve' in fieldConfig) || (0, _devAssert.default)(0, "".concat(config.name, ".").concat(fieldName, " field has a resolve property, but Input Types cannot define resolvers.")); |
| return { |
| name: fieldName, |
| description: fieldConfig.description, |
| type: fieldConfig.type, |
| defaultValue: fieldConfig.defaultValue, |
| extensions: fieldConfig.extensions && (0, _toObjMap.default)(fieldConfig.extensions), |
| astNode: fieldConfig.astNode |
| }; |
| }); |
| } |
| |
| function isRequiredInputField(field) { |
| return isNonNullType(field.type) && field.defaultValue === undefined; |
| } |