1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.isType = isType;
|
7 | exports.assertType = assertType;
|
8 | exports.isScalarType = isScalarType;
|
9 | exports.assertScalarType = assertScalarType;
|
10 | exports.isObjectType = isObjectType;
|
11 | exports.assertObjectType = assertObjectType;
|
12 | exports.isInterfaceType = isInterfaceType;
|
13 | exports.assertInterfaceType = assertInterfaceType;
|
14 | exports.isUnionType = isUnionType;
|
15 | exports.assertUnionType = assertUnionType;
|
16 | exports.isEnumType = isEnumType;
|
17 | exports.assertEnumType = assertEnumType;
|
18 | exports.isInputObjectType = isInputObjectType;
|
19 | exports.assertInputObjectType = assertInputObjectType;
|
20 | exports.isListType = isListType;
|
21 | exports.assertListType = assertListType;
|
22 | exports.isNonNullType = isNonNullType;
|
23 | exports.assertNonNullType = assertNonNullType;
|
24 | exports.isInputType = isInputType;
|
25 | exports.assertInputType = assertInputType;
|
26 | exports.isOutputType = isOutputType;
|
27 | exports.assertOutputType = assertOutputType;
|
28 | exports.isLeafType = isLeafType;
|
29 | exports.assertLeafType = assertLeafType;
|
30 | exports.isCompositeType = isCompositeType;
|
31 | exports.assertCompositeType = assertCompositeType;
|
32 | exports.isAbstractType = isAbstractType;
|
33 | exports.assertAbstractType = assertAbstractType;
|
34 | exports.GraphQLList = GraphQLList;
|
35 | exports.GraphQLNonNull = GraphQLNonNull;
|
36 | exports.isWrappingType = isWrappingType;
|
37 | exports.assertWrappingType = assertWrappingType;
|
38 | exports.isNullableType = isNullableType;
|
39 | exports.assertNullableType = assertNullableType;
|
40 | exports.getNullableType = getNullableType;
|
41 | exports.isNamedType = isNamedType;
|
42 | exports.assertNamedType = assertNamedType;
|
43 | exports.getNamedType = getNamedType;
|
44 | exports.argsToArgsConfig = argsToArgsConfig;
|
45 | exports.isRequiredArgument = isRequiredArgument;
|
46 | exports.isRequiredInputField = isRequiredInputField;
|
47 | exports.GraphQLInputObjectType = exports.GraphQLEnumType = exports.GraphQLUnionType = exports.GraphQLInterfaceType = exports.GraphQLObjectType = exports.GraphQLScalarType = void 0;
|
48 |
|
49 | var _objectEntries = _interopRequireDefault(require("../polyfills/objectEntries"));
|
50 |
|
51 | var _inspect = _interopRequireDefault(require("../jsutils/inspect"));
|
52 |
|
53 | var _keyMap = _interopRequireDefault(require("../jsutils/keyMap"));
|
54 |
|
55 | var _mapValue = _interopRequireDefault(require("../jsutils/mapValue"));
|
56 |
|
57 | var _toObjMap = _interopRequireDefault(require("../jsutils/toObjMap"));
|
58 |
|
59 | var _devAssert = _interopRequireDefault(require("../jsutils/devAssert"));
|
60 |
|
61 | var _keyValMap = _interopRequireDefault(require("../jsutils/keyValMap"));
|
62 |
|
63 | var _instanceOf = _interopRequireDefault(require("../jsutils/instanceOf"));
|
64 |
|
65 | var _isObjectLike = _interopRequireDefault(require("../jsutils/isObjectLike"));
|
66 |
|
67 | var _identityFunc = _interopRequireDefault(require("../jsutils/identityFunc"));
|
68 |
|
69 | var _defineToJSON = _interopRequireDefault(require("../jsutils/defineToJSON"));
|
70 |
|
71 | var _defineToStringTag = _interopRequireDefault(require("../jsutils/defineToStringTag"));
|
72 |
|
73 | var _kinds = require("../language/kinds");
|
74 |
|
75 | var _valueFromASTUntyped = require("../utilities/valueFromASTUntyped");
|
76 |
|
77 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
78 |
|
79 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
80 |
|
81 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
82 |
|
83 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
84 |
|
85 | function isType(type) {
|
86 | return isScalarType(type) || isObjectType(type) || isInterfaceType(type) || isUnionType(type) || isEnumType(type) || isInputObjectType(type) || isListType(type) || isNonNullType(type);
|
87 | }
|
88 |
|
89 | function assertType(type) {
|
90 | if (!isType(type)) {
|
91 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL type."));
|
92 | }
|
93 |
|
94 | return type;
|
95 | }
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | function isScalarType(type) {
|
103 | return (0, _instanceOf.default)(type, GraphQLScalarType);
|
104 | }
|
105 |
|
106 | function assertScalarType(type) {
|
107 | if (!isScalarType(type)) {
|
108 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Scalar type."));
|
109 | }
|
110 |
|
111 | return type;
|
112 | }
|
113 |
|
114 |
|
115 | function isObjectType(type) {
|
116 | return (0, _instanceOf.default)(type, GraphQLObjectType);
|
117 | }
|
118 |
|
119 | function assertObjectType(type) {
|
120 | if (!isObjectType(type)) {
|
121 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Object type."));
|
122 | }
|
123 |
|
124 | return type;
|
125 | }
|
126 |
|
127 |
|
128 | function isInterfaceType(type) {
|
129 | return (0, _instanceOf.default)(type, GraphQLInterfaceType);
|
130 | }
|
131 |
|
132 | function assertInterfaceType(type) {
|
133 | if (!isInterfaceType(type)) {
|
134 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Interface type."));
|
135 | }
|
136 |
|
137 | return type;
|
138 | }
|
139 |
|
140 |
|
141 | function isUnionType(type) {
|
142 | return (0, _instanceOf.default)(type, GraphQLUnionType);
|
143 | }
|
144 |
|
145 | function assertUnionType(type) {
|
146 | if (!isUnionType(type)) {
|
147 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Union type."));
|
148 | }
|
149 |
|
150 | return type;
|
151 | }
|
152 |
|
153 |
|
154 | function isEnumType(type) {
|
155 | return (0, _instanceOf.default)(type, GraphQLEnumType);
|
156 | }
|
157 |
|
158 | function assertEnumType(type) {
|
159 | if (!isEnumType(type)) {
|
160 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Enum type."));
|
161 | }
|
162 |
|
163 | return type;
|
164 | }
|
165 |
|
166 |
|
167 | function isInputObjectType(type) {
|
168 | return (0, _instanceOf.default)(type, GraphQLInputObjectType);
|
169 | }
|
170 |
|
171 | function assertInputObjectType(type) {
|
172 | if (!isInputObjectType(type)) {
|
173 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Input Object type."));
|
174 | }
|
175 |
|
176 | return type;
|
177 | }
|
178 |
|
179 |
|
180 | function isListType(type) {
|
181 | return (0, _instanceOf.default)(type, GraphQLList);
|
182 | }
|
183 |
|
184 | function assertListType(type) {
|
185 | if (!isListType(type)) {
|
186 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL List type."));
|
187 | }
|
188 |
|
189 | return type;
|
190 | }
|
191 |
|
192 |
|
193 | function isNonNullType(type) {
|
194 | return (0, _instanceOf.default)(type, GraphQLNonNull);
|
195 | }
|
196 |
|
197 | function assertNonNullType(type) {
|
198 | if (!isNonNullType(type)) {
|
199 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL Non-Null type."));
|
200 | }
|
201 |
|
202 | return type;
|
203 | }
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 | function isInputType(type) {
|
210 | return isScalarType(type) || isEnumType(type) || isInputObjectType(type) || isWrappingType(type) && isInputType(type.ofType);
|
211 | }
|
212 |
|
213 | function assertInputType(type) {
|
214 | if (!isInputType(type)) {
|
215 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL input type."));
|
216 | }
|
217 |
|
218 | return type;
|
219 | }
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 | function isOutputType(type) {
|
226 | return isScalarType(type) || isObjectType(type) || isInterfaceType(type) || isUnionType(type) || isEnumType(type) || isWrappingType(type) && isOutputType(type.ofType);
|
227 | }
|
228 |
|
229 | function assertOutputType(type) {
|
230 | if (!isOutputType(type)) {
|
231 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL output type."));
|
232 | }
|
233 |
|
234 | return type;
|
235 | }
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 | function isLeafType(type) {
|
242 | return isScalarType(type) || isEnumType(type);
|
243 | }
|
244 |
|
245 | function assertLeafType(type) {
|
246 | if (!isLeafType(type)) {
|
247 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL leaf type."));
|
248 | }
|
249 |
|
250 | return type;
|
251 | }
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 | function isCompositeType(type) {
|
258 | return isObjectType(type) || isInterfaceType(type) || isUnionType(type);
|
259 | }
|
260 |
|
261 | function assertCompositeType(type) {
|
262 | if (!isCompositeType(type)) {
|
263 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL composite type."));
|
264 | }
|
265 |
|
266 | return type;
|
267 | }
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 | function isAbstractType(type) {
|
274 | return isInterfaceType(type) || isUnionType(type);
|
275 | }
|
276 |
|
277 | function assertAbstractType(type) {
|
278 | if (!isAbstractType(type)) {
|
279 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL abstract type."));
|
280 | }
|
281 |
|
282 | return type;
|
283 | }
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 | function GraphQLList(ofType) {
|
306 | if (this instanceof GraphQLList) {
|
307 | this.ofType = assertType(ofType);
|
308 | } else {
|
309 | return new GraphQLList(ofType);
|
310 | }
|
311 | }
|
312 |
|
313 |
|
314 | GraphQLList.prototype.toString = function toString() {
|
315 | return '[' + String(this.ofType) + ']';
|
316 | };
|
317 |
|
318 |
|
319 | (0, _defineToStringTag.default)(GraphQLList);
|
320 | (0, _defineToJSON.default)(GraphQLList);
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 | function GraphQLNonNull(ofType) {
|
344 | if (this instanceof GraphQLNonNull) {
|
345 | this.ofType = assertNullableType(ofType);
|
346 | } else {
|
347 | return new GraphQLNonNull(ofType);
|
348 | }
|
349 | }
|
350 |
|
351 |
|
352 | GraphQLNonNull.prototype.toString = function toString() {
|
353 | return String(this.ofType) + '!';
|
354 | };
|
355 |
|
356 |
|
357 | (0, _defineToStringTag.default)(GraphQLNonNull);
|
358 | (0, _defineToJSON.default)(GraphQLNonNull);
|
359 |
|
360 |
|
361 |
|
362 |
|
363 | function isWrappingType(type) {
|
364 | return isListType(type) || isNonNullType(type);
|
365 | }
|
366 |
|
367 | function assertWrappingType(type) {
|
368 | if (!isWrappingType(type)) {
|
369 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL wrapping type."));
|
370 | }
|
371 |
|
372 | return type;
|
373 | }
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 | function isNullableType(type) {
|
380 | return isType(type) && !isNonNullType(type);
|
381 | }
|
382 |
|
383 | function assertNullableType(type) {
|
384 | if (!isNullableType(type)) {
|
385 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL nullable type."));
|
386 | }
|
387 |
|
388 | return type;
|
389 | }
|
390 |
|
391 |
|
392 |
|
393 | function getNullableType(type) {
|
394 |
|
395 | if (type) {
|
396 | return isNonNullType(type) ? type.ofType : type;
|
397 | }
|
398 | }
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 | function isNamedType(type) {
|
405 | return isScalarType(type) || isObjectType(type) || isInterfaceType(type) || isUnionType(type) || isEnumType(type) || isInputObjectType(type);
|
406 | }
|
407 |
|
408 | function assertNamedType(type) {
|
409 | if (!isNamedType(type)) {
|
410 | throw new Error("Expected ".concat((0, _inspect.default)(type), " to be a GraphQL named type."));
|
411 | }
|
412 |
|
413 | return type;
|
414 | }
|
415 |
|
416 |
|
417 |
|
418 | function getNamedType(type) {
|
419 |
|
420 | if (type) {
|
421 | var unwrappedType = type;
|
422 |
|
423 | while (isWrappingType(unwrappedType)) {
|
424 | unwrappedType = unwrappedType.ofType;
|
425 | }
|
426 |
|
427 | return unwrappedType;
|
428 | }
|
429 | }
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 | function resolveThunk(thunk) {
|
437 |
|
438 | return typeof thunk === 'function' ? thunk() : thunk;
|
439 | }
|
440 |
|
441 | function undefineIfEmpty(arr) {
|
442 | return arr && arr.length > 0 ? arr : undefined;
|
443 | }
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 | var GraphQLScalarType =
|
471 |
|
472 | function () {
|
473 | function GraphQLScalarType(config) {
|
474 | var parseValue = config.parseValue || _identityFunc.default;
|
475 | this.name = config.name;
|
476 | this.description = config.description;
|
477 | this.serialize = config.serialize || _identityFunc.default;
|
478 | this.parseValue = parseValue;
|
479 |
|
480 | this.parseLiteral = config.parseLiteral || function (node) {
|
481 | return parseValue((0, _valueFromASTUntyped.valueFromASTUntyped)(node));
|
482 | };
|
483 |
|
484 | this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions);
|
485 | this.astNode = config.astNode;
|
486 | this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
|
487 | typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.');
|
488 | 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."));
|
489 |
|
490 | if (config.parseLiteral) {
|
491 | typeof config.parseValue === 'function' && typeof config.parseLiteral === 'function' || (0, _devAssert.default)(0, "".concat(this.name, " must provide both \"parseValue\" and \"parseLiteral\" functions."));
|
492 | }
|
493 | }
|
494 |
|
495 | var _proto = GraphQLScalarType.prototype;
|
496 |
|
497 | _proto.toConfig = function toConfig() {
|
498 | return {
|
499 | name: this.name,
|
500 | description: this.description,
|
501 | serialize: this.serialize,
|
502 | parseValue: this.parseValue,
|
503 | parseLiteral: this.parseLiteral,
|
504 | extensions: this.extensions,
|
505 | astNode: this.astNode,
|
506 | extensionASTNodes: this.extensionASTNodes || []
|
507 | };
|
508 | };
|
509 |
|
510 | _proto.toString = function toString() {
|
511 | return this.name;
|
512 | };
|
513 |
|
514 | return GraphQLScalarType;
|
515 | }();
|
516 |
|
517 |
|
518 | exports.GraphQLScalarType = GraphQLScalarType;
|
519 | (0, _defineToStringTag.default)(GraphQLScalarType);
|
520 | (0, _defineToJSON.default)(GraphQLScalarType);
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 | var GraphQLObjectType =
|
560 |
|
561 | function () {
|
562 | function GraphQLObjectType(config) {
|
563 | this.name = config.name;
|
564 | this.description = config.description;
|
565 | this.isTypeOf = config.isTypeOf;
|
566 | this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions);
|
567 | this.astNode = config.astNode;
|
568 | this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
|
569 | this._fields = defineFieldMap.bind(undefined, config);
|
570 | this._interfaces = defineInterfaces.bind(undefined, config);
|
571 | typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.');
|
572 | 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), "."));
|
573 | }
|
574 |
|
575 | var _proto2 = GraphQLObjectType.prototype;
|
576 |
|
577 | _proto2.getFields = function getFields() {
|
578 | if (typeof this._fields === 'function') {
|
579 | this._fields = this._fields();
|
580 | }
|
581 |
|
582 | return this._fields;
|
583 | };
|
584 |
|
585 | _proto2.getInterfaces = function getInterfaces() {
|
586 | if (typeof this._interfaces === 'function') {
|
587 | this._interfaces = this._interfaces();
|
588 | }
|
589 |
|
590 | return this._interfaces;
|
591 | };
|
592 |
|
593 | _proto2.toConfig = function toConfig() {
|
594 | return {
|
595 | name: this.name,
|
596 | description: this.description,
|
597 | interfaces: this.getInterfaces(),
|
598 | fields: fieldsToFieldsConfig(this.getFields()),
|
599 | isTypeOf: this.isTypeOf,
|
600 | extensions: this.extensions,
|
601 | astNode: this.astNode,
|
602 | extensionASTNodes: this.extensionASTNodes || []
|
603 | };
|
604 | };
|
605 |
|
606 | _proto2.toString = function toString() {
|
607 | return this.name;
|
608 | };
|
609 |
|
610 | return GraphQLObjectType;
|
611 | }();
|
612 |
|
613 |
|
614 | exports.GraphQLObjectType = GraphQLObjectType;
|
615 | (0, _defineToStringTag.default)(GraphQLObjectType);
|
616 | (0, _defineToJSON.default)(GraphQLObjectType);
|
617 |
|
618 | function defineInterfaces(config) {
|
619 | var interfaces = resolveThunk(config.interfaces) || [];
|
620 | Array.isArray(interfaces) || (0, _devAssert.default)(0, "".concat(config.name, " interfaces must be an Array or a function which returns an Array."));
|
621 | return interfaces;
|
622 | }
|
623 |
|
624 | function defineFieldMap(config) {
|
625 | var fieldMap = resolveThunk(config.fields) || {};
|
626 | 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."));
|
627 | return (0, _mapValue.default)(fieldMap, function (fieldConfig, fieldName) {
|
628 | isPlainObj(fieldConfig) || (0, _devAssert.default)(0, "".concat(config.name, ".").concat(fieldName, " field config must be an object"));
|
629 | !('isDeprecated' in fieldConfig) || (0, _devAssert.default)(0, "".concat(config.name, ".").concat(fieldName, " should provide \"deprecationReason\" instead of \"isDeprecated\"."));
|
630 | 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), "."));
|
631 | var argsConfig = fieldConfig.args || {};
|
632 | isPlainObj(argsConfig) || (0, _devAssert.default)(0, "".concat(config.name, ".").concat(fieldName, " args must be an object with argument names as keys."));
|
633 | var args = (0, _objectEntries.default)(argsConfig).map(function (_ref) {
|
634 | var argName = _ref[0],
|
635 | arg = _ref[1];
|
636 | return {
|
637 | name: argName,
|
638 | description: arg.description === undefined ? null : arg.description,
|
639 | type: arg.type,
|
640 | defaultValue: arg.defaultValue,
|
641 | extensions: arg.extensions && (0, _toObjMap.default)(arg.extensions),
|
642 | astNode: arg.astNode
|
643 | };
|
644 | });
|
645 | return _objectSpread({}, fieldConfig, {
|
646 | name: fieldName,
|
647 | description: fieldConfig.description,
|
648 | type: fieldConfig.type,
|
649 | args: args,
|
650 | resolve: fieldConfig.resolve,
|
651 | subscribe: fieldConfig.subscribe,
|
652 | isDeprecated: Boolean(fieldConfig.deprecationReason),
|
653 | deprecationReason: fieldConfig.deprecationReason,
|
654 | extensions: fieldConfig.extensions && (0, _toObjMap.default)(fieldConfig.extensions),
|
655 | astNode: fieldConfig.astNode
|
656 | });
|
657 | });
|
658 | }
|
659 |
|
660 | function isPlainObj(obj) {
|
661 | return (0, _isObjectLike.default)(obj) && !Array.isArray(obj);
|
662 | }
|
663 |
|
664 | function fieldsToFieldsConfig(fields) {
|
665 | return (0, _mapValue.default)(fields, function (field) {
|
666 | return {
|
667 | description: field.description,
|
668 | type: field.type,
|
669 | args: argsToArgsConfig(field.args),
|
670 | resolve: field.resolve,
|
671 | subscribe: field.subscribe,
|
672 | deprecationReason: field.deprecationReason,
|
673 | extensions: field.extensions,
|
674 | astNode: field.astNode
|
675 | };
|
676 | });
|
677 | }
|
678 |
|
679 | function argsToArgsConfig(args) {
|
680 | return (0, _keyValMap.default)(args, function (arg) {
|
681 | return arg.name;
|
682 | }, function (arg) {
|
683 | return {
|
684 | description: arg.description,
|
685 | type: arg.type,
|
686 | defaultValue: arg.defaultValue,
|
687 | extensions: arg.extensions,
|
688 | astNode: arg.astNode
|
689 | };
|
690 | });
|
691 | }
|
692 |
|
693 | function isRequiredArgument(arg) {
|
694 | return isNonNullType(arg.type) && arg.defaultValue === undefined;
|
695 | }
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 | var GraphQLInterfaceType =
|
716 |
|
717 | function () {
|
718 | function GraphQLInterfaceType(config) {
|
719 | this.name = config.name;
|
720 | this.description = config.description;
|
721 | this.resolveType = config.resolveType;
|
722 | this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions);
|
723 | this.astNode = config.astNode;
|
724 | this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
|
725 | this._fields = defineFieldMap.bind(undefined, config);
|
726 | typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.');
|
727 | 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), "."));
|
728 | }
|
729 |
|
730 | var _proto3 = GraphQLInterfaceType.prototype;
|
731 |
|
732 | _proto3.getFields = function getFields() {
|
733 | if (typeof this._fields === 'function') {
|
734 | this._fields = this._fields();
|
735 | }
|
736 |
|
737 | return this._fields;
|
738 | };
|
739 |
|
740 | _proto3.toConfig = function toConfig() {
|
741 | return {
|
742 | name: this.name,
|
743 | description: this.description,
|
744 | fields: fieldsToFieldsConfig(this.getFields()),
|
745 | resolveType: this.resolveType,
|
746 | extensions: this.extensions,
|
747 | astNode: this.astNode,
|
748 | extensionASTNodes: this.extensionASTNodes || []
|
749 | };
|
750 | };
|
751 |
|
752 | _proto3.toString = function toString() {
|
753 | return this.name;
|
754 | };
|
755 |
|
756 | return GraphQLInterfaceType;
|
757 | }();
|
758 |
|
759 |
|
760 | exports.GraphQLInterfaceType = GraphQLInterfaceType;
|
761 | (0, _defineToStringTag.default)(GraphQLInterfaceType);
|
762 | (0, _defineToJSON.default)(GraphQLInterfaceType);
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 |
|
772 |
|
773 |
|
774 |
|
775 |
|
776 |
|
777 |
|
778 |
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 | var GraphQLUnionType =
|
788 |
|
789 | function () {
|
790 | function GraphQLUnionType(config) {
|
791 | this.name = config.name;
|
792 | this.description = config.description;
|
793 | this.resolveType = config.resolveType;
|
794 | this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions);
|
795 | this.astNode = config.astNode;
|
796 | this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
|
797 | this._types = defineTypes.bind(undefined, config);
|
798 | typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.');
|
799 | 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), "."));
|
800 | }
|
801 |
|
802 | var _proto4 = GraphQLUnionType.prototype;
|
803 |
|
804 | _proto4.getTypes = function getTypes() {
|
805 | if (typeof this._types === 'function') {
|
806 | this._types = this._types();
|
807 | }
|
808 |
|
809 | return this._types;
|
810 | };
|
811 |
|
812 | _proto4.toConfig = function toConfig() {
|
813 | return {
|
814 | name: this.name,
|
815 | description: this.description,
|
816 | types: this.getTypes(),
|
817 | resolveType: this.resolveType,
|
818 | extensions: this.extensions,
|
819 | astNode: this.astNode,
|
820 | extensionASTNodes: this.extensionASTNodes || []
|
821 | };
|
822 | };
|
823 |
|
824 | _proto4.toString = function toString() {
|
825 | return this.name;
|
826 | };
|
827 |
|
828 | return GraphQLUnionType;
|
829 | }();
|
830 |
|
831 |
|
832 | exports.GraphQLUnionType = GraphQLUnionType;
|
833 | (0, _defineToStringTag.default)(GraphQLUnionType);
|
834 | (0, _defineToJSON.default)(GraphQLUnionType);
|
835 |
|
836 | function defineTypes(config) {
|
837 | var types = resolveThunk(config.types) || [];
|
838 | 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, "."));
|
839 | return types;
|
840 | }
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 | var GraphQLEnumType
|
864 |
|
865 | =
|
866 |
|
867 | function () {
|
868 | function GraphQLEnumType(config) {
|
869 | this.name = config.name;
|
870 | this.description = config.description;
|
871 | this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions);
|
872 | this.astNode = config.astNode;
|
873 | this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
|
874 | this._values = defineEnumValues(this.name, config.values);
|
875 | this._valueLookup = new Map(this._values.map(function (enumValue) {
|
876 | return [enumValue.value, enumValue];
|
877 | }));
|
878 | this._nameLookup = (0, _keyMap.default)(this._values, function (value) {
|
879 | return value.name;
|
880 | });
|
881 | typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.');
|
882 | }
|
883 |
|
884 | var _proto5 = GraphQLEnumType.prototype;
|
885 |
|
886 | _proto5.getValues = function getValues() {
|
887 | return this._values;
|
888 | };
|
889 |
|
890 | _proto5.getValue = function getValue(name) {
|
891 | return this._nameLookup[name];
|
892 | };
|
893 |
|
894 | _proto5.serialize = function serialize(value) {
|
895 | var enumValue = this._valueLookup.get(value);
|
896 |
|
897 | if (enumValue) {
|
898 | return enumValue.name;
|
899 | }
|
900 | };
|
901 |
|
902 | _proto5.parseValue = function parseValue(value)
|
903 | /* T */
|
904 | {
|
905 | if (typeof value === 'string') {
|
906 | var enumValue = this.getValue(value);
|
907 |
|
908 | if (enumValue) {
|
909 | return enumValue.value;
|
910 | }
|
911 | }
|
912 | };
|
913 |
|
914 | _proto5.parseLiteral = function parseLiteral(valueNode, _variables)
|
915 | /* T */
|
916 | {
|
917 |
|
918 | if (valueNode.kind === _kinds.Kind.ENUM) {
|
919 | var enumValue = this.getValue(valueNode.value);
|
920 |
|
921 | if (enumValue) {
|
922 | return enumValue.value;
|
923 | }
|
924 | }
|
925 | };
|
926 |
|
927 | _proto5.toConfig = function toConfig() {
|
928 | var values = (0, _keyValMap.default)(this.getValues(), function (value) {
|
929 | return value.name;
|
930 | }, function (value) {
|
931 | return {
|
932 | description: value.description,
|
933 | value: value.value,
|
934 | deprecationReason: value.deprecationReason,
|
935 | extensions: value.extensions,
|
936 | astNode: value.astNode
|
937 | };
|
938 | });
|
939 | return {
|
940 | name: this.name,
|
941 | description: this.description,
|
942 | values: values,
|
943 | extensions: this.extensions,
|
944 | astNode: this.astNode,
|
945 | extensionASTNodes: this.extensionASTNodes || []
|
946 | };
|
947 | };
|
948 |
|
949 | _proto5.toString = function toString() {
|
950 | return this.name;
|
951 | };
|
952 |
|
953 | return GraphQLEnumType;
|
954 | }();
|
955 |
|
956 |
|
957 | exports.GraphQLEnumType = GraphQLEnumType;
|
958 | (0, _defineToStringTag.default)(GraphQLEnumType);
|
959 | (0, _defineToJSON.default)(GraphQLEnumType);
|
960 |
|
961 | function defineEnumValues(typeName, valueMap) {
|
962 | isPlainObj(valueMap) || (0, _devAssert.default)(0, "".concat(typeName, " values must be an object with value names as keys."));
|
963 | return (0, _objectEntries.default)(valueMap).map(function (_ref2) {
|
964 | var valueName = _ref2[0],
|
965 | value = _ref2[1];
|
966 | isPlainObj(value) || (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)(value), "."));
|
967 | !('isDeprecated' in value) || (0, _devAssert.default)(0, "".concat(typeName, ".").concat(valueName, " should provide \"deprecationReason\" instead of \"isDeprecated\"."));
|
968 | return {
|
969 | name: valueName,
|
970 | description: value.description,
|
971 | value: 'value' in value ? value.value : valueName,
|
972 | isDeprecated: Boolean(value.deprecationReason),
|
973 | deprecationReason: value.deprecationReason,
|
974 | extensions: value.extensions && (0, _toObjMap.default)(value.extensions),
|
975 | astNode: value.astNode
|
976 | };
|
977 | });
|
978 | }
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 | var GraphQLInputObjectType =
|
1001 |
|
1002 | function () {
|
1003 | function GraphQLInputObjectType(config) {
|
1004 | this.name = config.name;
|
1005 | this.description = config.description;
|
1006 | this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions);
|
1007 | this.astNode = config.astNode;
|
1008 | this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);
|
1009 | this._fields = defineInputFieldMap.bind(undefined, config);
|
1010 | typeof config.name === 'string' || (0, _devAssert.default)(0, 'Must provide name.');
|
1011 | }
|
1012 |
|
1013 | var _proto6 = GraphQLInputObjectType.prototype;
|
1014 |
|
1015 | _proto6.getFields = function getFields() {
|
1016 | if (typeof this._fields === 'function') {
|
1017 | this._fields = this._fields();
|
1018 | }
|
1019 |
|
1020 | return this._fields;
|
1021 | };
|
1022 |
|
1023 | _proto6.toConfig = function toConfig() {
|
1024 | var fields = (0, _mapValue.default)(this.getFields(), function (field) {
|
1025 | return {
|
1026 | description: field.description,
|
1027 | type: field.type,
|
1028 | defaultValue: field.defaultValue,
|
1029 | extensions: field.extensions,
|
1030 | astNode: field.astNode
|
1031 | };
|
1032 | });
|
1033 | return {
|
1034 | name: this.name,
|
1035 | description: this.description,
|
1036 | fields: fields,
|
1037 | extensions: this.extensions,
|
1038 | astNode: this.astNode,
|
1039 | extensionASTNodes: this.extensionASTNodes || []
|
1040 | };
|
1041 | };
|
1042 |
|
1043 | _proto6.toString = function toString() {
|
1044 | return this.name;
|
1045 | };
|
1046 |
|
1047 | return GraphQLInputObjectType;
|
1048 | }();
|
1049 |
|
1050 |
|
1051 | exports.GraphQLInputObjectType = GraphQLInputObjectType;
|
1052 | (0, _defineToStringTag.default)(GraphQLInputObjectType);
|
1053 | (0, _defineToJSON.default)(GraphQLInputObjectType);
|
1054 |
|
1055 | function defineInputFieldMap(config) {
|
1056 | var fieldMap = resolveThunk(config.fields) || {};
|
1057 | 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."));
|
1058 | return (0, _mapValue.default)(fieldMap, function (fieldConfig, fieldName) {
|
1059 | !('resolve' in fieldConfig) || (0, _devAssert.default)(0, "".concat(config.name, ".").concat(fieldName, " field has a resolve property, but Input Types cannot define resolvers."));
|
1060 | return _objectSpread({}, fieldConfig, {
|
1061 | name: fieldName,
|
1062 | description: fieldConfig.description,
|
1063 | type: fieldConfig.type,
|
1064 | defaultValue: fieldConfig.defaultValue,
|
1065 | extensions: fieldConfig.extensions && (0, _toObjMap.default)(fieldConfig.extensions),
|
1066 | astNode: fieldConfig.astNode
|
1067 | });
|
1068 | });
|
1069 | }
|
1070 |
|
1071 | function isRequiredInputField(field) {
|
1072 | return isNonNullType(field.type) && field.defaultValue === undefined;
|
1073 | }
|