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