1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.GraphQLInputObjectType = exports.GraphQLEnumType = exports.GraphQLUnionType = exports.GraphQLInterfaceType = exports.GraphQLObjectType = exports.GraphQLScalarType = undefined;
|
7 |
|
8 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
9 |
|
10 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
11 |
|
12 | exports.isType = isType;
|
13 | exports.assertType = assertType;
|
14 | exports.isScalarType = isScalarType;
|
15 | exports.assertScalarType = assertScalarType;
|
16 | exports.isObjectType = isObjectType;
|
17 | exports.assertObjectType = assertObjectType;
|
18 | exports.isInterfaceType = isInterfaceType;
|
19 | exports.assertInterfaceType = assertInterfaceType;
|
20 | exports.isUnionType = isUnionType;
|
21 | exports.assertUnionType = assertUnionType;
|
22 | exports.isEnumType = isEnumType;
|
23 | exports.assertEnumType = assertEnumType;
|
24 | exports.isInputObjectType = isInputObjectType;
|
25 | exports.assertInputObjectType = assertInputObjectType;
|
26 | exports.isListType = isListType;
|
27 | exports.assertListType = assertListType;
|
28 | exports.isNonNullType = isNonNullType;
|
29 | exports.assertNonNullType = assertNonNullType;
|
30 | exports.isInputType = isInputType;
|
31 | exports.assertInputType = assertInputType;
|
32 | exports.isOutputType = isOutputType;
|
33 | exports.assertOutputType = assertOutputType;
|
34 | exports.isLeafType = isLeafType;
|
35 | exports.assertLeafType = assertLeafType;
|
36 | exports.isCompositeType = isCompositeType;
|
37 | exports.assertCompositeType = assertCompositeType;
|
38 | exports.isAbstractType = isAbstractType;
|
39 | exports.assertAbstractType = assertAbstractType;
|
40 | exports.isWrappingType = isWrappingType;
|
41 | exports.assertWrappingType = assertWrappingType;
|
42 | exports.isNullableType = isNullableType;
|
43 | exports.assertNullableType = assertNullableType;
|
44 | exports.getNullableType = getNullableType;
|
45 | exports.isNamedType = isNamedType;
|
46 | exports.assertNamedType = assertNamedType;
|
47 | exports.getNamedType = getNamedType;
|
48 |
|
49 | var _instanceOf = require('../jsutils/instanceOf');
|
50 |
|
51 | var _instanceOf2 = _interopRequireDefault(_instanceOf);
|
52 |
|
53 | var _invariant = require('../jsutils/invariant');
|
54 |
|
55 | var _invariant2 = _interopRequireDefault(_invariant);
|
56 |
|
57 | var _isInvalid = require('../jsutils/isInvalid');
|
58 |
|
59 | var _isInvalid2 = _interopRequireDefault(_isInvalid);
|
60 |
|
61 | var _kinds = require('../language/kinds');
|
62 |
|
63 | var Kind = _interopRequireWildcard(_kinds);
|
64 |
|
65 | var _valueFromASTUntyped = require('../utilities/valueFromASTUntyped');
|
66 |
|
67 | var _wrappers = require('./wrappers');
|
68 |
|
69 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
70 |
|
71 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
72 |
|
73 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | function isType(type) {
|
88 | return isScalarType(type) || isObjectType(type) || isInterfaceType(type) || isUnionType(type) || isEnumType(type) || isInputObjectType(type) || isListType(type) || isNonNullType(type);
|
89 | }
|
90 |
|
91 | function assertType(type) {
|
92 | !isType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL type.') : void 0;
|
93 | return type;
|
94 | }
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | function isScalarType(type) {
|
102 | return (0, _instanceOf2.default)(type, GraphQLScalarType);
|
103 | }
|
104 |
|
105 | function assertScalarType(type) {
|
106 | !isScalarType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL Scalar type.') : void 0;
|
107 | return type;
|
108 | }
|
109 |
|
110 |
|
111 | function isObjectType(type) {
|
112 | return (0, _instanceOf2.default)(type, GraphQLObjectType);
|
113 | }
|
114 |
|
115 | function assertObjectType(type) {
|
116 | !isObjectType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL Object type.') : void 0;
|
117 | return type;
|
118 | }
|
119 |
|
120 |
|
121 | function isInterfaceType(type) {
|
122 | return (0, _instanceOf2.default)(type, GraphQLInterfaceType);
|
123 | }
|
124 |
|
125 | function assertInterfaceType(type) {
|
126 | !isInterfaceType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL Interface type.') : void 0;
|
127 | return type;
|
128 | }
|
129 |
|
130 |
|
131 | function isUnionType(type) {
|
132 | return (0, _instanceOf2.default)(type, GraphQLUnionType);
|
133 | }
|
134 |
|
135 | function assertUnionType(type) {
|
136 | !isUnionType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL Union type.') : void 0;
|
137 | return type;
|
138 | }
|
139 |
|
140 |
|
141 | function isEnumType(type) {
|
142 | return (0, _instanceOf2.default)(type, GraphQLEnumType);
|
143 | }
|
144 |
|
145 | function assertEnumType(type) {
|
146 | !isEnumType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL Enum type.') : void 0;
|
147 | return type;
|
148 | }
|
149 |
|
150 |
|
151 | function isInputObjectType(type) {
|
152 | return (0, _instanceOf2.default)(type, GraphQLInputObjectType);
|
153 | }
|
154 |
|
155 | function assertInputObjectType(type) {
|
156 | !isInputObjectType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL Input Object type.') : void 0;
|
157 | return type;
|
158 | }
|
159 |
|
160 |
|
161 | function isListType(type) {
|
162 | return (0, _instanceOf2.default)(type, _wrappers.GraphQLList);
|
163 | }
|
164 |
|
165 | function assertListType(type) {
|
166 | !isListType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL List type.') : void 0;
|
167 | return type;
|
168 | }
|
169 |
|
170 |
|
171 | function isNonNullType(type) {
|
172 | return (0, _instanceOf2.default)(type, _wrappers.GraphQLNonNull);
|
173 | }
|
174 |
|
175 | function assertNonNullType(type) {
|
176 | !isNonNullType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL Non-Null type.') : void 0;
|
177 | return type;
|
178 | }
|
179 |
|
180 |
|
181 |
|
182 |
|
183 | function isInputType(type) {
|
184 | return isScalarType(type) || isEnumType(type) || isInputObjectType(type) || isWrappingType(type) && isInputType(type.ofType);
|
185 | }
|
186 |
|
187 | function assertInputType(type) {
|
188 | !isInputType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL input type.') : void 0;
|
189 | return type;
|
190 | }
|
191 |
|
192 |
|
193 |
|
194 |
|
195 | function isOutputType(type) {
|
196 | return isScalarType(type) || isObjectType(type) || isInterfaceType(type) || isUnionType(type) || isEnumType(type) || isWrappingType(type) && isOutputType(type.ofType);
|
197 | }
|
198 |
|
199 | function assertOutputType(type) {
|
200 | !isOutputType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL output type.') : void 0;
|
201 | return type;
|
202 | }
|
203 |
|
204 |
|
205 |
|
206 |
|
207 | function isLeafType(type) {
|
208 | return isScalarType(type) || isEnumType(type);
|
209 | }
|
210 |
|
211 | function assertLeafType(type) {
|
212 | !isLeafType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL leaf type.') : void 0;
|
213 | return type;
|
214 | }
|
215 |
|
216 |
|
217 |
|
218 |
|
219 | function isCompositeType(type) {
|
220 | return isObjectType(type) || isInterfaceType(type) || isUnionType(type);
|
221 | }
|
222 |
|
223 | function assertCompositeType(type) {
|
224 | !isCompositeType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL composite type.') : void 0;
|
225 | return type;
|
226 | }
|
227 |
|
228 |
|
229 |
|
230 |
|
231 | function isAbstractType(type) {
|
232 | return isInterfaceType(type) || isUnionType(type);
|
233 | }
|
234 |
|
235 | function assertAbstractType(type) {
|
236 | !isAbstractType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL abstract type.') : void 0;
|
237 | return type;
|
238 | }
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | function isWrappingType(type) {
|
245 | return isListType(type) || isNonNullType(type);
|
246 | }
|
247 |
|
248 | function assertWrappingType(type) {
|
249 | !isWrappingType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL wrapping type.') : void 0;
|
250 | return type;
|
251 | }
|
252 |
|
253 |
|
254 |
|
255 |
|
256 | function isNullableType(type) {
|
257 | return isType(type) && !isNonNullType(type);
|
258 | }
|
259 |
|
260 | function assertNullableType(type) {
|
261 | !isNullableType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL nullable type.') : void 0;
|
262 | return type;
|
263 | }
|
264 |
|
265 |
|
266 | function getNullableType(type) {
|
267 |
|
268 | if (type) {
|
269 | return isNonNullType(type) ? type.ofType : type;
|
270 | }
|
271 | }
|
272 |
|
273 |
|
274 |
|
275 |
|
276 | function isNamedType(type) {
|
277 | return isScalarType(type) || isObjectType(type) || isInterfaceType(type) || isUnionType(type) || isEnumType(type) || isInputObjectType(type);
|
278 | }
|
279 |
|
280 | function assertNamedType(type) {
|
281 | !isNamedType(type) ? (0, _invariant2.default)(0, 'Expected ' + String(type) + ' to be a GraphQL named type.') : void 0;
|
282 | return type;
|
283 | }
|
284 |
|
285 |
|
286 | function getNamedType(type) {
|
287 |
|
288 | if (type) {
|
289 | var unwrappedType = type;
|
290 | while (isWrappingType(unwrappedType)) {
|
291 | unwrappedType = unwrappedType.ofType;
|
292 | }
|
293 | return unwrappedType;
|
294 | }
|
295 | }
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | function resolveThunk(thunk) {
|
304 | return typeof thunk === 'function' ? thunk() : thunk;
|
305 | }
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 | var GraphQLScalarType = exports.GraphQLScalarType = function () {
|
333 | function GraphQLScalarType(config) {
|
334 | _classCallCheck(this, GraphQLScalarType);
|
335 |
|
336 | this.name = config.name;
|
337 | this.description = config.description;
|
338 | this.astNode = config.astNode;
|
339 | this._scalarConfig = config;
|
340 | !(typeof config.name === 'string') ? (0, _invariant2.default)(0, 'Must provide name.') : void 0;
|
341 | !(typeof config.serialize === 'function') ? (0, _invariant2.default)(0, 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.') : void 0;
|
342 | if (config.parseValue || config.parseLiteral) {
|
343 | !(typeof config.parseValue === 'function' && typeof config.parseLiteral === 'function') ? (0, _invariant2.default)(0, this.name + ' must provide both "parseValue" and "parseLiteral" ' + 'functions.') : void 0;
|
344 | }
|
345 | }
|
346 |
|
347 |
|
348 |
|
349 |
|
350 | GraphQLScalarType.prototype.serialize = function serialize(value) {
|
351 | var serializer = this._scalarConfig.serialize;
|
352 | return serializer(value);
|
353 | };
|
354 |
|
355 |
|
356 |
|
357 |
|
358 | GraphQLScalarType.prototype.parseValue = function parseValue(value) {
|
359 | var parser = this._scalarConfig.parseValue;
|
360 | if ((0, _isInvalid2.default)(value)) {
|
361 | return undefined;
|
362 | }
|
363 | return parser ? parser(value) : value;
|
364 | };
|
365 |
|
366 |
|
367 |
|
368 |
|
369 | GraphQLScalarType.prototype.parseLiteral = function parseLiteral(valueNode, variables) {
|
370 | var parser = this._scalarConfig.parseLiteral;
|
371 | return parser ? parser(valueNode, variables) : (0, _valueFromASTUntyped.valueFromASTUntyped)(valueNode, variables);
|
372 | };
|
373 |
|
374 | GraphQLScalarType.prototype.toString = function toString() {
|
375 | return this.name;
|
376 | };
|
377 |
|
378 | return GraphQLScalarType;
|
379 | }();
|
380 |
|
381 |
|
382 |
|
383 |
|
384 | GraphQLScalarType.prototype.toJSON = GraphQLScalarType.prototype.inspect = GraphQLScalarType.prototype.toString;
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 | var GraphQLObjectType = exports.GraphQLObjectType = function () {
|
424 | function GraphQLObjectType(config) {
|
425 | _classCallCheck(this, GraphQLObjectType);
|
426 |
|
427 | this.name = config.name;
|
428 | this.description = config.description;
|
429 | this.astNode = config.astNode;
|
430 | this.extensionASTNodes = config.extensionASTNodes;
|
431 | this.isTypeOf = config.isTypeOf;
|
432 | this._typeConfig = config;
|
433 | !(typeof config.name === 'string') ? (0, _invariant2.default)(0, 'Must provide name.') : void 0;
|
434 | if (config.isTypeOf) {
|
435 | !(typeof config.isTypeOf === 'function') ? (0, _invariant2.default)(0, this.name + ' must provide "isTypeOf" as a function.') : void 0;
|
436 | }
|
437 | }
|
438 |
|
439 | GraphQLObjectType.prototype.getFields = function getFields() {
|
440 | return this._fields || (this._fields = defineFieldMap(this, this._typeConfig.fields));
|
441 | };
|
442 |
|
443 | GraphQLObjectType.prototype.getInterfaces = function getInterfaces() {
|
444 | return this._interfaces || (this._interfaces = defineInterfaces(this, this._typeConfig.interfaces));
|
445 | };
|
446 |
|
447 | GraphQLObjectType.prototype.toString = function toString() {
|
448 | return this.name;
|
449 | };
|
450 |
|
451 | return GraphQLObjectType;
|
452 | }();
|
453 |
|
454 |
|
455 |
|
456 |
|
457 | GraphQLObjectType.prototype.toJSON = GraphQLObjectType.prototype.inspect = GraphQLObjectType.prototype.toString;
|
458 |
|
459 | function defineInterfaces(type, interfacesThunk) {
|
460 | var interfaces = resolveThunk(interfacesThunk) || [];
|
461 | !Array.isArray(interfaces) ? (0, _invariant2.default)(0, type.name + ' interfaces must be an Array or a function which returns ' + 'an Array.') : void 0;
|
462 | return interfaces;
|
463 | }
|
464 |
|
465 | function defineFieldMap(type, fieldsThunk) {
|
466 | var fieldMap = resolveThunk(fieldsThunk) || {};
|
467 | !isPlainObj(fieldMap) ? (0, _invariant2.default)(0, type.name + ' fields must be an object with field names as keys or a ' + 'function which returns such an object.') : void 0;
|
468 |
|
469 | var resultFieldMap = Object.create(null);
|
470 | Object.keys(fieldMap).forEach(function (fieldName) {
|
471 | var fieldConfig = fieldMap[fieldName];
|
472 | !isPlainObj(fieldConfig) ? (0, _invariant2.default)(0, type.name + '.' + fieldName + ' field config must be an object') : void 0;
|
473 | !!fieldConfig.hasOwnProperty('isDeprecated') ? (0, _invariant2.default)(0, type.name + '.' + fieldName + ' should provide "deprecationReason" instead ' + 'of "isDeprecated".') : void 0;
|
474 | var field = _extends({}, fieldConfig, {
|
475 | isDeprecated: Boolean(fieldConfig.deprecationReason),
|
476 | name: fieldName
|
477 | });
|
478 | !isValidResolver(field.resolve) ? (0, _invariant2.default)(0, type.name + '.' + fieldName + ' field resolver must be a function if ' + ('provided, but got: ' + String(field.resolve) + '.')) : void 0;
|
479 | var argsConfig = fieldConfig.args;
|
480 | if (!argsConfig) {
|
481 | field.args = [];
|
482 | } else {
|
483 | !isPlainObj(argsConfig) ? (0, _invariant2.default)(0, type.name + '.' + fieldName + ' args must be an object with argument ' + 'names as keys.') : void 0;
|
484 | field.args = Object.keys(argsConfig).map(function (argName) {
|
485 | var arg = argsConfig[argName];
|
486 | return {
|
487 | name: argName,
|
488 | description: arg.description === undefined ? null : arg.description,
|
489 | type: arg.type,
|
490 | defaultValue: arg.defaultValue,
|
491 | astNode: arg.astNode
|
492 | };
|
493 | });
|
494 | }
|
495 | resultFieldMap[fieldName] = field;
|
496 | });
|
497 | return resultFieldMap;
|
498 | }
|
499 |
|
500 | function isPlainObj(obj) {
|
501 | return obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && !Array.isArray(obj);
|
502 | }
|
503 |
|
504 |
|
505 | function isValidResolver(resolver) {
|
506 | return resolver == null || typeof resolver === 'function';
|
507 | }
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 | var GraphQLInterfaceType = exports.GraphQLInterfaceType = function () {
|
528 | function GraphQLInterfaceType(config) {
|
529 | _classCallCheck(this, GraphQLInterfaceType);
|
530 |
|
531 | this.name = config.name;
|
532 | this.description = config.description;
|
533 | this.astNode = config.astNode;
|
534 | this.extensionASTNodes = config.extensionASTNodes;
|
535 | this.resolveType = config.resolveType;
|
536 | this._typeConfig = config;
|
537 | !(typeof config.name === 'string') ? (0, _invariant2.default)(0, 'Must provide name.') : void 0;
|
538 | if (config.resolveType) {
|
539 | !(typeof config.resolveType === 'function') ? (0, _invariant2.default)(0, this.name + ' must provide "resolveType" as a function.') : void 0;
|
540 | }
|
541 | }
|
542 |
|
543 | GraphQLInterfaceType.prototype.getFields = function getFields() {
|
544 | return this._fields || (this._fields = defineFieldMap(this, this._typeConfig.fields));
|
545 | };
|
546 |
|
547 | GraphQLInterfaceType.prototype.toString = function toString() {
|
548 | return this.name;
|
549 | };
|
550 |
|
551 | return GraphQLInterfaceType;
|
552 | }();
|
553 |
|
554 |
|
555 |
|
556 |
|
557 | GraphQLInterfaceType.prototype.toJSON = GraphQLInterfaceType.prototype.inspect = GraphQLInterfaceType.prototype.toString;
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 | var GraphQLUnionType = exports.GraphQLUnionType = function () {
|
583 | function GraphQLUnionType(config) {
|
584 | _classCallCheck(this, GraphQLUnionType);
|
585 |
|
586 | this.name = config.name;
|
587 | this.description = config.description;
|
588 | this.astNode = config.astNode;
|
589 | this.resolveType = config.resolveType;
|
590 | this._typeConfig = config;
|
591 | !(typeof config.name === 'string') ? (0, _invariant2.default)(0, 'Must provide name.') : void 0;
|
592 | if (config.resolveType) {
|
593 | !(typeof config.resolveType === 'function') ? (0, _invariant2.default)(0, this.name + ' must provide "resolveType" as a function.') : void 0;
|
594 | }
|
595 | }
|
596 |
|
597 | GraphQLUnionType.prototype.getTypes = function getTypes() {
|
598 | return this._types || (this._types = defineTypes(this, this._typeConfig.types));
|
599 | };
|
600 |
|
601 | GraphQLUnionType.prototype.toString = function toString() {
|
602 | return this.name;
|
603 | };
|
604 |
|
605 | return GraphQLUnionType;
|
606 | }();
|
607 |
|
608 |
|
609 |
|
610 |
|
611 | GraphQLUnionType.prototype.toJSON = GraphQLUnionType.prototype.inspect = GraphQLUnionType.prototype.toString;
|
612 |
|
613 | function defineTypes(unionType, typesThunk) {
|
614 | var types = resolveThunk(typesThunk) || [];
|
615 | !Array.isArray(types) ? (0, _invariant2.default)(0, 'Must provide Array of types or a function which returns ' + ('such an array for Union ' + unionType.name + '.')) : void 0;
|
616 | return types;
|
617 | }
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 | var GraphQLEnumType = exports.GraphQLEnumType = function () {
|
641 | function GraphQLEnumType(config /* <T> */) {
|
642 | _classCallCheck(this, GraphQLEnumType);
|
643 |
|
644 | this.name = config.name;
|
645 | this.description = config.description;
|
646 | this.astNode = config.astNode;
|
647 | this._enumConfig = config;
|
648 | !(typeof config.name === 'string') ? (0, _invariant2.default)(0, 'Must provide name.') : void 0;
|
649 | }
|
650 |
|
651 | GraphQLEnumType.prototype.getValues = function getValues() {
|
652 | return this._values || (this._values = defineEnumValues(this, this._enumConfig.values));
|
653 | };
|
654 |
|
655 | GraphQLEnumType.prototype.getValue = function getValue(name) {
|
656 | return this._getNameLookup()[name];
|
657 | };
|
658 |
|
659 | GraphQLEnumType.prototype.serialize = function serialize(value /* T */) {
|
660 | var enumValue = this._getValueLookup().get(value);
|
661 | if (enumValue) {
|
662 | return enumValue.name;
|
663 | }
|
664 | };
|
665 |
|
666 | GraphQLEnumType.prototype.parseValue = function parseValue(value) /* T */{
|
667 | if (typeof value === 'string') {
|
668 | var enumValue = this._getNameLookup()[value];
|
669 | if (enumValue) {
|
670 | return enumValue.value;
|
671 | }
|
672 | }
|
673 | };
|
674 |
|
675 | GraphQLEnumType.prototype.parseLiteral = function parseLiteral(valueNode, _variables) /* T */{
|
676 |
|
677 | if (valueNode.kind === Kind.ENUM) {
|
678 | var enumValue = this._getNameLookup()[valueNode.value];
|
679 | if (enumValue) {
|
680 | return enumValue.value;
|
681 | }
|
682 | }
|
683 | };
|
684 |
|
685 | GraphQLEnumType.prototype._getValueLookup = function _getValueLookup() {
|
686 | if (!this._valueLookup) {
|
687 | var lookup = new Map();
|
688 | this.getValues().forEach(function (value) {
|
689 | lookup.set(value.value, value);
|
690 | });
|
691 | this._valueLookup = lookup;
|
692 | }
|
693 | return this._valueLookup;
|
694 | };
|
695 |
|
696 | GraphQLEnumType.prototype._getNameLookup = function _getNameLookup() {
|
697 | if (!this._nameLookup) {
|
698 | var lookup = Object.create(null);
|
699 | this.getValues().forEach(function (value) {
|
700 | lookup[value.name] = value;
|
701 | });
|
702 | this._nameLookup = lookup;
|
703 | }
|
704 | return this._nameLookup;
|
705 | };
|
706 |
|
707 | GraphQLEnumType.prototype.toString = function toString() {
|
708 | return this.name;
|
709 | };
|
710 |
|
711 | return GraphQLEnumType;
|
712 | }();
|
713 |
|
714 |
|
715 |
|
716 |
|
717 | GraphQLEnumType.prototype.toJSON = GraphQLEnumType.prototype.inspect = GraphQLEnumType.prototype.toString;
|
718 |
|
719 | function defineEnumValues(type, valueMap /* <T> */
|
720 | ) {
|
721 | !isPlainObj(valueMap) ? (0, _invariant2.default)(0, type.name + ' values must be an object with value names as keys.') : void 0;
|
722 | return Object.keys(valueMap).map(function (valueName) {
|
723 | var value = valueMap[valueName];
|
724 | !isPlainObj(value) ? (0, _invariant2.default)(0, type.name + '.' + valueName + ' must refer to an object with a "value" key ' + ('representing an internal value but got: ' + String(value) + '.')) : void 0;
|
725 | !!value.hasOwnProperty('isDeprecated') ? (0, _invariant2.default)(0, type.name + '.' + valueName + ' should provide "deprecationReason" instead ' + 'of "isDeprecated".') : void 0;
|
726 | return {
|
727 | name: valueName,
|
728 | description: value.description,
|
729 | isDeprecated: Boolean(value.deprecationReason),
|
730 | deprecationReason: value.deprecationReason,
|
731 | astNode: value.astNode,
|
732 | value: value.hasOwnProperty('value') ? value.value : valueName
|
733 | };
|
734 | });
|
735 | }
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 | var GraphQLInputObjectType = exports.GraphQLInputObjectType = function () {
|
758 | function GraphQLInputObjectType(config) {
|
759 | _classCallCheck(this, GraphQLInputObjectType);
|
760 |
|
761 | this.name = config.name;
|
762 | this.description = config.description;
|
763 | this.astNode = config.astNode;
|
764 | this._typeConfig = config;
|
765 | !(typeof config.name === 'string') ? (0, _invariant2.default)(0, 'Must provide name.') : void 0;
|
766 | }
|
767 |
|
768 | GraphQLInputObjectType.prototype.getFields = function getFields() {
|
769 | return this._fields || (this._fields = this._defineFieldMap());
|
770 | };
|
771 |
|
772 | GraphQLInputObjectType.prototype._defineFieldMap = function _defineFieldMap() {
|
773 | var _this = this;
|
774 |
|
775 | var fieldMap = resolveThunk(this._typeConfig.fields) || {};
|
776 | !isPlainObj(fieldMap) ? (0, _invariant2.default)(0, this.name + ' fields must be an object with field names as keys or a ' + 'function which returns such an object.') : void 0;
|
777 | var resultFieldMap = Object.create(null);
|
778 | Object.keys(fieldMap).forEach(function (fieldName) {
|
779 | var field = _extends({}, fieldMap[fieldName], {
|
780 | name: fieldName
|
781 | });
|
782 | !!field.hasOwnProperty('resolve') ? (0, _invariant2.default)(0, _this.name + '.' + fieldName + ' field type has a resolve property, but ' + 'Input Types cannot define resolvers.') : void 0;
|
783 | resultFieldMap[fieldName] = field;
|
784 | });
|
785 | return resultFieldMap;
|
786 | };
|
787 |
|
788 | GraphQLInputObjectType.prototype.toString = function toString() {
|
789 | return this.name;
|
790 | };
|
791 |
|
792 | return GraphQLInputObjectType;
|
793 | }();
|
794 |
|
795 |
|
796 |
|
797 |
|
798 | GraphQLInputObjectType.prototype.toJSON = GraphQLInputObjectType.prototype.toString;
|
799 | GraphQLInputObjectType.prototype.inspect = GraphQLInputObjectType.prototype.toString; |
\ | No newline at end of file |