relay-compiler 1.3.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. package/LICENSE +16 -26
  2. package/bin/relay-compiler +7348 -5939
  3. package/index.js +3 -6
  4. package/lib/{FileParser.js → ASTCache.js} +17 -14
  5. package/lib/ASTConvert.js +84 -70
  6. package/lib/CodegenDirectory.js +122 -28
  7. package/lib/{RelayCodegenRunner.js → CodegenRunner.js} +110 -186
  8. package/lib/CodegenTypes.js +12 -0
  9. package/lib/{RelayCodegenWatcher.js → CodegenWatcher.js} +53 -43
  10. package/lib/DefaultHandleKey.js +2 -4
  11. package/lib/DotGraphQLParser.js +27 -0
  12. package/lib/FilterDirectivesTransform.js +11 -11
  13. package/lib/FindGraphQLTags.js +33 -52
  14. package/lib/FlattenTransform.js +197 -0
  15. package/lib/GraphQLCompilerContext.js +158 -0
  16. package/lib/GraphQLCompilerProfiler.js +271 -0
  17. package/lib/GraphQLCompilerPublic.js +27 -22
  18. package/lib/GraphQLCompilerUserError.js +26 -0
  19. package/lib/GraphQLConsoleReporter.js +58 -0
  20. package/lib/GraphQLIR.js +12 -0
  21. package/lib/{RelayPrinter.js → GraphQLIRPrinter.js} +42 -38
  22. package/lib/{RelayIRTransformer.js → GraphQLIRTransformer.js} +47 -38
  23. package/lib/GraphQLIRTransforms.js +6 -15
  24. package/lib/{RelayIRVisitor.js → GraphQLIRVisitor.js} +7 -6
  25. package/lib/GraphQLMultiReporter.js +50 -0
  26. package/lib/GraphQLParser.js +743 -0
  27. package/lib/GraphQLReporter.js +12 -0
  28. package/lib/GraphQLSchemaUtils.js +10 -36
  29. package/lib/GraphQLValidator.js +13 -15
  30. package/lib/{RelayWatchmanClient.js → GraphQLWatchmanClient.js} +15 -17
  31. package/lib/InlineFragmentsTransform.js +48 -0
  32. package/lib/PatchedBabelGenerator.js +58 -0
  33. package/lib/RelayApplyFragmentArgumentTransform.js +37 -18
  34. package/lib/RelayCodeGenerator.js +130 -60
  35. package/lib/RelayCompilerBin.js +80 -35
  36. package/lib/RelayCompilerCache.js +18 -11
  37. package/lib/RelayCompilerPublic.js +24 -10
  38. package/lib/RelayCompilerScope.js +2 -4
  39. package/lib/RelayConcreteNode.js +31 -14
  40. package/lib/RelayConnectionConstants.js +2 -4
  41. package/lib/RelayConnectionTransform.js +34 -38
  42. package/lib/RelayDefaultHandleKey.js +2 -4
  43. package/lib/RelayDeferrableFragmentTransform.js +464 -0
  44. package/lib/RelayError.js +2 -6
  45. package/lib/RelayFieldHandleTransform.js +15 -11
  46. package/lib/RelayFileWriter.js +119 -98
  47. package/lib/RelayFlowBabelFactories.js +113 -0
  48. package/lib/RelayFlowGenerator.js +180 -200
  49. package/lib/RelayFlowTypeTransformers.js +109 -0
  50. package/lib/RelayGenerateIDFieldTransform.js +131 -0
  51. package/lib/RelayGenerateTypeNameTransform.js +75 -0
  52. package/lib/RelayGraphQLEnumsGenerator.js +65 -0
  53. package/lib/RelayIRTransforms.js +19 -23
  54. package/lib/RelayInternalTypes.js +2 -5
  55. package/lib/RelayInternals.js +2 -5
  56. package/lib/RelayJSModuleParser.js +64 -0
  57. package/lib/RelayMaskTransform.js +129 -0
  58. package/lib/RelayMetricsRecorder.js +9 -9
  59. package/lib/RelayMockRenderer.js +3 -8
  60. package/lib/RelayNetworkDebug.js +4 -7
  61. package/lib/RelayParser.js +28 -645
  62. package/lib/RelayProfiler.js +7 -7
  63. package/lib/RelayQueryCaching.js +2 -5
  64. package/lib/RelayRelayDirectiveTransform.js +47 -33
  65. package/lib/RelayRuntimeTypes.js +22 -0
  66. package/lib/RelayShallowMock.js +4 -7
  67. package/lib/RelaySkipHandleFieldTransform.js +13 -11
  68. package/lib/RelayTaskQueue.js +2 -5
  69. package/lib/RelayTransformUtils.js +20 -0
  70. package/lib/RelayTypes.js +2 -5
  71. package/lib/RelayValidator.js +9 -8
  72. package/lib/RelayViewerHandleTransform.js +22 -18
  73. package/lib/SkipClientFieldTransform.js +36 -53
  74. package/lib/SkipRedundantNodesTransform.js +22 -29
  75. package/lib/SkipUnreachableNodeTransform.js +57 -36
  76. package/lib/SourceControl.js +61 -0
  77. package/lib/StripUnusedVariablesTransform.js +86 -41
  78. package/lib/areEqualOSS.js +2 -4
  79. package/lib/compileRelayArtifacts.js +72 -0
  80. package/lib/dedent.js +2 -5
  81. package/lib/dedupeJSONStringify.js +132 -0
  82. package/lib/deepFreeze.js +3 -5
  83. package/lib/deepMergeAssignments.js +68 -0
  84. package/lib/filterContextForNode.js +5 -7
  85. package/lib/formatGeneratedModule.js +5 -9
  86. package/lib/{getIdentifierForRelayArgumentValue.js → getIdentifierForArgumentValue.js} +8 -10
  87. package/lib/getIdentifierForSelection.js +37 -0
  88. package/lib/getLiteralArgumentValues.js +26 -0
  89. package/lib/getModuleName.js +2 -4
  90. package/lib/getRelayHandleKey.js +2 -4
  91. package/lib/isCompatibleRelayFragmentType.js +2 -5
  92. package/lib/isEquivalentType.js +55 -0
  93. package/lib/isPromise.js +2 -5
  94. package/lib/isScalarAndEqual.js +3 -5
  95. package/lib/murmurHash.js +2 -4
  96. package/lib/nullthrowsOSS.js +7 -5
  97. package/lib/recycleNodesInto.js +2 -4
  98. package/lib/relayUnstableBatchedUpdates.js +2 -5
  99. package/lib/relayUnstableBatchedUpdates.native.js +2 -5
  100. package/lib/requestsForOperation.js +75 -0
  101. package/lib/simpleClone.js +2 -4
  102. package/lib/stableCopy.js +35 -0
  103. package/lib/testEditDistance.js +2 -5
  104. package/lib/throwFailedPromise.js +2 -5
  105. package/lib/writeRelayGeneratedFile.js +84 -50
  106. package/package.json +16 -15
  107. package/relay-compiler.js +7208 -5872
  108. package/relay-compiler.min.js +7200 -5867
  109. package/ARCHITECTURE.md +0 -94
  110. package/PATENTS +0 -33
  111. package/lib/AutoAliasTransform.js +0 -80
  112. package/lib/GraphQLFileParser.js +0 -27
  113. package/lib/GraphQLTextParser.js +0 -46
  114. package/lib/RelayCodegenTypes.js +0 -14
  115. package/lib/RelayCompiledTypes.js +0 -13
  116. package/lib/RelayCompiler.js +0 -144
  117. package/lib/RelayCompilerContext.js +0 -133
  118. package/lib/RelayCompilerUserError.js +0 -30
  119. package/lib/RelayConsoleReporter.js +0 -40
  120. package/lib/RelayFileIRParser.js +0 -66
  121. package/lib/RelayFlattenTransform.js +0 -278
  122. package/lib/RelayFlowParser.js +0 -188
  123. package/lib/RelayGenerateRequisiteFieldsTransform.js +0 -189
  124. package/lib/RelayIR.js +0 -14
  125. package/lib/RelayMultiReporter.js +0 -40
  126. package/lib/RelayReporter.js +0 -14
  127. package/lib/RelayTestSchema.js +0 -21
  128. package/lib/formatStorageKey.js +0 -37
  129. package/lib/getIdentifierForRelaySelection.js +0 -54
  130. package/lib/getRelayLiteralArgumentValues.js +0 -28
  131. package/lib/parseGraphQLText.js +0 -33
  132. package/lib/prettyStringify.js +0 -35
  133. package/lib/printFlowTypes.js +0 -282
  134. package/lib/stableJSONStringify.js +0 -45
  135. package/lib/stableJSONStringifyOSS.js +0 -44
  136. package/lib/transformInputObjectToIR.js +0 -85
  137. package/lib/writeLegacyFlowFile.js +0 -24
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2013-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @providesModule GraphQLReporter
8
+ *
9
+ * @format
10
+ */
11
+
12
+ 'use strict';
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule GraphQLSchemaUtils
10
8
  *
@@ -72,6 +70,10 @@ function isAbstractType(type) {
72
70
  return rawType instanceof GraphQLInterfaceType || rawType instanceof GraphQLUnionType;
73
71
  }
74
72
 
73
+ function isUnionType(type) {
74
+ return type instanceof GraphQLUnionType;
75
+ }
76
+
75
77
  /**
76
78
  * Get the unmodified type, with list/null wrappers removed.
77
79
  */
@@ -130,7 +132,7 @@ function getInterfaces(type) {
130
132
  *
131
133
  * Determine if an AST node contains a fragment/operation definition.
132
134
  */
133
- function isOperationDefinitionAST(ast) {
135
+ function isExecutableDefinitionAST(ast) {
134
136
  return ast.kind === 'FragmentDefinition' || ast.kind === 'OperationDefinition';
135
137
  }
136
138
 
@@ -140,7 +142,7 @@ function isOperationDefinitionAST(ast) {
140
142
  * Determine if an AST node contains a schema definition.
141
143
  */
142
144
  function isSchemaDefinitionAST(ast) {
143
- return ast.kind === 'DirectiveDefinition' || ast.kind === 'EnumTypeDefinition' || ast.kind === 'InputObjectTypeDefinition' || ast.kind === 'InterfaceTypeDefinition' || ast.kind === 'ObjectTypeDefinition' || ast.kind === 'ScalarTypeDefinition' || ast.kind === 'TypeExtensionDefinition' || ast.kind === 'UnionTypeDefinition';
145
+ return ast.kind === 'SchemaDefinition' || ast.kind === 'ScalarTypeDefinition' || ast.kind === 'ObjectTypeDefinition' || ast.kind === 'InterfaceTypeDefinition' || ast.kind === 'UnionTypeDefinition' || ast.kind === 'EnumTypeDefinition' || ast.kind === 'InputObjectTypeDefinition' || ast.kind === 'DirectiveDefinition' || ast.kind === 'ScalarTypeExtension' || ast.kind === 'ObjectTypeExtension' || ast.kind === 'InterfaceTypeExtension' || ast.kind === 'UnionTypeExtension' || ast.kind === 'EnumTypeExtension' || ast.kind === 'InputObjectTypeExtension';
144
146
  }
145
147
 
146
148
  function assertTypeWithFields(type) {
@@ -159,37 +161,8 @@ function getTypeFromAST(schema, ast) {
159
161
  return type;
160
162
  }
161
163
 
162
- /**
163
- * Given a defitinition AST node, gives us a unique name for that node.
164
- * Note: this can be tricky for type extensions: while types always have one
165
- * name, type extensions are defined by everything inside them.
166
- *
167
- * TODO @mmahoney: t16495627 write tests or remove uses of this
168
- */
169
- function definitionName(definition) {
170
- switch (definition.kind) {
171
- case 'DirectiveDefinition':
172
- case 'EnumTypeDefinition':
173
- case 'FragmentDefinition':
174
- case 'InputObjectTypeDefinition':
175
- case 'InterfaceTypeDefinition':
176
- case 'ObjectTypeDefinition':
177
- case 'ScalarTypeDefinition':
178
- case 'UnionTypeDefinition':
179
- return definition.name.value;
180
- case 'OperationDefinition':
181
- return definition.name ? definition.name.value : '';
182
- case 'TypeExtensionDefinition':
183
- return definition.toString();
184
- case 'SchemaDefinition':
185
- return 'schema';
186
- }
187
- throw new Error('Unkown definition kind: ' + definition.kind);
188
- }
189
-
190
164
  module.exports = {
191
165
  assertTypeWithFields: assertTypeWithFields,
192
- definitionName: definitionName,
193
166
  canHaveSelections: canHaveSelections,
194
167
  getNullableType: getNullableType,
195
168
  getRawType: getRawType,
@@ -198,7 +171,8 @@ module.exports = {
198
171
  hasID: hasID,
199
172
  implementsInterface: implementsInterface,
200
173
  isAbstractType: isAbstractType,
201
- isOperationDefinitionAST: isOperationDefinitionAST,
174
+ isUnionType: isUnionType,
175
+ isExecutableDefinitionAST: isExecutableDefinitionAST,
202
176
  isSchemaDefinitionAST: isSchemaDefinitionAST,
203
177
  mayImplement: mayImplement
204
178
  };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  *
10
8
  * @providesModule GraphQLValidator
@@ -14,14 +12,11 @@
14
12
  'use strict';
15
13
 
16
14
  var _require = require('graphql'),
17
- ArgumentsOfCorrectTypeRule = _require.ArgumentsOfCorrectTypeRule,
18
- DefaultValuesOfCorrectTypeRule = _require.DefaultValuesOfCorrectTypeRule,
19
15
  formatError = _require.formatError,
20
16
  FragmentsOnCompositeTypesRule = _require.FragmentsOnCompositeTypesRule,
21
17
  KnownArgumentNamesRule = _require.KnownArgumentNamesRule,
22
18
  KnownTypeNamesRule = _require.KnownTypeNamesRule,
23
19
  LoneAnonymousOperationRule = _require.LoneAnonymousOperationRule,
24
- NoFragmentCyclesRule = _require.NoFragmentCyclesRule,
25
20
  NoUnusedVariablesRule = _require.NoUnusedVariablesRule,
26
21
  PossibleFragmentSpreadsRule = _require.PossibleFragmentSpreadsRule,
27
22
  ProvidedNonNullArgumentsRule = _require.ProvidedNonNullArgumentsRule,
@@ -32,7 +27,9 @@ var _require = require('graphql'),
32
27
  UniqueOperationNamesRule = _require.UniqueOperationNamesRule,
33
28
  UniqueVariableNamesRule = _require.UniqueVariableNamesRule,
34
29
  validate = _require.validate,
30
+ ValuesOfCorrectTypeRule = _require.ValuesOfCorrectTypeRule,
35
31
  VariablesAreInputTypesRule = _require.VariablesAreInputTypesRule,
32
+ VariablesDefaultValueAllowedRule = _require.VariablesDefaultValueAllowedRule,
36
33
  VariablesInAllowedPositionRule = _require.VariablesInAllowedPositionRule;
37
34
 
38
35
  function validateOrThrow(document, schema, rules) {
@@ -53,11 +50,12 @@ module.exports = {
53
50
  GLOBAL_RULES: [KnownArgumentNamesRule,
54
51
  // TODO #19327202 Relay Classic generates some fragments in runtime, so Relay
55
52
  // Modern queries might reference fragments unknown in build time
56
- //KnownFragmentNamesRule,
57
- NoFragmentCyclesRule,
58
- // TODO #19327144 Because of graphql.experimental feature
59
- // @argumentDefinitions, this validation incorrectly marks some fragment
60
- // variables as undefined.
53
+ // KnownFragmentNamesRule,
54
+ // TODO: #25618795 Because of @argumentDefinitions, this validation
55
+ // incorrectly flags a subset of fragments using @include/@skip as recursive.
56
+ // NoFragmentCyclesRule,
57
+ // TODO #19327144 Because of @argumentDefinitions, this validation
58
+ // incorrectly marks some fragment variables as undefined.
61
59
  // NoUndefinedVariablesRule,
62
60
  // TODO #19327202 Queries generated dynamically with Relay Classic might use
63
61
  // unused fragments
@@ -67,12 +65,12 @@ module.exports = {
67
65
  // generating aliases
68
66
  //OverlappingFieldsCanBeMergedRule,
69
67
  ProvidedNonNullArgumentsRule, UniqueArgumentNamesRule, UniqueFragmentNamesRule, UniqueInputFieldNamesRule, UniqueOperationNamesRule, UniqueVariableNamesRule],
70
- LOCAL_RULES: [ArgumentsOfCorrectTypeRule, DefaultValuesOfCorrectTypeRule,
68
+ LOCAL_RULES: [
71
69
  // TODO #13818691: make this aware of @fixme_fat_interface
72
70
  // FieldsOnCorrectTypeRule,
73
71
  FragmentsOnCompositeTypesRule, KnownTypeNamesRule,
74
72
  // TODO #17737009: Enable this after cleaning up existing issues
75
73
  // KnownDirectivesRule,
76
- LoneAnonymousOperationRule, PossibleFragmentSpreadsRule, ScalarLeafsRule, VariablesAreInputTypesRule, VariablesInAllowedPositionRule],
77
- validate: validateOrThrow
74
+ LoneAnonymousOperationRule, PossibleFragmentSpreadsRule, ScalarLeafsRule, VariablesDefaultValueAllowedRule, ValuesOfCorrectTypeRule, VariablesAreInputTypesRule, VariablesInAllowedPositionRule],
75
+ validate: require('./GraphQLCompilerProfiler').instrument(validateOrThrow, 'GraphQLValidator.validate')
78
76
  };
@@ -1,12 +1,10 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
- * @providesModule RelayWatchmanClient
7
+ * @providesModule GraphQLWatchmanClient
10
8
  *
11
9
  * @format
12
10
  */
@@ -20,10 +18,10 @@ var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/cla
20
18
 
21
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
22
20
 
23
- var RelayWatchmanClient = function () {
24
- RelayWatchmanClient.isAvailable = function isAvailable() {
21
+ var GraphQLWatchmanClient = function () {
22
+ GraphQLWatchmanClient.isAvailable = function isAvailable() {
25
23
  return new Promise(function (resolve) {
26
- var client = new RelayWatchmanClient();
24
+ var client = new GraphQLWatchmanClient();
27
25
  client.on('error', function () {
28
26
  resolve(false);
29
27
  client.end();
@@ -38,13 +36,13 @@ var RelayWatchmanClient = function () {
38
36
  });
39
37
  };
40
38
 
41
- function RelayWatchmanClient() {
42
- (0, _classCallCheck3['default'])(this, RelayWatchmanClient);
39
+ function GraphQLWatchmanClient() {
40
+ (0, _classCallCheck3['default'])(this, GraphQLWatchmanClient);
43
41
 
44
42
  this._client = new (require('fb-watchman').Client)();
45
43
  }
46
44
 
47
- RelayWatchmanClient.prototype.command = function command() {
45
+ GraphQLWatchmanClient.prototype.command = function command() {
48
46
  var _this = this;
49
47
 
50
48
  for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
@@ -62,7 +60,7 @@ var RelayWatchmanClient = function () {
62
60
  });
63
61
  };
64
62
 
65
- RelayWatchmanClient.prototype.hasCapability = (() => {
63
+ GraphQLWatchmanClient.prototype.hasCapability = (() => {
66
64
  var _ref = (0, _asyncToGenerator3.default)(function* (capability) {
67
65
  var resp = yield this.command('list-capabilities');
68
66
  return resp.capabilities.includes(capability);
@@ -75,7 +73,7 @@ var RelayWatchmanClient = function () {
75
73
  return hasCapability;
76
74
  })();
77
75
 
78
- RelayWatchmanClient.prototype.watchProject = (() => {
76
+ GraphQLWatchmanClient.prototype.watchProject = (() => {
79
77
  var _ref2 = (0, _asyncToGenerator3.default)(function* (baseDir) {
80
78
  var resp = yield this.command('watch-project', baseDir);
81
79
  if ('warning' in resp) {
@@ -94,15 +92,15 @@ var RelayWatchmanClient = function () {
94
92
  return watchProject;
95
93
  })();
96
94
 
97
- RelayWatchmanClient.prototype.on = function on(event, callback) {
95
+ GraphQLWatchmanClient.prototype.on = function on(event, callback) {
98
96
  this._client.on(event, callback);
99
97
  };
100
98
 
101
- RelayWatchmanClient.prototype.end = function end() {
99
+ GraphQLWatchmanClient.prototype.end = function end() {
102
100
  this._client.end();
103
101
  };
104
102
 
105
- return RelayWatchmanClient;
103
+ return GraphQLWatchmanClient;
106
104
  }();
107
105
 
108
- module.exports = RelayWatchmanClient;
106
+ module.exports = GraphQLWatchmanClient;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Copyright (c) 2013-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @providesModule InlineFragmentsTransform
8
+ *
9
+ * @format
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ var STATE = {};
15
+
16
+ /**
17
+ * A transform that inlines all fragments and removes them.
18
+ */
19
+ function inlineFragmentsTransform(context) {
20
+ return require('./GraphQLIRTransformer').transform(context, {
21
+ Fragment: visitFragment,
22
+ FragmentSpread: visitFragmentSpread
23
+ }, function () {
24
+ return STATE;
25
+ });
26
+ }
27
+
28
+ function visitFragment(fragment, state) {
29
+ return null;
30
+ }
31
+
32
+ function visitFragmentSpread(fragmentSpread, state) {
33
+ require('fbjs/lib/invariant')(fragmentSpread.args.length === 0, 'InlineFragmentsTransform: Cannot flatten fragment spread `%s` with ' + 'arguments. Use the `ApplyFragmentArgumentTransform` before flattening', fragmentSpread.name);
34
+ var fragment = this.getContext().getFragment(fragmentSpread.name);
35
+ var result = {
36
+ kind: 'InlineFragment',
37
+ directives: fragmentSpread.directives,
38
+ metadata: fragmentSpread.metadata,
39
+ selections: fragment.selections,
40
+ typeCondition: fragment.type
41
+ };
42
+
43
+ return this.traverse(result, state);
44
+ }
45
+
46
+ module.exports = {
47
+ transform: inlineFragmentsTransform
48
+ };
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Copyright (c) 2013-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ var babelGenerator = require('babel-generator')['default'];
13
+
14
+
15
+ /**
16
+ * babel-generator has a bug where it doesn't correctly adds parens around
17
+ * some flow types. This mokey patches the code generator.
18
+ *
19
+ * TODO(T22289880): remove this module once the babel issue is fixed
20
+ * https://github.com/babel/babel/issues/6333
21
+ */
22
+ function generate(ast) {
23
+ var originalUnionTypeAnnotation = require('babel-generator/lib/printer').prototype.UnionTypeAnnotation;
24
+ var originalIntersectionTypeAnnotation = require('babel-generator/lib/printer').prototype.IntersectionTypeAnnotation;
25
+ require('babel-generator/lib/printer').prototype.UnionTypeAnnotation = function (node) {
26
+ var needsParens = node.types.length > 1;
27
+ if (needsParens) {
28
+ this.token('(');
29
+ }
30
+ originalUnionTypeAnnotation.call(this, node);
31
+ if (needsParens) {
32
+ this.token(')');
33
+ }
34
+ };
35
+ require('babel-generator/lib/printer').prototype.IntersectionTypeAnnotation = function (node) {
36
+ var needsParens = node.types.length > 1;
37
+ if (needsParens) {
38
+ this.token('(');
39
+ }
40
+ originalIntersectionTypeAnnotation.call(this, node);
41
+ if (needsParens) {
42
+ this.token(')');
43
+ }
44
+ };
45
+ try {
46
+ return babelGenerator(ast, {
47
+ flowCommaSeparator: true,
48
+ quotes: 'single'
49
+ }).code;
50
+ } finally {
51
+ require('babel-generator/lib/printer').prototype.UnionTypeAnnotation = originalUnionTypeAnnotation;
52
+ require('babel-generator/lib/printer').prototype.IntersectionTypeAnnotation = originalIntersectionTypeAnnotation;
53
+ }
54
+ }
55
+
56
+ module.exports = {
57
+ generate: generate
58
+ };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Copyright (c) 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  *
9
7
  * @providesModule RelayApplyFragmentArgumentTransform
10
8
  *
@@ -19,6 +17,10 @@ var _toConsumableArray3 = _interopRequireDefault(require('babel-runtime/helpers/
19
17
 
20
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
21
19
 
20
+ var _require = require('./GraphQLCompilerPublic'),
21
+ getIdentifierForArgumentValue = _require.getIdentifierForArgumentValue,
22
+ IRTransformer = _require.IRTransformer;
23
+
22
24
  var getFragmentScope = require('./RelayCompilerScope').getFragmentScope,
23
25
  getRootScope = require('./RelayCompilerScope').getRootScope;
24
26
 
@@ -46,21 +48,20 @@ var getFragmentScope = require('./RelayCompilerScope').getFragmentScope,
46
48
  */
47
49
 
48
50
 
49
- function transform(context) {
50
- var documents = context.documents();
51
+ function relayApplyFragmentArgumentTransform(context) {
51
52
  var fragments = new (require('fbjs/lib/Map'))();
52
- var nextContext = new (require('./RelayCompilerContext'))(context.schema);
53
- nextContext = documents.reduce(function (ctx, node) {
54
- if (node.kind === 'Root') {
53
+ var nextContext = IRTransformer.transform(context, {
54
+ Root: function Root(node) {
55
55
  var scope = getRootScope(node.argumentDefinitions);
56
- var transformedNode = transformNode(context, fragments, scope, node);
57
- return transformedNode ? ctx.add(transformedNode) : ctx;
58
- } else {
59
- // fragments are transformed when referenced; unreferenced fragments are
60
- // not added to the output.
61
- return ctx;
56
+ return transformNode(context, fragments, scope, node);
57
+ },
58
+ // Fragments are included below where referenced.
59
+ // Unreferenced fragments are not included.
60
+ Fragment: function Fragment() {
61
+ return null;
62
62
  }
63
- }, nextContext);
63
+ });
64
+
64
65
  return Array.from(fragments.values()).reduce(function (ctx, fragment) {
65
66
  return fragment ? ctx.add(fragment) : ctx;
66
67
  }, nextContext);
@@ -98,6 +99,20 @@ function transformFragmentSpread(context, fragments, scope, spread) {
98
99
  });
99
100
  }
100
101
 
102
+ function transformDeferrableFragmentSpread(context, fragments, scope, spread) {
103
+ var directives = transformDirectives(scope, spread.directives);
104
+ var fragment = context.getFragment(spread.name);
105
+ var appliedFragment = transformFragment(context, fragments, scope, fragment, spread.fragmentArgs);
106
+ if (!appliedFragment) {
107
+ return null;
108
+ }
109
+ return (0, _extends3['default'])({}, spread, {
110
+ fragmentArgs: [],
111
+ directives: directives,
112
+ name: appliedFragment.name
113
+ });
114
+ }
115
+
101
116
  function transformField(context, fragments, scope, field) {
102
117
  var args = transformArguments(scope, field.args);
103
118
  var directives = transformDirectives(scope, field.directives);
@@ -149,6 +164,8 @@ function transformSelections(context, fragments, scope, selections) {
149
164
  nextSelection = transformNode(context, fragments, scope, selection);
150
165
  } else if (selection.kind === 'FragmentSpread') {
151
166
  nextSelection = transformFragmentSpread(context, fragments, scope, selection);
167
+ } else if (selection.kind === 'DeferrableFragmentSpread') {
168
+ nextSelection = transformDeferrableFragmentSpread(context, fragments, scope, selection);
152
169
  } else if (selection.kind === 'Condition') {
153
170
  var conditionSelections = transformCondition(context, fragments, scope, selection);
154
171
  if (conditionSelections) {
@@ -251,10 +268,12 @@ function hashArguments(args, scope) {
251
268
  }
252
269
  return {
253
270
  name: arg.name,
254
- value: require('./getIdentifierForRelayArgumentValue')(value)
271
+ value: getIdentifierForArgumentValue(value)
255
272
  };
256
273
  }));
257
274
  return require('./murmurHash')(printedArgs);
258
275
  }
259
276
 
260
- module.exports = { transform: transform };
277
+ module.exports = {
278
+ transform: relayApplyFragmentArgumentTransform
279
+ };