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
@@ -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 RelayProfiler
10
8
  *
@@ -78,9 +76,11 @@ var RelayProfiler = {
78
76
  * `attachHandler` and `detachHandler` methods.
79
77
  */
80
78
  instrumentMethods: function instrumentMethods(object, names) {
81
- require('fbjs/lib/forEachObject')(names, function (name, key) {
82
- object[key] = RelayProfiler.instrument(name, object[key]);
83
- });
79
+ for (var _key in names) {
80
+ if (names.hasOwnProperty(_key)) {
81
+ object[_key] = RelayProfiler.instrument(names[_key], object[_key]);
82
+ }
83
+ }
84
84
  },
85
85
 
86
86
 
@@ -1,12 +1,9 @@
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 RelayQueryCaching
10
7
  *
11
8
  * @format
12
9
  */
@@ -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 RelayRelayDirectiveTransform
10
8
  *
@@ -17,48 +15,64 @@ var _extends3 = _interopRequireDefault(require('babel-runtime/helpers/extends'))
17
15
 
18
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
19
17
 
18
+ var _require = require('./GraphQLCompilerPublic'),
19
+ CompilerContext = _require.CompilerContext,
20
+ IRTransformer = _require.IRTransformer,
21
+ getLiteralArgumentValues = _require.getLiteralArgumentValues;
22
+
20
23
  var RELAY = 'relay';
21
- var PLURAL = 'plural';
22
- var SCHEMA_EXTENSION = 'directive @relay(\n # Marks a connection field as containing nodes without \'id\' fields.\n # This is used to silence the warning when diffing connections.\n isConnectionWithoutNodeID: Boolean,\n\n # Marks a fragment as intended for pattern matching (as opposed to fetching).\n # Used in Classic only.\n pattern: Boolean,\n\n # Marks a fragment as being backed by a GraphQLList.\n plural: Boolean,\n\n # Marks a fragment spread which should be unmasked if provided false\n mask: Boolean = true,\n\n # Selectively pass variables down into a fragment. Only used in Classic.\n variables: [String!],\n) on FRAGMENT_DEFINITION | FRAGMENT_SPREAD | INLINE_FRAGMENT | FIELD';
24
+ var SCHEMA_EXTENSION = 'directive @relay(\n # Marks this fragment spread as being deferrable such that it loads after\n # other portions of the view.\n deferrable: Boolean,\n\n # Marks a connection field as containing nodes without \'id\' fields.\n # This is used to silence the warning when diffing connections.\n isConnectionWithoutNodeID: Boolean,\n\n # Marks a fragment as intended for pattern matching (as opposed to fetching).\n # Used in Classic only.\n pattern: Boolean,\n\n # Marks a fragment as being backed by a GraphQLList.\n plural: Boolean,\n\n # Marks a fragment spread which should be unmasked if provided false\n mask: Boolean = true,\n\n # Selectively pass variables down into a fragment. Only used in Classic.\n variables: [String!],\n) on FRAGMENT_DEFINITION | FRAGMENT_SPREAD | INLINE_FRAGMENT | FIELD';
23
25
 
24
26
  /**
25
27
  * A transform that extracts `@relay(plural: Boolean)` directives and converts
26
28
  * them to metadata that can be accessed at runtime.
27
29
  */
28
- function transform(context) {
29
- return require('./RelayIRTransformer').transform(context, {
30
- Fragment: visitFragment
31
- }, function () {
32
- return {};
33
- } // empty state
34
- );
30
+ function relayRelayDirectiveTransform(context) {
31
+ return IRTransformer.transform(context, {
32
+ Fragment: visitRelayMetadata(fragmentMetadata),
33
+ FragmentSpread: visitRelayMetadata(fragmentSpreadMetadata)
34
+ });
35
35
  }
36
36
 
37
- function visitFragment(fragment) {
38
- var relayDirective = fragment.directives.find(function (_ref) {
39
- var name = _ref.name;
40
- return name === RELAY;
41
- });
42
- if (!relayDirective) {
43
- return fragment;
44
- }
37
+ function visitRelayMetadata(metadataFn) {
38
+ return function (node) {
39
+ var relayDirective = node.directives.find(function (_ref) {
40
+ var name = _ref.name;
41
+ return name === RELAY;
42
+ });
43
+ if (!relayDirective) {
44
+ return this.traverse(node);
45
+ }
46
+ var argValues = getLiteralArgumentValues(relayDirective.args);
47
+ var metadata = metadataFn(argValues);
48
+ return this.traverse((0, _extends3['default'])({}, node, {
49
+ directives: node.directives.filter(function (directive) {
50
+ return directive !== relayDirective;
51
+ }),
52
+ metadata: (0, _extends3['default'])({}, node.metadata || {}, metadata)
53
+ }));
54
+ };
55
+ }
45
56
 
46
- var _getRelayLiteralArgum = require('./getRelayLiteralArgumentValues')(relayDirective.args),
47
- plural = _getRelayLiteralArgum.plural;
57
+ function fragmentMetadata(_ref2) {
58
+ var plural = _ref2.plural;
48
59
 
49
- require('fbjs/lib/invariant')(plural === undefined || typeof plural === 'boolean', 'RelayRelayDirectiveTransform: Expected the %s argument to @%s to be ' + 'a boolean literal or not specified.', PLURAL, RELAY);
50
- return (0, _extends3['default'])({}, fragment, {
51
- directives: fragment.directives.filter(function (directive) {
52
- return directive !== relayDirective;
53
- }),
54
- metadata: (0, _extends3['default'])({}, fragment.metadata || {}, {
55
- plural: plural
56
- })
57
- });
60
+ require('fbjs/lib/invariant')(plural === undefined || typeof plural === 'boolean', 'RelayRelayDirectiveTransform: Expected the "plural" argument to @relay ' + 'to be a boolean literal if specified.');
61
+ return { plural: plural };
62
+ }
63
+
64
+ function fragmentSpreadMetadata(_ref3) {
65
+ var mask = _ref3.mask,
66
+ deferrable = _ref3.deferrable;
67
+
68
+ require('fbjs/lib/invariant')(mask === undefined || typeof mask === 'boolean', 'RelayRelayDirectiveTransform: Expected the "mask" argument to @relay ' + 'to be a boolean literal if specified.');
69
+ require('fbjs/lib/invariant')(deferrable === undefined || typeof deferrable === 'boolean', 'RelayRelayDirectiveTransform: Expected the "deferrable" argument to ' + '@relay to be a boolean literal if specified.');
70
+ require('fbjs/lib/invariant')(!(deferrable === true && mask === false), 'RelayRelayDirectiveTransform: Cannot unmask a deferrable fragment spread.');
71
+ return { mask: mask, deferrable: deferrable };
58
72
  }
59
73
 
60
74
  module.exports = {
61
75
  RELAY: RELAY,
62
76
  SCHEMA_EXTENSION: SCHEMA_EXTENSION,
63
- transform: transform
77
+ transform: relayRelayDirectiveTransform
64
78
  };
@@ -0,0 +1,22 @@
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 RelayRuntimeTypes
8
+ *
9
+ * @format
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ /**
15
+ * Basic types used throughout Relay.
16
+ */
17
+
18
+ /**
19
+ * Represents any resource that must be explicitly disposed of. The most common
20
+ * use-case is as a return value for subscriptions, where calling `dispose()`
21
+ * would cancel the subscription.
22
+ */
@@ -1,12 +1,9 @@
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 RelayShallowMock
10
7
  *
11
8
  * @format
12
9
  */
@@ -18,7 +15,7 @@
18
15
  * Adds `unwrap` to the container that returns the component to test.
19
16
  *
20
17
  * @example
21
- * jest.mock('Relay', () => require('RelayShallowMock'));
18
+ * jest.mock('Relay', () => require('./RelayShallowMock'));
22
19
  * const renderer = require('ReactTestRenderer');
23
20
  * const MyContainer = require('MyContainer');
24
21
  *
@@ -48,7 +45,7 @@ var _inherits3 = _interopRequireDefault(require('babel-runtime/helpers/inherits'
48
45
 
49
46
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
50
47
 
51
- var Relay = require.requireActual('./RelayClassic');
48
+ var Relay = require.requireActual('./RelayPublic');
52
49
 
53
50
  var RelayShallowMock = {
54
51
  createContainer: function createContainer(component, spec) {
@@ -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 RelaySkipHandleFieldTransform
10
8
  *
@@ -17,21 +15,23 @@ var _extends3 = _interopRequireDefault(require('babel-runtime/helpers/extends'))
17
15
 
18
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
19
17
 
18
+ var _require = require('./GraphQLCompilerPublic'),
19
+ CompilerContext = _require.CompilerContext,
20
+ IRTransformer = _require.IRTransformer;
21
+
20
22
  /**
21
23
  * A transform that removes field `handles`. Intended for use when e.g.
22
24
  * printing queries to send to a GraphQL server.
23
25
  */
24
- function transform(context, schema) {
25
- return require('./RelayIRTransformer').transform(context, {
26
+ function relaySkipHandleFieldTransform(context) {
27
+ return IRTransformer.transform(context, {
26
28
  LinkedField: visitField,
27
29
  ScalarField: visitField
28
- }, function () {
29
- return true;
30
30
  });
31
31
  }
32
32
 
33
- function visitField(field, state) {
34
- var transformedNode = this.traverse(field, state);
33
+ function visitField(field) {
34
+ var transformedNode = this.traverse(field);
35
35
  if (transformedNode.handles) {
36
36
  return (0, _extends3['default'])({}, transformedNode, {
37
37
  handles: null
@@ -40,4 +40,6 @@ function visitField(field, state) {
40
40
  return transformedNode;
41
41
  }
42
42
 
43
- module.exports = { transform: transform };
43
+ module.exports = {
44
+ transform: relaySkipHandleFieldTransform
45
+ };
@@ -1,12 +1,9 @@
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 RelayTaskQueue
10
7
  *
11
8
  * @format
12
9
  */
@@ -0,0 +1,20 @@
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
+ *
8
+ * @providesModule RelayTransformUtils
9
+ * @format
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ function hasUnaliasedSelection(field, fieldName) {
15
+ return field.selections.some(function (selection) {
16
+ return selection.kind === 'ScalarField' && selection.alias == null && selection.name === fieldName;
17
+ });
18
+ }
19
+
20
+ module.exports = { hasUnaliasedSelection: hasUnaliasedSelection };
package/lib/RelayTypes.js CHANGED
@@ -1,12 +1,9 @@
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 RelayTypes
10
7
  *
11
8
  * @format
12
9
  */
@@ -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 RelayValidator
@@ -17,10 +15,13 @@ var _toConsumableArray3 = _interopRequireDefault(require('babel-runtime/helpers/
17
15
 
18
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
19
17
 
20
- var _require = require('./GraphQLValidator'),
21
- GLOBAL_RULES = _require.GLOBAL_RULES,
22
- LOCAL_RULES = _require.LOCAL_RULES,
23
- validate = _require.validate;
18
+ var _require = require('./GraphQLCompilerPublic'),
19
+ Validator = _require.Validator;
20
+
21
+ var GLOBAL_RULES = Validator.GLOBAL_RULES,
22
+ LOCAL_RULES = Validator.LOCAL_RULES,
23
+ validate = Validator.validate;
24
+
24
25
 
25
26
  function DisallowIdAsAliasValidationRule(context) {
26
27
  return {
@@ -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 RelayViewerHandleTransform
@@ -13,20 +11,26 @@
13
11
 
14
12
  'use strict';
15
13
 
14
+ // TODO T21875029 ../../../relay-runtime/util/RelayDefaultHandleKey
15
+
16
16
  var _extends3 = _interopRequireDefault(require('babel-runtime/helpers/extends'));
17
17
 
18
18
  var _toConsumableArray3 = _interopRequireDefault(require('babel-runtime/helpers/toConsumableArray'));
19
19
 
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
21
21
 
22
- var _require = require('./GraphQLSchemaUtils'),
23
- getRawType = _require.getRawType;
22
+ var _require = require('./RelayDefaultHandleKey'),
23
+ DEFAULT_HANDLE_KEY = _require.DEFAULT_HANDLE_KEY;
24
+
25
+ var _require2 = require('graphql'),
26
+ GraphQLObjectType = _require2.GraphQLObjectType;
27
+
28
+ var _require3 = require('./GraphQLCompilerPublic'),
29
+ IRTransformer = _require3.IRTransformer,
30
+ SchemaUtils = _require3.SchemaUtils;
24
31
 
25
- var _require2 = require('./RelayDefaultHandleKey'),
26
- DEFAULT_HANDLE_KEY = _require2.DEFAULT_HANDLE_KEY;
32
+ var getRawType = SchemaUtils.getRawType;
27
33
 
28
- var _require3 = require('graphql'),
29
- GraphQLObjectType = _require3.GraphQLObjectType;
30
34
 
31
35
  var ID = 'id';
32
36
  var VIEWER_HANDLE = 'viewer';
@@ -35,20 +39,18 @@ var VIEWER_TYPE = 'Viewer';
35
39
  /**
36
40
  * A transform that adds a "viewer" handle to all fields whose type is `Viewer`.
37
41
  */
38
- function transform(context, schema) {
39
- var viewerType = schema.getType(VIEWER_TYPE);
42
+ function relayViewerHandleTransform(context) {
43
+ var viewerType = context.serverSchema.getType(VIEWER_TYPE);
40
44
  if (viewerType == null || !(viewerType instanceof GraphQLObjectType) || viewerType.getFields()[ID] != null) {
41
45
  return context;
42
46
  }
43
- return require('./RelayIRTransformer').transform(context, {
47
+ return IRTransformer.transform(context, {
44
48
  LinkedField: visitLinkedField
45
- }, function () {
46
- return {};
47
49
  });
48
50
  }
49
51
 
50
- function visitLinkedField(field, state) {
51
- var transformedNode = this.traverse(field, state);
52
+ function visitLinkedField(field) {
53
+ var transformedNode = this.traverse(field);
52
54
  if (getRawType(field.type).name !== VIEWER_TYPE) {
53
55
  return transformedNode;
54
56
  }
@@ -69,4 +71,6 @@ function visitLinkedField(field, state) {
69
71
  return handles !== transformedNode.handles ? (0, _extends3['default'])({}, transformedNode, { handles: handles }) : transformedNode;
70
72
  }
71
73
 
72
- module.exports = { transform: transform };
74
+ module.exports = {
75
+ transform: relayViewerHandleTransform
76
+ };
@@ -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 SkipClientFieldTransform
@@ -13,10 +11,6 @@
13
11
 
14
12
  'use strict';
15
13
 
16
- var _extends3 = _interopRequireDefault(require('babel-runtime/helpers/extends'));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
19
-
20
14
  var _require = require('./GraphQLSchemaUtils'),
21
15
  assertTypeWithFields = _require.assertTypeWithFields,
22
16
  canHaveSelections = _require.canHaveSelections,
@@ -29,7 +23,7 @@ var _require2 = require('graphql'),
29
23
 
30
24
  /**
31
25
  * A transform that removes any selections that are not valid relative to the
32
- * given schema. The primary use case is for fields added via client
26
+ * server schema. The primary use case is for fields added via client
33
27
  * `extend type ...` definitions and for inline fragments / fragment spreads
34
28
  * whose types are added with client `type ...` type extensions.
35
29
  *
@@ -78,46 +72,37 @@ var _require2 = require('graphql'),
78
72
  * type, and (2) is removed because the `ClientType` type does not exist in the
79
73
  * base schema.
80
74
  */
81
- function transform(context, schema) {
82
- return require('./RelayIRTransformer').transform(context, {
75
+ function skipClientFieldTransform(context) {
76
+ return require('./GraphQLIRTransformer').transform(context, {
83
77
  FragmentSpread: visitFragmentSpread,
84
78
  InlineFragment: visitInlineFragment,
85
79
  LinkedField: visitField,
86
80
  ScalarField: visitField
87
- }, buildState.bind(null, schema));
81
+ }, function (node) {
82
+ return buildState(context, node);
83
+ });
88
84
  }
89
85
 
90
86
  /**
91
87
  * @internal
92
88
  *
93
89
  * Build the initial state, returning null for fragments whose type is not
94
- * defined in the original schema.
90
+ * defined in the server schema.
95
91
  */
96
- function buildState(schema, node) {
97
- var parentType = void 0;
92
+ function buildState(context, node) {
93
+ var schema = context.serverSchema;
98
94
  if (node.kind === 'Fragment') {
99
- parentType = schema.getType(node.type.name);
100
- } else {
101
- switch (node.operation) {
102
- case 'query':
103
- parentType = schema.getQueryType();
104
- break;
105
- case 'mutation':
106
- parentType = schema.getMutationType();
107
- break;
108
- case 'subscription':
109
- parentType = schema.getSubscriptionType();
110
- break;
111
- }
95
+ return schema.getType(node.type.name);
112
96
  }
113
- if (parentType) {
114
- return {
115
- schema: schema,
116
- parentType: parentType
117
- };
118
- } else {
119
- return null;
97
+ switch (node.operation) {
98
+ case 'query':
99
+ return schema.getQueryType();
100
+ case 'mutation':
101
+ return schema.getMutationType();
102
+ case 'subscription':
103
+ return schema.getSubscriptionType();
120
104
  }
105
+ return null;
121
106
  }
122
107
 
123
108
  /**
@@ -125,21 +110,19 @@ function buildState(schema, node) {
125
110
  *
126
111
  * Skip fields that were added via `extend type ...`.
127
112
  */
128
- function visitField(field, state) {
113
+ function visitField(field, parentType) {
129
114
  if (
130
115
  // Field is defined in the original parent type definition:
131
- canHaveSelections(state.parentType) && assertTypeWithFields(state.parentType).getFields()[field.name] ||
116
+ canHaveSelections(parentType) && assertTypeWithFields(parentType).getFields()[field.name] ||
132
117
  // Allow metadata fields and fields defined on classic "fat" interfaces
133
118
  field.name === SchemaMetaFieldDef.name || field.name === TypeMetaFieldDef.name || field.name === TypeNameMetaFieldDef.name || field.directives.some(function (_ref) {
134
119
  var name = _ref.name;
135
120
  return name === 'fixme_fat_interface';
136
121
  })) {
137
122
  var rawType = getRawType(field.type);
138
- var type = state.schema.getType(rawType.name);
139
- require('fbjs/lib/invariant')(type, 'SkipClientFieldTransform: Expected type `%s` to be defined in ' + 'the original schema.', rawType.name);
140
- return this.traverse(field, (0, _extends3['default'])({}, state, {
141
- parentType: type
142
- }));
123
+ var type = this.getContext().serverSchema.getType(rawType.name);
124
+ require('fbjs/lib/invariant')(type, 'SkipClientFieldTransform: Expected type `%s` to be defined in ' + 'the server schema.', rawType.name);
125
+ return this.traverse(field, type);
143
126
  }
144
127
  return null;
145
128
  }
@@ -150,12 +133,11 @@ function visitField(field, state) {
150
133
  * Skip fragment spreads where the referenced fragment is not defined in the
151
134
  * original schema.
152
135
  */
153
- function visitFragmentSpread(spread, state) {
136
+ function visitFragmentSpread(spread, parentType) {
154
137
  var context = this.getContext();
155
- var fragment = context.get(spread.name);
156
- require('fbjs/lib/invariant')(fragment && fragment.kind === 'Fragment', 'SkipClientFieldTransform: Expected a fragment named `%s` to be defined.', spread.name);
157
- if (state.schema.getType(fragment.type.name)) {
158
- return this.traverse(spread, state);
138
+ var fragment = context.getFragment(spread.name);
139
+ if (context.serverSchema.getType(fragment.type.name)) {
140
+ return this.traverse(spread, parentType);
159
141
  }
160
142
  return null;
161
143
  }
@@ -165,14 +147,15 @@ function visitFragmentSpread(spread, state) {
165
147
  *
166
148
  * Skip inline fragments where the type is not in the schema.
167
149
  */
168
- function visitInlineFragment(fragment, state) {
169
- var type = state.schema.getType(fragment.typeCondition.name);
150
+ function visitInlineFragment(fragment, parentType) {
151
+ var schema = this.getContext().serverSchema;
152
+ var type = schema.getType(fragment.typeCondition.name);
170
153
  if (type) {
171
- return this.traverse(fragment, (0, _extends3['default'])({}, state, {
172
- parentType: type
173
- }));
154
+ return this.traverse(fragment, type);
174
155
  }
175
156
  return null;
176
157
  }
177
158
 
178
- module.exports = { transform: transform };
159
+ module.exports = {
160
+ transform: skipClientFieldTransform
161
+ };