UNPKG

28.1 kBJavaScriptView Raw
1// @generated
2/**
3 * Copyright (c) 2013-present, Facebook, Inc.
4 * All rights reserved.
5 *
6 * This source code is licensed under the BSD-style license found in the
7 * LICENSE file in the root directory of this source tree. An additional grant
8 * of patent rights can be found in the PATENTS file in the same directory.
9 *
10 *
11 * @fullSyntaxTransform
12 */
13
14// TODO: Import types from `graphql`.
15'use strict';
16
17var _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; };
18
19var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
20
21var _createClass = (function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
22
23function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
24
25function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
26
27var _require = require('./GraphQL');
28
29var types = _require.type;
30var _require$type_introspection = _require.type_introspection;
31var SchemaMetaFieldDef = _require$type_introspection.SchemaMetaFieldDef;
32var TypeMetaFieldDef = _require$type_introspection.TypeMetaFieldDef;
33var TypeNameMetaFieldDef = _require$type_introspection.TypeNameMetaFieldDef;
34
35var GraphQLRelayDirective = require('./GraphQLRelayDirective');
36
37var find = require('./find');
38var invariant = require('./invariant');
39
40var _nextFragmentID = 0;
41
42var RelayQLNode = (function () {
43 function RelayQLNode(context, ast) {
44 _classCallCheck(this, RelayQLNode);
45
46 this.ast = ast;
47 this.context = context;
48 }
49
50 _createClass(RelayQLNode, [{
51 key: 'getType',
52 value: function getType() {
53 invariant(false, 'Missing Implementation');
54 }
55 }, {
56 key: 'getField',
57 value: function getField(fieldName) {
58 return find(this.getFields(), function (field) {
59 return field.getName() === fieldName;
60 });
61 }
62 }, {
63 key: 'getFields',
64 value: function getFields() {
65 var fields = [];
66 this.getSelections().forEach(function (selection) {
67 if (selection instanceof RelayQLField) {
68 fields.push(selection);
69 }
70 });
71 return fields;
72 }
73 }, {
74 key: 'getSelections',
75 value: function getSelections() {
76 var _this = this;
77
78 if (!this.ast.selectionSet) {
79 return [];
80 }
81 return this.ast.selectionSet.selections.map(function (selection) {
82 if (selection.kind === 'Field') {
83 return new RelayQLField(_this.context, selection, _this.getType());
84 } else if (selection.kind === 'FragmentSpread') {
85 return new RelayQLFragmentSpread(_this.context, selection);
86 } else if (selection.kind === 'InlineFragment') {
87 return new RelayQLInlineFragment(_this.context, selection, _this.getType());
88 } else {
89 invariant(false, 'Unexpected selection kind: %s', selection.kind);
90 }
91 });
92 }
93 }, {
94 key: 'getDirectives',
95 value: function getDirectives() {
96 var _this2 = this;
97
98 return (this.ast.directives || []).map(function (directive) {
99 return new RelayQLDirective(_this2.context, directive);
100 });
101 }
102 }, {
103 key: 'hasDirective',
104 value: function hasDirective(name) {
105 return (this.ast.directives || []).some(function (d) {
106 return d.name.value === name;
107 });
108 }
109 }, {
110 key: 'isPattern',
111 value: function isPattern() {
112 return this.context.isPattern;
113 }
114 }]);
115
116 return RelayQLNode;
117})();
118
119var RelayQLDefinition = (function (_RelayQLNode) {
120 _inherits(RelayQLDefinition, _RelayQLNode);
121
122 function RelayQLDefinition() {
123 _classCallCheck(this, RelayQLDefinition);
124
125 _get(Object.getPrototypeOf(RelayQLDefinition.prototype), 'constructor', this).apply(this, arguments);
126 }
127
128 _createClass(RelayQLDefinition, [{
129 key: 'getName',
130 value: function getName() {
131 return this.ast.name ? this.ast.name.value : this.getType().getName({ modifiers: false }); // TODO: this.context.definitionName;
132 }
133 }]);
134
135 return RelayQLDefinition;
136})(RelayQLNode);
137
138var RelayQLFragment = (function (_RelayQLDefinition) {
139 _inherits(RelayQLFragment, _RelayQLDefinition);
140
141 function RelayQLFragment(context, ast, parentType) {
142 _classCallCheck(this, RelayQLFragment);
143
144 // @relay(pattern: true)
145 var isPattern = (ast.directives || []).some(function (directive) {
146 return directive.name.value === 'relay' && (directive.arguments || []).some(function (arg) {
147 return arg.name.value === 'pattern' && arg.value.kind === 'BooleanValue' && arg.value.value;
148 });
149 });
150 _get(Object.getPrototypeOf(RelayQLFragment.prototype), 'constructor', this).call(this, _extends({}, context, { isPattern: isPattern }), ast);
151 this.fragmentID = null;
152 this.parentType = parentType;
153 }
154
155 _createClass(RelayQLFragment, [{
156 key: 'getFragmentID',
157 value: function getFragmentID() {
158 if (this.fragmentID == null) {
159 var suffix = (_nextFragmentID++).toString(32);
160 // The fragmentLocationID is the same for all inline/nested fragments
161 // within each Relay.QL tagged template expression; the auto-incrementing
162 // suffix distinguishes these fragments from each other.
163 this.fragmentID = this.context.fragmentLocationID + ':' + suffix;
164 }
165 return this.fragmentID;
166 }
167 }, {
168 key: 'getType',
169 value: function getType() {
170 var type = this.ast.typeCondition;
171 if (type) {
172 // Convert `ListType` and `NonNullType` into `NamedType`.
173 while (type.kind !== 'NamedType') {
174 type = type.type;
175 }
176 return new RelayQLType(this.context, this.context.schema.getType(type.name.value));
177 } else if (this.ast.kind === 'InlineFragment') {
178 // Inline fragments without type conditions fall back to parent type.
179 invariant(this.parentType, 'Cannot get type of typeless inline fragment without parent type.');
180 return this.parentType;
181 } else {
182 invariant(false, 'Unexpected fragment kind: %s', this.ast.kind);
183 }
184 }
185 }]);
186
187 return RelayQLFragment;
188})(RelayQLDefinition);
189
190var RelayQLMutation = (function (_RelayQLDefinition2) {
191 _inherits(RelayQLMutation, _RelayQLDefinition2);
192
193 function RelayQLMutation() {
194 _classCallCheck(this, RelayQLMutation);
195
196 _get(Object.getPrototypeOf(RelayQLMutation.prototype), 'constructor', this).apply(this, arguments);
197 }
198
199 _createClass(RelayQLMutation, [{
200 key: 'getType',
201 value: function getType() {
202 return new RelayQLType(this.context, this.context.schema.getMutationType());
203 }
204 }]);
205
206 return RelayQLMutation;
207})(RelayQLDefinition);
208
209var RelayQLQuery = (function (_RelayQLDefinition3) {
210 _inherits(RelayQLQuery, _RelayQLDefinition3);
211
212 function RelayQLQuery() {
213 _classCallCheck(this, RelayQLQuery);
214
215 _get(Object.getPrototypeOf(RelayQLQuery.prototype), 'constructor', this).apply(this, arguments);
216 }
217
218 _createClass(RelayQLQuery, [{
219 key: 'getType',
220 value: function getType() {
221 return new RelayQLType(this.context, this.context.schema.getQueryType());
222 }
223 }]);
224
225 return RelayQLQuery;
226})(RelayQLDefinition);
227
228var RelayQLSubscription = (function (_RelayQLDefinition4) {
229 _inherits(RelayQLSubscription, _RelayQLDefinition4);
230
231 function RelayQLSubscription() {
232 _classCallCheck(this, RelayQLSubscription);
233
234 _get(Object.getPrototypeOf(RelayQLSubscription.prototype), 'constructor', this).apply(this, arguments);
235 }
236
237 _createClass(RelayQLSubscription, [{
238 key: 'getType',
239 value: function getType() {
240 return new RelayQLType(this.context, this.context.schema.getSubscriptionType());
241 }
242 }]);
243
244 return RelayQLSubscription;
245})(RelayQLDefinition);
246
247var RelayQLField = (function (_RelayQLNode2) {
248 _inherits(RelayQLField, _RelayQLNode2);
249
250 function RelayQLField(context, ast, parentType) {
251 _classCallCheck(this, RelayQLField);
252
253 _get(Object.getPrototypeOf(RelayQLField.prototype), 'constructor', this).call(this, context, ast);
254 var fieldName = this.ast.name.value;
255 var fieldDef = parentType.getFieldDefinition(fieldName, ast);
256 invariant(fieldDef, 'You supplied a field named `%s` on type `%s`, but no such field ' + 'exists on that type.', fieldName, parentType.getName({ modifiers: false }));
257 this.fieldDef = fieldDef;
258 }
259
260 _createClass(RelayQLField, [{
261 key: 'getName',
262 value: function getName() {
263 return this.ast.name.value;
264 }
265 }, {
266 key: 'getAlias',
267 value: function getAlias() {
268 return this.ast.alias ? this.ast.alias.value : null;
269 }
270 }, {
271 key: 'getType',
272 value: function getType() {
273 return this.fieldDef.getType();
274 }
275 }, {
276 key: 'hasArgument',
277 value: function hasArgument(argName) {
278 return this.getArguments().some(function (arg) {
279 return arg.getName() === argName;
280 });
281 }
282 }, {
283 key: 'getArguments',
284 value: function getArguments() {
285 var _this3 = this;
286
287 var argTypes = this.fieldDef.getDeclaredArguments();
288 return (this.ast.arguments || []).map(function (arg) {
289 var argName = arg.name.value;
290 var argType = argTypes[argName];
291 invariant(argType, 'You supplied an argument named `%s` on field `%s`, but no such ' + 'argument exists on that field.', argName, _this3.getName());
292 return new RelayQLArgument(_this3.context, arg, argType);
293 });
294 }
295 }, {
296 key: 'hasDeclaredArgument',
297 value: function hasDeclaredArgument(argName) {
298 return this.fieldDef.getDeclaredArguments().hasOwnProperty(argName);
299 }
300 }, {
301 key: 'getDeclaredArgument',
302 value: function getDeclaredArgument(argName) {
303 return this.fieldDef.getArgument(argName);
304 }
305 }, {
306 key: 'getDeclaredArguments',
307 value: function getDeclaredArguments() {
308 return this.fieldDef.getDeclaredArguments();
309 }
310 }]);
311
312 return RelayQLField;
313})(RelayQLNode);
314
315var RelayQLFragmentSpread = (function (_RelayQLNode3) {
316 _inherits(RelayQLFragmentSpread, _RelayQLNode3);
317
318 function RelayQLFragmentSpread() {
319 _classCallCheck(this, RelayQLFragmentSpread);
320
321 _get(Object.getPrototypeOf(RelayQLFragmentSpread.prototype), 'constructor', this).apply(this, arguments);
322 }
323
324 _createClass(RelayQLFragmentSpread, [{
325 key: 'getName',
326 value: function getName() {
327 return this.ast.name.value;
328 }
329 }, {
330 key: 'getSelections',
331 value: function getSelections() {
332 invariant(false, 'Cannot get selection of a fragment spread.');
333 }
334 }]);
335
336 return RelayQLFragmentSpread;
337})(RelayQLNode);
338
339var RelayQLInlineFragment = (function (_RelayQLNode4) {
340 _inherits(RelayQLInlineFragment, _RelayQLNode4);
341
342 function RelayQLInlineFragment(context, ast, parentType) {
343 _classCallCheck(this, RelayQLInlineFragment);
344
345 _get(Object.getPrototypeOf(RelayQLInlineFragment.prototype), 'constructor', this).call(this, context, ast);
346 this.parentType = parentType;
347 }
348
349 _createClass(RelayQLInlineFragment, [{
350 key: 'getFragment',
351 value: function getFragment() {
352 return new RelayQLFragment(this.context, this.ast, this.parentType);
353 }
354 }]);
355
356 return RelayQLInlineFragment;
357})(RelayQLNode);
358
359var RelayQLDirective = (function () {
360 function RelayQLDirective(context, ast) {
361 var _this4 = this;
362
363 _classCallCheck(this, RelayQLDirective);
364
365 this.ast = ast;
366 this.context = context;
367 this.argTypes = {};
368
369 var directiveName = ast.name.value;
370 var schemaDirective = directiveName === GraphQLRelayDirective.name ? GraphQLRelayDirective : context.schema.getDirective(directiveName);
371 invariant(schemaDirective, 'You supplied a directive named `%s`, but no such directive exists.', directiveName);
372 schemaDirective.args.forEach(function (schemaArg) {
373 _this4.argTypes[schemaArg.name] = new RelayQLArgumentType(schemaArg.type);
374 });
375 }
376
377 _createClass(RelayQLDirective, [{
378 key: 'getName',
379 value: function getName() {
380 return this.ast.name.value;
381 }
382 }, {
383 key: 'getArguments',
384 value: function getArguments() {
385 var _this5 = this;
386
387 return (this.ast.arguments || []).map(function (arg) {
388 var argName = arg.name.value;
389 var argType = _this5.argTypes[argName];
390 invariant(argType, 'You supplied an argument named `%s` on directive `%s`, but no ' + 'such argument exists on that directive.', argName, _this5.getName());
391 return new RelayQLArgument(_this5.context, arg, argType);
392 });
393 }
394 }]);
395
396 return RelayQLDirective;
397})();
398
399var RelayQLArgument = (function () {
400 function RelayQLArgument(context, ast, type) {
401 _classCallCheck(this, RelayQLArgument);
402
403 this.ast = ast;
404 this.context = context;
405 this.type = type;
406 }
407
408 _createClass(RelayQLArgument, [{
409 key: 'getName',
410 value: function getName() {
411 return this.ast.name.value;
412 }
413 }, {
414 key: 'getType',
415 value: function getType() {
416 return this.type;
417 }
418 }, {
419 key: 'isVariable',
420 value: function isVariable() {
421 return this.ast.value.kind === 'Variable';
422 }
423 }, {
424 key: 'getVariableName',
425 value: function getVariableName() {
426 invariant(this.ast.value.kind === 'Variable', 'Cannot get variable name of an argument value.');
427 return this.ast.value.name.value;
428 }
429 }, {
430 key: 'getValue',
431 value: function getValue() {
432 var _this6 = this;
433
434 invariant(!this.isVariable(), 'Cannot get value of an argument variable.');
435 var value = this.ast.value;
436 switch (value.kind) {
437 case 'IntValue':
438 return parseInt(value.value, 10);
439 case 'FloatValue':
440 return parseFloat(value.value);
441 case 'StringValue':
442 case 'BooleanValue':
443 case 'EnumValue':
444 return value.value;
445 case 'ListValue':
446 return value.values.map(function (value) {
447 return new RelayQLArgument(_this6.context, _extends({}, _this6.ast, { value: value }), _this6.type.ofType());
448 });
449 }
450 invariant(false, 'Unexpected argument kind: %s', value.kind);
451 }
452 }]);
453
454 return RelayQLArgument;
455})();
456
457var RelayQLType = (function () {
458 function RelayQLType(context, schemaModifiedType) {
459 _classCallCheck(this, RelayQLType);
460
461 this.context = context;
462
463 var _stripMarkerTypes = stripMarkerTypes(schemaModifiedType);
464
465 var isListType = _stripMarkerTypes.isListType;
466 var isNonNullType = _stripMarkerTypes.isNonNullType;
467 var schemaUnmodifiedType = _stripMarkerTypes.schemaUnmodifiedType;
468
469 this.isListType = isListType;
470 this.isNonNullType = isNonNullType;
471 this.schemaUnmodifiedType = schemaUnmodifiedType;
472 this.schemaModifiedType = schemaModifiedType;
473 }
474
475 _createClass(RelayQLType, [{
476 key: 'canHaveSubselections',
477 value: function canHaveSubselections() {
478 return !(this.schemaUnmodifiedType instanceof types.GraphQLScalarType || this.schemaUnmodifiedType instanceof types.GraphQLEnumType);
479 }
480 }, {
481 key: 'getName',
482 value: function getName(_ref) {
483 var modifiers = _ref.modifiers;
484 return (function () {
485 return modifiers ? this.schemaModifiedType.toString() : this.schemaUnmodifiedType.toString();
486 }).apply(this, arguments);
487 }
488 }, {
489 key: 'hasField',
490 value: function hasField(fieldName) {
491 return !!this.getFieldDefinition(fieldName);
492 }
493 }, {
494 key: 'getFieldDefinition',
495 value: function getFieldDefinition(fieldName, fieldAST) {
496 var type = this.schemaUnmodifiedType;
497 var isQueryType = type === this.context.schema.getQueryType();
498 var hasTypeName = type instanceof types.GraphQLObjectType || type instanceof types.GraphQLInterfaceType || type instanceof types.GraphQLUnionType;
499 var hasFields = type instanceof types.GraphQLObjectType || type instanceof types.GraphQLInterfaceType;
500
501 var schemaFieldDef = undefined;
502 if (isQueryType && fieldName === SchemaMetaFieldDef.name) {
503 schemaFieldDef = SchemaMetaFieldDef;
504 } else if (isQueryType && fieldName === TypeMetaFieldDef.name) {
505 schemaFieldDef = TypeMetaFieldDef;
506 } else if (hasTypeName && fieldName === TypeNameMetaFieldDef.name) {
507 schemaFieldDef = TypeNameMetaFieldDef;
508 } else if (hasFields) {
509 schemaFieldDef = type.getFields()[fieldName];
510 }
511
512 // Temporary workarounds to support legacy schemas
513 if (!schemaFieldDef) {
514 if (hasTypeName && fieldName === '__type__') {
515 schemaFieldDef = {
516 name: '__type__',
517 type: new types.GraphQLNonNull(this.context.schema.getType('Type')),
518 description: 'The introspected type of this object.',
519 deprecatedReason: 'Use __typename',
520 args: []
521 };
522 } else if (types.isAbstractType(type) && fieldAST && fieldAST.directives && fieldAST.directives.some(function (directive) {
523 return directive.name.value === 'fixme_fat_interface';
524 })) {
525 var possibleTypes = type.getPossibleTypes();
526
527 var _loop = function (ii) {
528 var possibleField = possibleTypes[ii].getFields()[fieldName];
529 if (possibleField) {
530 // Fat interface fields can have differing arguments. Try to return
531 // a field with matching arguments, but still return a field if the
532 // arguments do not match.
533 schemaFieldDef = possibleField;
534 if (fieldAST && fieldAST.arguments) {
535 var argumentsAllExist = fieldAST.arguments.every(function (argument) {
536 return find(possibleField.args, function (argDef) {
537 return argDef.name === argument.name.value;
538 });
539 });
540 if (argumentsAllExist) {
541 return 'break';
542 }
543 }
544 }
545 };
546
547 for (var ii = 0; ii < possibleTypes.length; ii++) {
548 var _ret = _loop(ii);
549
550 if (_ret === 'break') break;
551 }
552 }
553 }
554
555 return schemaFieldDef ? new RelayQLFieldDefinition(this.context, schemaFieldDef) : null;
556 }
557 }, {
558 key: 'getInterfaces',
559 value: function getInterfaces() {
560 var _this7 = this;
561
562 if (this.schemaUnmodifiedType instanceof types.GraphQLObjectType) {
563 return this.schemaUnmodifiedType.getInterfaces().map(function (schemaInterface) {
564 return new RelayQLType(_this7.context, schemaInterface);
565 });
566 }
567 return [];
568 }
569 }, {
570 key: 'getConcreteTypes',
571 value: function getConcreteTypes() {
572 var _this8 = this;
573
574 invariant(this.isAbstract(), 'Cannot get concrete types of a concrete type.');
575 return this.schemaUnmodifiedType.getPossibleTypes().map(function (concreteType) {
576 return new RelayQLType(_this8.context, concreteType);
577 });
578 }
579 }, {
580 key: 'getIdentifyingFieldDefinition',
581 value: function getIdentifyingFieldDefinition() {
582 if (this.alwaysImplements('Node')) {
583 return this.getFieldDefinition('id');
584 }
585 return null;
586 }
587 }, {
588 key: 'isAbstract',
589 value: function isAbstract() {
590 return types.isAbstractType(this.schemaUnmodifiedType);
591 }
592 }, {
593 key: 'isList',
594 value: function isList() {
595 return this.isListType;
596 }
597 }, {
598 key: 'isNonNull',
599 value: function isNonNull() {
600 return this.isNonNullType;
601 }
602 }, {
603 key: 'isConnection',
604 value: function isConnection() {
605 if (!/Connection$/.test(this.getName({ modifiers: false }))) {
606 return false;
607 }
608 var edges = this.getFieldDefinition('edges');
609 if (!edges || !edges.getType().canHaveSubselections()) {
610 return false;
611 }
612 var node = edges.getType().getFieldDefinition('node');
613 if (!node || !node.getType().canHaveSubselections()) {
614 return false;
615 }
616 var cursor = edges.getType().getFieldDefinition('cursor');
617 if (!cursor || cursor.getType().canHaveSubselections()) {
618 return false;
619 }
620 return true;
621 }
622 }, {
623 key: 'isConnectionEdge',
624 value: function isConnectionEdge() {
625 return (/Edge$/.test(this.getName({ modifiers: false })) && this.hasField('node') && this.hasField('cursor')
626 );
627 }
628 }, {
629 key: 'isConnectionPageInfo',
630 value: function isConnectionPageInfo() {
631 return this.getName({ modifiers: false }) === 'PageInfo';
632 }
633 }, {
634 key: 'alwaysImplements',
635 value: function alwaysImplements(typeName) {
636 return this.getName({ modifiers: false }) === typeName || this.getInterfaces().some(function (type) {
637 return type.getName({ modifiers: false }) === typeName;
638 }) || this.isAbstract() && this.getConcreteTypes().every(function (type) {
639 return type.alwaysImplements(typeName);
640 });
641 }
642 }, {
643 key: 'mayImplement',
644 value: function mayImplement(typeName) {
645 return this.getName({ modifiers: false }) === typeName || this.getInterfaces().some(function (type) {
646 return type.getName({ modifiers: false }) === typeName;
647 }) || this.isAbstract() && this.getConcreteTypes().some(function (type) {
648 return type.alwaysImplements(typeName);
649 });
650 }
651 }, {
652 key: 'generateField',
653 value: function generateField(fieldName) {
654 var generatedFieldAST = {
655 kind: 'Field',
656 name: {
657 kind: 'Name',
658 value: fieldName
659 }
660 };
661 return new RelayQLField(this.context, generatedFieldAST, this);
662 }
663 }, {
664 key: 'generateIdFragment',
665 value: function generateIdFragment() {
666 var generatedFragmentAST = {
667 kind: 'Fragment',
668 name: {
669 kind: 'Name',
670 value: 'IdFragment'
671 },
672 typeCondition: {
673 kind: 'NamedType',
674 name: {
675 value: 'Node'
676 }
677 },
678 selectionSet: {
679 selections: [{
680 kind: 'Field',
681 name: {
682 name: 'Name',
683 value: 'id'
684 }
685 }]
686 }
687 };
688 return new RelayQLFragment(this.context, generatedFragmentAST, this);
689 }
690 }]);
691
692 return RelayQLType;
693})();
694
695var RelayQLFieldDefinition = (function () {
696 function RelayQLFieldDefinition(context, schemaFieldDef) {
697 _classCallCheck(this, RelayQLFieldDefinition);
698
699 this.context = context;
700 this.schemaFieldDef = schemaFieldDef;
701 }
702
703 _createClass(RelayQLFieldDefinition, [{
704 key: 'getName',
705 value: function getName() {
706 return this.schemaFieldDef.name;
707 }
708 }, {
709 key: 'getType',
710 value: function getType() {
711 return new RelayQLType(this.context, this.schemaFieldDef.type);
712 }
713 }, {
714 key: 'hasArgument',
715 value: function hasArgument(argName) {
716 return this.schemaFieldDef.args.some(function (schemaArg) {
717 return schemaArg.name === argName;
718 });
719 }
720 }, {
721 key: 'getArgument',
722 value: function getArgument(argName) {
723 var schemaArg = find(this.schemaFieldDef.args, function (schemaArg) {
724 return schemaArg.name === argName;
725 });
726 invariant(schemaArg, 'You tried to get an argument named `%s` on field `%s`, but no such ' + 'argument exists on that field.', argName, this.getName());
727 return new RelayQLArgumentType(schemaArg.type);
728 }
729 }, {
730 key: 'getDeclaredArguments',
731 value: function getDeclaredArguments() {
732 var args = {};
733 this.schemaFieldDef.args.forEach(function (schemaArg) {
734 args[schemaArg.name] = new RelayQLArgumentType(schemaArg.type);
735 });
736 return args;
737 }
738 }]);
739
740 return RelayQLFieldDefinition;
741})();
742
743var RelayQLArgumentType = (function () {
744 function RelayQLArgumentType(schemaModifiedArgType) {
745 _classCallCheck(this, RelayQLArgumentType);
746
747 var _stripMarkerTypes2 = stripMarkerTypes(schemaModifiedArgType);
748
749 var isListType = _stripMarkerTypes2.isListType;
750 var isNonNullType = _stripMarkerTypes2.isNonNullType;
751 var schemaUnmodifiedType = _stripMarkerTypes2.schemaUnmodifiedType;
752
753 this.isListType = isListType;
754 this.isNonNullType = isNonNullType;
755 this.schemaUnmodifiedArgType = schemaUnmodifiedType;
756 this.schemaModifiedArgType = schemaModifiedArgType;
757 }
758
759 _createClass(RelayQLArgumentType, [{
760 key: 'getName',
761 value: function getName(_ref2) {
762 var modifiers = _ref2.modifiers;
763 return (function () {
764 return modifiers ? this.schemaModifiedArgType.toString() : this.schemaUnmodifiedArgType.toString();
765 }).apply(this, arguments);
766 }
767 }, {
768 key: 'ofType',
769 value: function ofType() {
770 invariant(this.isList() || this.isNonNull(), 'Can only get type of list or non-null type.');
771 return new RelayQLArgumentType(this.schemaUnmodifiedArgType);
772 }
773 }, {
774 key: 'isEnum',
775 value: function isEnum() {
776 return this.schemaUnmodifiedArgType instanceof types.GraphQLEnumType;
777 }
778 }, {
779 key: 'isList',
780 value: function isList() {
781 return this.isListType;
782 }
783 }, {
784 key: 'isNonNull',
785 value: function isNonNull() {
786 return this.isNonNullType;
787 }
788 }, {
789 key: 'isObject',
790 value: function isObject() {
791 return this.schemaUnmodifiedArgType instanceof types.GraphQLInputObjectType;
792 }
793 }, {
794 key: 'isScalar',
795 value: function isScalar() {
796 return this.schemaUnmodifiedArgType instanceof types.GraphQLScalarType;
797 }
798 }]);
799
800 return RelayQLArgumentType;
801})();
802
803function stripMarkerTypes(schemaModifiedType) {
804 var isListType = false;
805 var isNonNullType = false;
806 var schemaUnmodifiedType = schemaModifiedType;
807 while (true) {
808 if (schemaUnmodifiedType instanceof types.GraphQLList) {
809 isListType = true;
810 } else if (schemaUnmodifiedType instanceof types.GraphQLNonNull) {
811 isNonNullType = true;
812 } else {
813 break;
814 }
815 schemaUnmodifiedType = schemaUnmodifiedType.ofType;
816 }
817 return { isListType: isListType, isNonNullType: isNonNullType, schemaUnmodifiedType: schemaUnmodifiedType };
818}
819
820module.exports = {
821 RelayQLArgument: RelayQLArgument,
822 RelayQLArgumentType: RelayQLArgumentType,
823 RelayQLDefinition: RelayQLDefinition,
824 RelayQLDirective: RelayQLDirective,
825 RelayQLField: RelayQLField,
826 RelayQLFieldDefinition: RelayQLFieldDefinition,
827 RelayQLFragment: RelayQLFragment,
828 RelayQLFragmentSpread: RelayQLFragmentSpread,
829 RelayQLInlineFragment: RelayQLInlineFragment,
830 RelayQLMutation: RelayQLMutation,
831 RelayQLNode: RelayQLNode,
832 RelayQLQuery: RelayQLQuery,
833 RelayQLSubscription: RelayQLSubscription,
834 RelayQLType: RelayQLType
835};
\No newline at end of file