babel-plugin-relay 2.0.0-rc.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,9 +10,29 @@
10
10
  */
11
11
  'use strict';
12
12
 
13
- var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
13
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
14
14
 
15
- var _toConsumableArray2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/toConsumableArray"));
15
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
16
+
17
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
18
+
19
+ var RelayTransformError = require("./RelayTransformError");
20
+
21
+ var find = require("./find");
22
+
23
+ var util = require("util");
24
+
25
+ var _require = require("./RelayQLAST"),
26
+ RelayQLField = _require.RelayQLField,
27
+ RelayQLFragment = _require.RelayQLFragment,
28
+ RelayQLFragmentSpread = _require.RelayQLFragmentSpread,
29
+ RelayQLInlineFragment = _require.RelayQLInlineFragment,
30
+ RelayQLMutation = _require.RelayQLMutation,
31
+ RelayQLQuery = _require.RelayQLQuery,
32
+ RelayQLSubscription = _require.RelayQLSubscription;
33
+
34
+ var _require2 = require("./RelayQLNodeInterface"),
35
+ ID = _require2.ID;
16
36
 
17
37
  module.exports = function (t, options) {
18
38
  var formatFields = options.snakeCase ? function (fields) {
@@ -55,16 +75,16 @@ module.exports = function (t, options) {
55
75
  var enableValidation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
56
76
  var printedDocument;
57
77
 
58
- if (definition instanceof require("./RelayQLAST").RelayQLQuery) {
78
+ if (definition instanceof RelayQLQuery) {
59
79
  printedDocument = this.printQuery(definition, enableValidation);
60
- } else if (definition instanceof require("./RelayQLAST").RelayQLFragment) {
80
+ } else if (definition instanceof RelayQLFragment) {
61
81
  printedDocument = this.printFragment(definition);
62
- } else if (definition instanceof require("./RelayQLAST").RelayQLMutation) {
82
+ } else if (definition instanceof RelayQLMutation) {
63
83
  printedDocument = this.printMutation(definition, enableValidation);
64
- } else if (definition instanceof require("./RelayQLAST").RelayQLSubscription) {
84
+ } else if (definition instanceof RelayQLSubscription) {
65
85
  printedDocument = this.printSubscription(definition, enableValidation);
66
86
  } else {
67
- throw new (require("./RelayTransformError"))(require("util").format('Unsupported definition: %s', definition), definition.getLocation());
87
+ throw new RelayTransformError(util.format('Unsupported definition: %s', definition), definition.getLocation());
68
88
  }
69
89
 
70
90
  return t.callExpression(t.functionExpression(null, substitutions.map(function (substitution) {
@@ -78,7 +98,7 @@ module.exports = function (t, options) {
78
98
  var rootFields = query.getFields();
79
99
 
80
100
  if (rootFields.length !== 1 && enableValidation) {
81
- throw new (require("./RelayTransformError"))(require("util").format('There are %d fields supplied to the query named `%s`, but queries ' + 'must have exactly one field.', rootFields.length, query.getName()), query.getLocation());
101
+ throw new RelayTransformError(util.format('There are %d fields supplied to the query named `%s`, but queries ' + 'must have exactly one field.', rootFields.length, query.getName()), query.getLocation());
82
102
  }
83
103
 
84
104
  var rootField = rootFields[0];
@@ -107,7 +127,7 @@ module.exports = function (t, options) {
107
127
  }
108
128
 
109
129
  if (rootFieldArgs.length > 1) {
110
- throw new (require("./RelayTransformError"))(require("util").format('Invalid root field `%s`; Relay only supports root fields with zero ' + 'or one argument.', rootField.getName()), query.getLocation());
130
+ throw new RelayTransformError(util.format('Invalid root field `%s`; Relay only supports root fields with zero ' + 'or one argument.', rootField.getName()), query.getLocation());
111
131
  }
112
132
 
113
133
  var calls = NULL;
@@ -154,8 +174,8 @@ module.exports = function (t, options) {
154
174
  var requisiteFields = {};
155
175
  var idFragment;
156
176
 
157
- if (fragmentType.hasField(require("./RelayQLNodeInterface").ID)) {
158
- requisiteFields[require("./RelayQLNodeInterface").ID] = true;
177
+ if (fragmentType.hasField(ID)) {
178
+ requisiteFields[ID] = true;
159
179
  } else if (shouldGenerateIdFragment(fragment)) {
160
180
  idFragment = fragmentType.generateIdFragment();
161
181
  }
@@ -166,11 +186,9 @@ module.exports = function (t, options) {
166
186
 
167
187
  var selections = this.printSelections(fragment, requisiteFields, idFragment ? [idFragment] : null, fragment.hasDirective('generated'));
168
188
  var relayDirective = findRelayDirective(fragment);
169
-
170
- var selectVariables = relayDirective && require("./find")(relayDirective.getArguments(), function (arg) {
189
+ var selectVariables = relayDirective && find(relayDirective.getArguments(), function (arg) {
171
190
  return arg.getName() === 'variables';
172
191
  });
173
-
174
192
  var metadata = this.printRelayDirectiveMetadata(fragment, {
175
193
  isAbstract: fragmentType.isAbstract(),
176
194
  isTrackingEnabled: !!selectVariables
@@ -191,7 +209,7 @@ module.exports = function (t, options) {
191
209
  var selectVariablesValue = selectVariables.getValue();
192
210
 
193
211
  if (!Array.isArray(selectVariablesValue)) {
194
- throw new (require("./RelayTransformError"))('The variables argument to the @relay directive should be an array ' + 'of strings.', fragment.getLocation());
212
+ throw new RelayTransformError('The variables argument to the @relay directive should be an array ' + 'of strings.', fragment.getLocation());
195
213
  }
196
214
 
197
215
  return t.callExpression(t.memberExpression(identify(this.tagName), t.identifier('__createFragment')), [fragmentCode, t.objectExpression(selectVariablesValue.map(function (item) {
@@ -212,7 +230,7 @@ module.exports = function (t, options) {
212
230
  var rootFields = mutation.getFields();
213
231
 
214
232
  if (rootFields.length !== 1 && enableValidation) {
215
- throw new (require("./RelayTransformError"))(require("util").format('There are %d fields supplied to the mutation named `%s`, but ' + 'mutations must have exactly one field.', rootFields.length, mutation.getName()), mutation.getLocation());
233
+ throw new RelayTransformError(util.format('There are %d fields supplied to the mutation named `%s`, but ' + 'mutations must have exactly one field.', rootFields.length, mutation.getName()), mutation.getLocation());
216
234
  }
217
235
 
218
236
  var rootField = rootFields[0];
@@ -250,7 +268,7 @@ module.exports = function (t, options) {
250
268
  var rootFields = subscription.getFields();
251
269
 
252
270
  if (rootFields.length !== 1 && enableValidation) {
253
- throw new (require("./RelayTransformError"))(require("util").format('There are %d fields supplied to the subscription named `%s`, but ' + 'subscriptions must have exactly one field.', rootFields.length, subscription.getName()), subscription.getLocation());
271
+ throw new RelayTransformError(util.format('There are %d fields supplied to the subscription named `%s`, but ' + 'subscriptions must have exactly one field.', rootFields.length, subscription.getName()), subscription.getLocation());
254
272
  }
255
273
 
256
274
  var rootField = rootFields[0];
@@ -296,20 +314,20 @@ module.exports = function (t, options) {
296
314
  var printedFragments = [];
297
315
  var didPrintFragmentReference = false;
298
316
  parent.getSelections().forEach(function (selection) {
299
- if (selection instanceof require("./RelayQLAST").RelayQLFragmentSpread) {
317
+ if (selection instanceof RelayQLFragmentSpread) {
300
318
  // Assume that all spreads exist via template substitution.
301
319
  if (selection.getDirectives().length !== 0) {
302
- throw new (require("./RelayTransformError"))('Directives are not yet supported for `${fragment}`-style fragment ' + 'references.', selection.getLocation());
320
+ throw new RelayTransformError('Directives are not yet supported for `${fragment}`-style fragment ' + 'references.', selection.getLocation());
303
321
  }
304
322
 
305
323
  printedFragments.push(_this2.printFragmentReference(selection));
306
324
  didPrintFragmentReference = true;
307
- } else if (selection instanceof require("./RelayQLAST").RelayQLInlineFragment) {
325
+ } else if (selection instanceof RelayQLInlineFragment) {
308
326
  printedFragments.push(_this2.printFragment(selection.getFragment()));
309
- } else if (selection instanceof require("./RelayQLAST").RelayQLField) {
327
+ } else if (selection instanceof RelayQLField) {
310
328
  fields.push(selection);
311
329
  } else {
312
- throw new (require("./RelayTransformError"))(require("util").format('Unsupported selection type `%s`.', selection), selection.getLocation());
330
+ throw new RelayTransformError(util.format('Unsupported selection type `%s`.', selection), selection.getLocation());
313
331
  }
314
332
  });
315
333
 
@@ -320,7 +338,7 @@ module.exports = function (t, options) {
320
338
  }
321
339
 
322
340
  var printedFields = this.printFields(fields, parent, requisiteFields, isGeneratedQuery);
323
- var selections = (0, _toConsumableArray2["default"])(printedFields).concat(printedFragments);
341
+ var selections = [].concat((0, _toConsumableArray2["default"])(printedFields), printedFragments);
324
342
 
325
343
  if (selections.length) {
326
344
  var arrayExpressionOfSelections = t.arrayExpression(selections);
@@ -364,8 +382,8 @@ module.exports = function (t, options) {
364
382
  var requisiteFields = {};
365
383
  var idFragment;
366
384
 
367
- if (fieldType.hasField(require("./RelayQLNodeInterface").ID)) {
368
- requisiteFields[require("./RelayQLNodeInterface").ID] = true;
385
+ if (fieldType.hasField(ID)) {
386
+ requisiteFields[ID] = true;
369
387
  } else if (shouldGenerateIdFragment(field)) {
370
388
  idFragment = fieldType.generateIdFragment();
371
389
  }
@@ -381,7 +399,7 @@ module.exports = function (t, options) {
381
399
 
382
400
  if (fieldType.alwaysImplements('Node')) {
383
401
  metadata.inferredRootCallName = 'node';
384
- metadata.inferredPrimaryKey = require("./RelayQLNodeInterface").ID;
402
+ metadata.inferredPrimaryKey = ID;
385
403
  }
386
404
 
387
405
  if (fieldType.isConnection()) {
@@ -532,7 +550,7 @@ module.exports = function (t, options) {
532
550
  if (relayDirective) {
533
551
  relayDirective.getArguments().forEach(function (arg) {
534
552
  if (arg.isVariable()) {
535
- throw new (require("./RelayTransformError"))(require("util").format('You supplied `$%s` as the `%s` argument to the `@relay` ' + 'directive, but `@relay` require scalar argument values.', arg.getVariableName(), arg.getName()), node.getLocation());
553
+ throw new RelayTransformError(util.format('You supplied `$%s` as the `%s` argument to the `@relay` ' + 'directive, but `@relay` require scalar argument values.', arg.getVariableName(), arg.getName()), node.getLocation());
536
554
  }
537
555
 
538
556
  if (arg.getName() !== 'variables') {
@@ -551,11 +569,11 @@ module.exports = function (t, options) {
551
569
  }
552
570
 
553
571
  return t.objectExpression(properties);
554
- };
572
+ }
555
573
  /**
556
574
  * Prints the type for arguments that are transmitted via variables.
557
575
  */
558
-
576
+ ;
559
577
 
560
578
  _proto.printArgumentTypeForMetadata = function printArgumentTypeForMetadata(argType) {
561
579
  // Only booleans and strings can be safely inlined, which is indicated to
@@ -589,7 +607,7 @@ module.exports = function (t, options) {
589
607
 
590
608
  function shouldGenerateIdFragment(node) {
591
609
  return node.getType().mayImplement('Node') && !node.getSelections().some(function (selection) {
592
- return selection instanceof require("./RelayQLAST").RelayQLInlineFragment && selection.getFragment().getType().getName({
610
+ return selection instanceof RelayQLInlineFragment && selection.getFragment().getType().getName({
593
611
  modifiers: false
594
612
  }) === 'Node';
595
613
  });
@@ -600,8 +618,8 @@ module.exports = function (t, options) {
600
618
  var argTypes = field.getDeclaredArguments();
601
619
  var argNames = Object.keys(argTypes);
602
620
 
603
- if (!parentType.isQueryType() && argNames.length === 1 && argNames[0] === require("./RelayQLNodeInterface").ID) {
604
- throw new (require("./RelayTransformError"))(require("util").format('You defined a `node(%s: %s)` field on type `%s`, but Relay requires ' + 'the `node` field to be defined on the root type. See the Object ' + 'Identification Guide: \n' + 'http://facebook.github.io/relay/docs/graphql-object-identification.html', require("./RelayQLNodeInterface").ID, argNames[0] && argTypes[argNames[0]].getName({
621
+ if (!parentType.isQueryType() && argNames.length === 1 && argNames[0] === ID) {
622
+ throw new RelayTransformError(util.format('You defined a `node(%s: %s)` field on type `%s`, but Relay requires ' + 'the `node` field to be defined on the root type. See the Object ' + 'Identification Guide: \n' + 'https://relay.dev/docs/en/graphql-server-specification#object-identification', ID, argNames[0] && argTypes[argNames[0]].getName({
605
623
  modifiers: true
606
624
  }), parentType.getName({
607
625
  modifiers: false
@@ -619,19 +637,19 @@ module.exports = function (t, options) {
619
637
  var condition = !first || !last || first.isVariable() && last.isVariable();
620
638
 
621
639
  if (!condition) {
622
- throw new (require("./RelayTransformError"))(require("util").format('Connection arguments `%s(first: <count>, last: <count>)` are ' + 'not supported unless both are variables. Use `(first: <count>)`, ' + '`(last: <count>)`, or `(first: $<var>, last: $<var>)`.', field.getName()), field.getLocation());
640
+ throw new RelayTransformError(util.format('Connection arguments `%s(first: <count>, last: <count>)` are ' + 'not supported unless both are variables. Use `(first: <count>)`, ' + '`(last: <count>)`, or `(first: $<var>, last: $<var>)`.', field.getName()), field.getLocation());
623
641
  }
624
642
 
625
643
  condition = !first || !before || first.isVariable() && before.isVariable();
626
644
 
627
645
  if (!condition) {
628
- throw new (require("./RelayTransformError"))(require("util").format('Connection arguments `%s(before: <cursor>, first: <count>)` are ' + 'not supported unless both are variables. Use `(first: <count>)`, ' + '`(after: <cursor>, first: <count>)`, `(before: <cursor>, last: <count>)`, ' + 'or `(before: $<var>, first: $<var>)`.', field.getName()), field.getLocation());
646
+ throw new RelayTransformError(util.format('Connection arguments `%s(before: <cursor>, first: <count>)` are ' + 'not supported unless both are variables. Use `(first: <count>)`, ' + '`(after: <cursor>, first: <count>)`, `(before: <cursor>, last: <count>)`, ' + 'or `(before: $<var>, first: $<var>)`.', field.getName()), field.getLocation());
629
647
  }
630
648
 
631
649
  condition = !last || !after || last.isVariable() && after.isVariable();
632
650
 
633
651
  if (!condition) {
634
- throw new (require("./RelayTransformError"))(require("util").format('Connection arguments `%s(after: <cursor>, last: <count>)` are ' + 'not supported unless both are variables. Use `(last: <count>)`, ' + '`(before: <cursor>, last: <count>)`, `(after: <cursor>, first: <count>)`, ' + 'or `(after: $<var>, last: $<var>)`.', field.getName()), field.getLocation());
652
+ throw new RelayTransformError(util.format('Connection arguments `%s(after: <cursor>, last: <count>)` are ' + 'not supported unless both are variables. Use `(last: <count>)`, ' + '`(before: <cursor>, last: <count>)`, `(after: <cursor>, first: <count>)`, ' + 'or `(after: $<var>, last: $<var>)`.', field.getName()), field.getLocation());
635
653
  } // Use `any` because we already check `isConnection` before validating.
636
654
 
637
655
 
@@ -642,7 +660,7 @@ module.exports = function (t, options) {
642
660
  var hasCondition = field.isPattern() || field.hasArgument('find') || field.hasArgument('first') || field.hasArgument('last');
643
661
 
644
662
  if (!hasCondition) {
645
- throw new (require("./RelayTransformError"))(require("util").format('You supplied the `%s` field on a connection named `%s`, but you did ' + 'not supply an argument necessary for Relay to handle the connection. ' + 'Please specify a limit argument like `first`, or `last` or ' + 'fetch a specific item with a `find` argument.', subfield.getName(), field.getName()), field.getLocation());
663
+ throw new RelayTransformError(util.format('You supplied the `%s` field on a connection named `%s`, but you did ' + 'not supply an argument necessary for Relay to handle the connection. ' + 'Please specify a limit argument like `first`, or `last` or ' + 'fetch a specific item with a `find` argument.', subfield.getName(), field.getName()), field.getLocation());
646
664
  }
647
665
  } else {
648
666
  // Suggest `edges{node{...}}` instead of `nodes{...}`.
@@ -654,7 +672,7 @@ module.exports = function (t, options) {
654
672
  });
655
673
 
656
674
  if (isNodesLikeField) {
657
- throw new (require("./RelayTransformError"))(require("util").format('You supplied a field named `%s` on a connection named `%s`, but ' + 'pagination is not supported on connections without using `%s`. ' + 'Use `%s{%s{%s{...}}}` instead.', subfield.getName(), field.getName(), FIELDS.edges, field.getName(), FIELDS.edges, FIELDS.node), field.getLocation());
675
+ throw new RelayTransformError(util.format('You supplied a field named `%s` on a connection named `%s`, but ' + 'pagination is not supported on connections without using `%s`. ' + 'Use `%s{%s{%s{...}}}` instead.', subfield.getName(), field.getName(), FIELDS.edges, field.getName(), FIELDS.edges, FIELDS.node), field.getLocation());
658
676
  }
659
677
  }
660
678
  });
@@ -665,25 +683,25 @@ module.exports = function (t, options) {
665
683
  var declaredArgNames = Object.keys(declaredArgs);
666
684
 
667
685
  if (declaredArgNames.length !== 1) {
668
- throw new (require("./RelayTransformError"))(require("util").format('Your schema defines a mutation field `%s` that takes %d arguments, ' + 'but mutation fields must have exactly one argument named `%s`.', rootField.getName(), declaredArgNames.length, INPUT_ARGUMENT_NAME), rootField.getLocation());
686
+ throw new RelayTransformError(util.format('Your schema defines a mutation field `%s` that takes %d arguments, ' + 'but mutation fields must have exactly one argument named `%s`.', rootField.getName(), declaredArgNames.length, INPUT_ARGUMENT_NAME), rootField.getLocation());
669
687
  }
670
688
 
671
689
  if (declaredArgNames[0] !== INPUT_ARGUMENT_NAME) {
672
- throw new (require("./RelayTransformError"))(require("util").format('Your schema defines a mutation field `%s` that takes an argument ' + 'named `%s`, but mutation fields must have exactly one argument ' + 'named `%s`.', rootField.getName(), declaredArgNames[0], INPUT_ARGUMENT_NAME), rootField.getLocation());
690
+ throw new RelayTransformError(util.format('Your schema defines a mutation field `%s` that takes an argument ' + 'named `%s`, but mutation fields must have exactly one argument ' + 'named `%s`.', rootField.getName(), declaredArgNames[0], INPUT_ARGUMENT_NAME), rootField.getLocation());
673
691
  }
674
692
 
675
693
  var rootFieldArgs = rootField.getArguments();
676
694
 
677
695
  if (rootFieldArgs.length > 1) {
678
- throw new (require("./RelayTransformError"))(require("util").format('There are %d arguments supplied to the mutation field named `%s`, ' + 'but mutation fields must have exactly one `%s` argument.', rootFieldArgs.length, rootField.getName(), INPUT_ARGUMENT_NAME), rootField.getLocation());
696
+ throw new RelayTransformError(util.format('There are %d arguments supplied to the mutation field named `%s`, ' + 'but mutation fields must have exactly one `%s` argument.', rootFieldArgs.length, rootField.getName(), INPUT_ARGUMENT_NAME), rootField.getLocation());
679
697
  }
680
698
  }
681
699
 
682
700
  var forEachRecursiveField = function forEachRecursiveField(parentSelection, callback) {
683
701
  parentSelection.getSelections().forEach(function (selection) {
684
- if (selection instanceof require("./RelayQLAST").RelayQLField) {
702
+ if (selection instanceof RelayQLField) {
685
703
  callback(selection);
686
- } else if (selection instanceof require("./RelayQLAST").RelayQLInlineFragment) {
704
+ } else if (selection instanceof RelayQLInlineFragment) {
687
705
  forEachRecursiveField(selection.getFragment(), callback);
688
706
  } // Ignore `RelayQLFragmentSpread` selections.
689
707
 
@@ -748,7 +766,7 @@ module.exports = function (t, options) {
748
766
  }
749
767
 
750
768
  function findRelayDirective(node) {
751
- return require("./find")(node.getDirectives(), function (directive) {
769
+ return find(node.getDirectives(), function (directive) {
752
770
  return directive.getName() === 'relay';
753
771
  });
754
772
  }
@@ -10,6 +10,31 @@
10
10
  */
11
11
  'use strict';
12
12
 
13
+ var RelayQLPrinter = require("./RelayQLPrinter");
14
+
15
+ var invariant = require("./invariant");
16
+
17
+ var util = require("util");
18
+
19
+ var _require = require("./RelayQLAST"),
20
+ RelayQLFragment = _require.RelayQLFragment,
21
+ RelayQLMutation = _require.RelayQLMutation,
22
+ RelayQLQuery = _require.RelayQLQuery,
23
+ RelayQLSubscription = _require.RelayQLSubscription;
24
+
25
+ var _require2 = require("graphql"),
26
+ formatError = _require2.formatError,
27
+ parse = _require2.parse,
28
+ Source = _require2.Source,
29
+ validate = _require2.validate,
30
+ FieldsOnCorrectTypeRule = _require2.FieldsOnCorrectTypeRule,
31
+ FragmentsOnCompositeTypesRule = _require2.FragmentsOnCompositeTypesRule,
32
+ KnownArgumentNamesRule = _require2.KnownArgumentNamesRule,
33
+ KnownTypeNamesRule = _require2.KnownTypeNamesRule,
34
+ PossibleFragmentSpreadsRule = _require2.PossibleFragmentSpreadsRule,
35
+ ValuesOfCorrectTypeRule = _require2.ValuesOfCorrectTypeRule,
36
+ VariablesInAllowedPositionRule = _require2.VariablesInAllowedPositionRule;
37
+
13
38
  /**
14
39
  * Transforms a TemplateLiteral node into a RelayQLDefinition, which is then
15
40
  * transformed into a Babel AST via RelayQLPrinter.
@@ -33,17 +58,15 @@ function () {
33
58
 
34
59
  var documentText = this.processTemplateText(templateText, options);
35
60
  var definition = this.processDocumentText(documentText, options);
36
-
37
- var Printer = require("./RelayQLPrinter")(t, this.options);
38
-
61
+ var Printer = RelayQLPrinter(t, this.options);
39
62
  return new Printer(options.tagName, variableNames).print(definition, substitutions, options.enableValidation);
40
- };
63
+ }
41
64
  /**
42
65
  * Convert TemplateLiteral into a single template string with substitution
43
66
  * names, a matching array of substituted values, and a set of substituted
44
67
  * variable names.
45
68
  */
46
-
69
+ ;
47
70
 
48
71
  _proto.processTemplateLiteral = function processTemplateLiteral(node, documentName) {
49
72
  var _this = this;
@@ -64,7 +87,7 @@ function () {
64
87
  });
65
88
 
66
89
  if (/:\s*$/.test(chunk)) {
67
- !_this.options.substituteVariables ? process.env.NODE_ENV !== "production" ? require("./invariant")(false, 'You supplied a GraphQL document named `%s` that uses template ' + 'substitution for an argument value, but variable substitution ' + 'has not been enabled.', documentName) : require("./invariant")(false) : void 0;
90
+ !_this.options.substituteVariables ? process.env.NODE_ENV !== "production" ? invariant(false, 'You supplied a GraphQL document named `%s` that uses template ' + 'substitution for an argument value, but variable substitution ' + 'has not been enabled.', documentName) : invariant(false) : void 0;
68
91
  chunks.push('$' + name);
69
92
  variableNames[name] = undefined;
70
93
  } else {
@@ -77,18 +100,18 @@ function () {
77
100
  templateText: chunks.join('').trim(),
78
101
  variableNames: variableNames
79
102
  };
80
- };
103
+ }
81
104
  /**
82
105
  * Converts the template string into a valid GraphQL document string.
83
106
  */
84
-
107
+ ;
85
108
 
86
109
  _proto.processTemplateText = function processTemplateText(templateText, _ref) {
87
110
  var documentName = _ref.documentName,
88
111
  propName = _ref.propName;
89
112
  var pattern = /^(fragment|mutation|query|subscription)\s*(\w*)?([\s\S]*)/;
90
113
  var matches = pattern.exec(templateText);
91
- !matches ? process.env.NODE_ENV !== "production" ? require("./invariant")(false, 'You supplied a GraphQL document named `%s` with invalid syntax. It ' + 'must start with `fragment`, `mutation`, `query`, or `subscription`.', documentName) : require("./invariant")(false) : void 0;
114
+ !matches ? process.env.NODE_ENV !== "production" ? invariant(false, 'You supplied a GraphQL document named `%s` with invalid syntax. It ' + 'must start with `fragment`, `mutation`, `query`, or `subscription`.', documentName) : invariant(false) : void 0;
92
115
  var type = matches[1];
93
116
  var name = matches[2] || documentName;
94
117
  var rest = matches[3]; // Allow `fragment on Type {...}`.
@@ -100,22 +123,20 @@ function () {
100
123
 
101
124
  var definitionName = capitalize(name);
102
125
  return type + ' ' + definitionName + ' ' + rest;
103
- };
126
+ }
104
127
  /**
105
128
  * Parses the GraphQL document string into a RelayQLDocument.
106
129
  */
107
-
130
+ ;
108
131
 
109
132
  _proto.processDocumentText = function processDocumentText(documentText, _ref2) {
110
133
  var documentName = _ref2.documentName,
111
134
  enableValidation = _ref2.enableValidation;
112
-
113
- var document = require("graphql").parse(new (require("graphql").Source)(documentText, documentName));
114
-
135
+ var document = parse(new Source(documentText, documentName));
115
136
  var validationErrors = enableValidation ? this.validateDocument(document, documentName) : null;
116
137
 
117
138
  if (validationErrors) {
118
- var error = new Error(require("util").format('You supplied a GraphQL document named `%s` with validation errors.', documentName));
139
+ var error = new Error(util.format('You supplied a GraphQL document named `%s` with validation errors.', documentName));
119
140
  error.validationErrors = validationErrors;
120
141
  error.sourceText = documentText;
121
142
  throw error;
@@ -130,36 +151,36 @@ function () {
130
151
  };
131
152
 
132
153
  if (definition.kind === 'FragmentDefinition') {
133
- return new (require("./RelayQLAST").RelayQLFragment)(context, definition);
154
+ return new RelayQLFragment(context, definition);
134
155
  } else if (definition.kind === 'OperationDefinition') {
135
156
  if (definition.operation === 'mutation') {
136
- return new (require("./RelayQLAST").RelayQLMutation)(context, definition);
157
+ return new RelayQLMutation(context, definition);
137
158
  } else if (definition.operation === 'query') {
138
- return new (require("./RelayQLAST").RelayQLQuery)(context, definition);
159
+ return new RelayQLQuery(context, definition);
139
160
  } else if (definition.operation === 'subscription') {
140
- return new (require("./RelayQLAST").RelayQLSubscription)(context, definition);
161
+ return new RelayQLSubscription(context, definition);
141
162
  } else {
142
- !false ? process.env.NODE_ENV !== "production" ? require("./invariant")(false, 'Unsupported operation: %s', definition.operation) : require("./invariant")(false) : void 0;
163
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'Unsupported operation: %s', definition.operation) : invariant(false) : void 0;
143
164
  }
144
165
  } else {
145
- !false ? process.env.NODE_ENV !== "production" ? require("./invariant")(false, 'Unsupported definition kind: %s', definition.kind) : require("./invariant")(false) : void 0;
166
+ !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'Unsupported definition kind: %s', definition.kind) : invariant(false) : void 0;
146
167
  }
147
168
  };
148
169
 
149
170
  _proto.validateDocument = function validateDocument(document, documentName) {
150
- !(document.definitions.length === 1) ? process.env.NODE_ENV !== "production" ? require("./invariant")(false, 'You supplied a GraphQL document named `%s` with %d definitions, but ' + 'it must have exactly one definition.', documentName, document.definitions.length) : require("./invariant")(false) : void 0;
171
+ !(document.definitions.length === 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'You supplied a GraphQL document named `%s` with %d definitions, but ' + 'it must have exactly one definition.', documentName, document.definitions.length) : invariant(false) : void 0;
151
172
  var validator = this.options.validator;
152
173
  var validationErrors;
153
174
 
154
175
  if (validator) {
155
176
  validationErrors = validator().validate(this.schema, document);
156
177
  } else {
157
- var rules = [require("graphql").FieldsOnCorrectTypeRule, require("graphql").FragmentsOnCompositeTypesRule, require("graphql").KnownArgumentNamesRule, require("graphql").KnownTypeNamesRule, require("graphql").PossibleFragmentSpreadsRule, require("graphql").ValuesOfCorrectTypeRule, require("graphql").VariablesInAllowedPositionRule];
158
- validationErrors = require("graphql").validate(this.schema, document, rules);
178
+ var rules = [FieldsOnCorrectTypeRule, FragmentsOnCompositeTypesRule, KnownArgumentNamesRule, KnownTypeNamesRule, PossibleFragmentSpreadsRule, ValuesOfCorrectTypeRule, VariablesInAllowedPositionRule];
179
+ validationErrors = validate(this.schema, document, rules);
159
180
  }
160
181
 
161
182
  if (validationErrors && validationErrors.length > 0) {
162
- return validationErrors.map(require("graphql").formatError);
183
+ return validationErrors.map(formatError);
163
184
  }
164
185
 
165
186
  return null;
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
- * strict
7
+ *
8
8
  * @fullSyntaxTransform
9
9
  * @format
10
10
  */
@@ -9,69 +9,28 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
+ var createClassicNode = require("./createClassicNode");
13
+
14
+ var createCompatNode = require("./createCompatNode");
15
+
16
+ var createModernNode = require("./createModernNode");
17
+
12
18
  /**
13
19
  * Given a graphql`` tagged template literal, replace it with the appropriate
14
20
  * runtime artifact.
15
21
  */
16
22
  function compileGraphQLTag(t, path, state, ast) {
17
- var mainDefinition = ast.definitions[0];
18
-
19
- if (mainDefinition.kind === 'FragmentDefinition') {
20
- var objPropName = getAssignedObjectPropertyName(t, path);
21
-
22
- if (objPropName) {
23
- if (ast.definitions.length !== 1) {
24
- throw new Error('BabelPluginRelay: Expected exactly one fragment in the ' + "graphql tag referenced by the property ".concat(objPropName, "."));
25
- }
26
-
27
- return replaceMemoized(t, path, createAST(t, state, path, mainDefinition));
28
- }
29
-
30
- var nodeMap = {};
31
- var _iteratorNormalCompletion = true;
32
- var _didIteratorError = false;
33
- var _iteratorError = undefined;
34
-
35
- try {
36
- for (var _iterator = ast.definitions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
37
- var definition = _step.value;
38
-
39
- if (definition.kind !== 'FragmentDefinition') {
40
- throw new Error('BabelPluginRelay: Expected only fragments within this ' + 'graphql tag.');
41
- }
42
-
43
- var _getFragmentNameParts = require("./getFragmentNameParts")(definition.name.value),
44
- propName = _getFragmentNameParts[1];
45
-
46
- nodeMap[propName] = createAST(t, state, path, definition);
47
- }
48
- } catch (err) {
49
- _didIteratorError = true;
50
- _iteratorError = err;
51
- } finally {
52
- try {
53
- if (!_iteratorNormalCompletion && _iterator["return"] != null) {
54
- _iterator["return"]();
55
- }
56
- } finally {
57
- if (_didIteratorError) {
58
- throw _iteratorError;
59
- }
60
- }
61
- }
62
-
63
- return replaceMemoized(t, path, createObject(t, nodeMap));
23
+ if (ast.definitions.length !== 1) {
24
+ throw new Error('BabelPluginRelay: Expected exactly one definition per graphql tag.');
64
25
  }
65
26
 
66
- if (mainDefinition.kind === 'OperationDefinition') {
67
- if (ast.definitions.length !== 1) {
68
- throw new Error('BabelPluginRelay: Expected exactly one operation ' + '(query, mutation, or subscription) per graphql tag.');
69
- }
27
+ var definition = ast.definitions[0];
70
28
 
71
- return replaceMemoized(t, path, createAST(t, state, path, mainDefinition));
29
+ if (definition.kind !== 'FragmentDefinition' && definition.kind !== 'OperationDefinition') {
30
+ throw new Error('BabelPluginRelay: Expected a fragment, mutation, query, or ' + 'subscription, got `' + definition.kind + '`.');
72
31
  }
73
32
 
74
- throw new Error('BabelPluginRelay: Expected a fragment, mutation, query, or ' + 'subscription, got `' + mainDefinition.kind + '`.');
33
+ return replaceMemoized(t, path, createAST(t, state, path, definition));
75
34
  }
76
35
 
77
36
  function createAST(t, state, path, graphqlDefinition) {
@@ -82,8 +41,7 @@ function createAST(t, state, path, graphqlDefinition) {
82
41
  var buildCommand = state.opts && state.opts.buildCommand || 'relay-compiler'; // Fallback is 'true'
83
42
 
84
43
  var isDevelopment = (process.env.BABEL_ENV || process.env.NODE_ENV) !== 'production';
85
-
86
- var modernNode = require("./createModernNode")(t, graphqlDefinition, state, {
44
+ var modernNode = createModernNode(t, graphqlDefinition, state, {
87
45
  artifactDirectory: artifactDirectory,
88
46
  buildCommand: buildCommand,
89
47
  isDevelopment: isDevelopment,
@@ -92,7 +50,7 @@ function createAST(t, state, path, graphqlDefinition) {
92
50
  });
93
51
 
94
52
  if (isCompatMode) {
95
- return require("./createCompatNode")(t, modernNode, require("./createClassicNode")(t, path, graphqlDefinition, state));
53
+ return createCompatNode(t, modernNode, createClassicNode(t, path, graphqlDefinition, state));
96
54
  }
97
55
 
98
56
  return modernNode;
@@ -119,16 +77,4 @@ function createObject(t, obj) {
119
77
  }));
120
78
  }
121
79
 
122
- function getAssignedObjectPropertyName(t, path) {
123
- var property = path;
124
-
125
- while (property) {
126
- if (t.isObjectProperty(property) && property.node.key.name) {
127
- return property.node.key.name;
128
- }
129
-
130
- property = property.parentPath;
131
- }
132
- }
133
-
134
80
  module.exports = compileGraphQLTag;
@@ -9,6 +9,10 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
+ var createTransformError = require("./createTransformError");
13
+
14
+ var getClassicTransformer = require("./getClassicTransformer");
15
+
12
16
  /**
13
17
  * Given all the metadata about a found RelayQL tag, compile it and return
14
18
  * the resulting Babel AST.
@@ -16,9 +20,7 @@
16
20
  function compileRelayQLTag(t, path, schemaProvider, quasi, documentName, propName, tagName, enableValidation, state) {
17
21
  try {
18
22
  var fileOpts = state.file && state.file.opts || {};
19
-
20
- var transformer = require("./getClassicTransformer")(schemaProvider, state.opts || {}, fileOpts);
21
-
23
+ var transformer = getClassicTransformer(schemaProvider, state.opts || {}, fileOpts);
22
24
  return transformer.transform(t, quasi, {
23
25
  documentName: documentName,
24
26
  propName: propName,
@@ -26,7 +28,7 @@ function compileRelayQLTag(t, path, schemaProvider, quasi, documentName, propNam
26
28
  enableValidation: enableValidation
27
29
  });
28
30
  } catch (error) {
29
- throw path.buildCodeFrameError(require("./createTransformError")(error), Error);
31
+ throw path.buildCodeFrameError(createTransformError(error), Error);
30
32
  }
31
33
  }
32
34