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