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.
- package/LICENSE +16 -26
- package/bin/relay-compiler +7348 -5939
- package/index.js +3 -6
- package/lib/{FileParser.js → ASTCache.js} +17 -14
- package/lib/ASTConvert.js +84 -70
- package/lib/CodegenDirectory.js +122 -28
- package/lib/{RelayCodegenRunner.js → CodegenRunner.js} +110 -186
- package/lib/CodegenTypes.js +12 -0
- package/lib/{RelayCodegenWatcher.js → CodegenWatcher.js} +53 -43
- package/lib/DefaultHandleKey.js +2 -4
- package/lib/DotGraphQLParser.js +27 -0
- package/lib/FilterDirectivesTransform.js +11 -11
- package/lib/FindGraphQLTags.js +33 -52
- package/lib/FlattenTransform.js +197 -0
- package/lib/GraphQLCompilerContext.js +158 -0
- package/lib/GraphQLCompilerProfiler.js +271 -0
- package/lib/GraphQLCompilerPublic.js +27 -22
- package/lib/GraphQLCompilerUserError.js +26 -0
- package/lib/GraphQLConsoleReporter.js +58 -0
- package/lib/GraphQLIR.js +12 -0
- package/lib/{RelayPrinter.js → GraphQLIRPrinter.js} +42 -38
- package/lib/{RelayIRTransformer.js → GraphQLIRTransformer.js} +47 -38
- package/lib/GraphQLIRTransforms.js +6 -15
- package/lib/{RelayIRVisitor.js → GraphQLIRVisitor.js} +7 -6
- package/lib/GraphQLMultiReporter.js +50 -0
- package/lib/GraphQLParser.js +743 -0
- package/lib/GraphQLReporter.js +12 -0
- package/lib/GraphQLSchemaUtils.js +10 -36
- package/lib/GraphQLValidator.js +13 -15
- package/lib/{RelayWatchmanClient.js → GraphQLWatchmanClient.js} +15 -17
- package/lib/InlineFragmentsTransform.js +48 -0
- package/lib/PatchedBabelGenerator.js +58 -0
- package/lib/RelayApplyFragmentArgumentTransform.js +37 -18
- package/lib/RelayCodeGenerator.js +130 -60
- package/lib/RelayCompilerBin.js +80 -35
- package/lib/RelayCompilerCache.js +18 -11
- package/lib/RelayCompilerPublic.js +24 -10
- package/lib/RelayCompilerScope.js +2 -4
- package/lib/RelayConcreteNode.js +31 -14
- package/lib/RelayConnectionConstants.js +2 -4
- package/lib/RelayConnectionTransform.js +34 -38
- package/lib/RelayDefaultHandleKey.js +2 -4
- package/lib/RelayDeferrableFragmentTransform.js +464 -0
- package/lib/RelayError.js +2 -6
- package/lib/RelayFieldHandleTransform.js +15 -11
- package/lib/RelayFileWriter.js +119 -98
- package/lib/RelayFlowBabelFactories.js +113 -0
- package/lib/RelayFlowGenerator.js +180 -200
- package/lib/RelayFlowTypeTransformers.js +109 -0
- package/lib/RelayGenerateIDFieldTransform.js +131 -0
- package/lib/RelayGenerateTypeNameTransform.js +75 -0
- package/lib/RelayGraphQLEnumsGenerator.js +65 -0
- package/lib/RelayIRTransforms.js +19 -23
- package/lib/RelayInternalTypes.js +2 -5
- package/lib/RelayInternals.js +2 -5
- package/lib/RelayJSModuleParser.js +64 -0
- package/lib/RelayMaskTransform.js +129 -0
- package/lib/RelayMetricsRecorder.js +9 -9
- package/lib/RelayMockRenderer.js +3 -8
- package/lib/RelayNetworkDebug.js +4 -7
- package/lib/RelayParser.js +28 -645
- package/lib/RelayProfiler.js +7 -7
- package/lib/RelayQueryCaching.js +2 -5
- package/lib/RelayRelayDirectiveTransform.js +47 -33
- package/lib/RelayRuntimeTypes.js +22 -0
- package/lib/RelayShallowMock.js +4 -7
- package/lib/RelaySkipHandleFieldTransform.js +13 -11
- package/lib/RelayTaskQueue.js +2 -5
- package/lib/RelayTransformUtils.js +20 -0
- package/lib/RelayTypes.js +2 -5
- package/lib/RelayValidator.js +9 -8
- package/lib/RelayViewerHandleTransform.js +22 -18
- package/lib/SkipClientFieldTransform.js +36 -53
- package/lib/SkipRedundantNodesTransform.js +22 -29
- package/lib/SkipUnreachableNodeTransform.js +57 -36
- package/lib/SourceControl.js +61 -0
- package/lib/StripUnusedVariablesTransform.js +86 -41
- package/lib/areEqualOSS.js +2 -4
- package/lib/compileRelayArtifacts.js +72 -0
- package/lib/dedent.js +2 -5
- package/lib/dedupeJSONStringify.js +132 -0
- package/lib/deepFreeze.js +3 -5
- package/lib/deepMergeAssignments.js +68 -0
- package/lib/filterContextForNode.js +5 -7
- package/lib/formatGeneratedModule.js +5 -9
- package/lib/{getIdentifierForRelayArgumentValue.js → getIdentifierForArgumentValue.js} +8 -10
- package/lib/getIdentifierForSelection.js +37 -0
- package/lib/getLiteralArgumentValues.js +26 -0
- package/lib/getModuleName.js +2 -4
- package/lib/getRelayHandleKey.js +2 -4
- package/lib/isCompatibleRelayFragmentType.js +2 -5
- package/lib/isEquivalentType.js +55 -0
- package/lib/isPromise.js +2 -5
- package/lib/isScalarAndEqual.js +3 -5
- package/lib/murmurHash.js +2 -4
- package/lib/nullthrowsOSS.js +7 -5
- package/lib/recycleNodesInto.js +2 -4
- package/lib/relayUnstableBatchedUpdates.js +2 -5
- package/lib/relayUnstableBatchedUpdates.native.js +2 -5
- package/lib/requestsForOperation.js +75 -0
- package/lib/simpleClone.js +2 -4
- package/lib/stableCopy.js +35 -0
- package/lib/testEditDistance.js +2 -5
- package/lib/throwFailedPromise.js +2 -5
- package/lib/writeRelayGeneratedFile.js +84 -50
- package/package.json +16 -15
- package/relay-compiler.js +7208 -5872
- package/relay-compiler.min.js +7200 -5867
- package/ARCHITECTURE.md +0 -94
- package/PATENTS +0 -33
- package/lib/AutoAliasTransform.js +0 -80
- package/lib/GraphQLFileParser.js +0 -27
- package/lib/GraphQLTextParser.js +0 -46
- package/lib/RelayCodegenTypes.js +0 -14
- package/lib/RelayCompiledTypes.js +0 -13
- package/lib/RelayCompiler.js +0 -144
- package/lib/RelayCompilerContext.js +0 -133
- package/lib/RelayCompilerUserError.js +0 -30
- package/lib/RelayConsoleReporter.js +0 -40
- package/lib/RelayFileIRParser.js +0 -66
- package/lib/RelayFlattenTransform.js +0 -278
- package/lib/RelayFlowParser.js +0 -188
- package/lib/RelayGenerateRequisiteFieldsTransform.js +0 -189
- package/lib/RelayIR.js +0 -14
- package/lib/RelayMultiReporter.js +0 -40
- package/lib/RelayReporter.js +0 -14
- package/lib/RelayTestSchema.js +0 -21
- package/lib/formatStorageKey.js +0 -37
- package/lib/getIdentifierForRelaySelection.js +0 -54
- package/lib/getRelayLiteralArgumentValues.js +0 -28
- package/lib/parseGraphQLText.js +0 -33
- package/lib/prettyStringify.js +0 -35
- package/lib/printFlowTypes.js +0 -282
- package/lib/stableJSONStringify.js +0 -45
- package/lib/stableJSONStringifyOSS.js +0 -44
- package/lib/transformInputObjectToIR.js +0 -85
- package/lib/writeLegacyFlowFile.js +0 -24
package/lib/RelayProfiler.js
CHANGED
@@ -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
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
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
|
-
|
82
|
-
|
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
|
|
package/lib/RelayQueryCaching.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
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
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
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
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
|
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
|
29
|
-
return
|
30
|
-
Fragment:
|
31
|
-
|
32
|
-
|
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
|
38
|
-
|
39
|
-
var
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
47
|
-
|
57
|
+
function fragmentMetadata(_ref2) {
|
58
|
+
var plural = _ref2.plural;
|
48
59
|
|
49
|
-
require('fbjs/lib/invariant')(plural === undefined || typeof plural === 'boolean', 'RelayRelayDirectiveTransform: Expected the
|
50
|
-
return
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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:
|
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
|
+
*/
|
package/lib/RelayShallowMock.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
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
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('./
|
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
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
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
|
25
|
-
return
|
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
|
34
|
-
var transformedNode = this.traverse(field
|
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 = {
|
43
|
+
module.exports = {
|
44
|
+
transform: relaySkipHandleFieldTransform
|
45
|
+
};
|
package/lib/RelayTaskQueue.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
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
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
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
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
|
*/
|
package/lib/RelayValidator.js
CHANGED
@@ -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
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
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('./
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
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('./
|
23
|
-
|
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
|
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
|
39
|
-
var viewerType =
|
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
|
47
|
+
return IRTransformer.transform(context, {
|
44
48
|
LinkedField: visitLinkedField
|
45
|
-
}, function () {
|
46
|
-
return {};
|
47
49
|
});
|
48
50
|
}
|
49
51
|
|
50
|
-
function visitLinkedField(field
|
51
|
-
var transformedNode = this.traverse(field
|
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 = {
|
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
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
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
|
-
*
|
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
|
82
|
-
return require('./
|
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
|
-
},
|
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
|
90
|
+
* defined in the server schema.
|
95
91
|
*/
|
96
|
-
function buildState(
|
97
|
-
var
|
92
|
+
function buildState(context, node) {
|
93
|
+
var schema = context.serverSchema;
|
98
94
|
if (node.kind === 'Fragment') {
|
99
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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,
|
113
|
+
function visitField(field, parentType) {
|
129
114
|
if (
|
130
115
|
// Field is defined in the original parent type definition:
|
131
|
-
canHaveSelections(
|
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 =
|
139
|
-
require('fbjs/lib/invariant')(type, 'SkipClientFieldTransform: Expected type `%s` to be defined in ' + 'the
|
140
|
-
return this.traverse(field,
|
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,
|
136
|
+
function visitFragmentSpread(spread, parentType) {
|
154
137
|
var context = this.getContext();
|
155
|
-
var fragment = context.
|
156
|
-
|
157
|
-
|
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,
|
169
|
-
var
|
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,
|
172
|
-
parentType: type
|
173
|
-
}));
|
154
|
+
return this.traverse(fragment, type);
|
174
155
|
}
|
175
156
|
return null;
|
176
157
|
}
|
177
158
|
|
178
|
-
module.exports = {
|
159
|
+
module.exports = {
|
160
|
+
transform: skipClientFieldTransform
|
161
|
+
};
|