relay-compiler 0.0.0-main-f0b65f0b → 0.0.0-main-e0026a71
Sign up to get free protection for your applications and to get access to all the features.
- package/cli.js +23 -0
- package/index.js +19 -3
- package/linux-x64/relay +0 -0
- package/macos-x64/relay +0 -0
- package/package.json +2 -24
- package/win-x64/relay.exe +0 -0
- package/bin/RelayCompilerBin.js.flow +0 -168
- package/bin/RelayCompilerMain.js.flow +0 -515
- package/bin/__fixtures__/plugin-module.js.flow +0 -17
- package/bin/relay-compiler +0 -19068
- package/codegen/CodegenDirectory.js.flow +0 -372
- package/codegen/CodegenRunner.js.flow +0 -424
- package/codegen/CodegenTypes.js.flow +0 -28
- package/codegen/CodegenWatcher.js.flow +0 -250
- package/codegen/NormalizationCodeGenerator.js.flow +0 -566
- package/codegen/ReaderCodeGenerator.js.flow +0 -510
- package/codegen/RelayCodeGenerator.js.flow +0 -85
- package/codegen/RelayFileWriter.js.flow +0 -365
- package/codegen/SourceControl.js.flow +0 -58
- package/codegen/compileRelayArtifacts.js.flow +0 -181
- package/codegen/createPrintRequireModuleDependency.js.flow +0 -19
- package/codegen/sortObjectByKey.js.flow +0 -25
- package/codegen/writeRelayGeneratedFile.js.flow +0 -235
- package/core/ASTCache.js.flow +0 -73
- package/core/ASTConvert.js.flow +0 -230
- package/core/CompilerContext.js.flow +0 -189
- package/core/CompilerError.js.flow +0 -255
- package/core/DotGraphQLParser.js.flow +0 -37
- package/core/GraphQLCompilerProfiler.js.flow +0 -341
- package/core/GraphQLDerivedFromMetadata.js.flow +0 -36
- package/core/GraphQLWatchmanClient.js.flow +0 -109
- package/core/IR.js.flow +0 -326
- package/core/IRPrinter.js.flow +0 -472
- package/core/IRTransformer.js.flow +0 -376
- package/core/IRValidator.js.flow +0 -259
- package/core/IRVisitor.js.flow +0 -150
- package/core/JSModuleParser.js.flow +0 -24
- package/core/RelayCompilerScope.js.flow +0 -199
- package/core/RelayFindGraphQLTags.js.flow +0 -118
- package/core/RelayGraphQLEnumsGenerator.js.flow +0 -55
- package/core/RelayIRTransforms.js.flow +0 -138
- package/core/RelayParser.js.flow +0 -1741
- package/core/RelaySourceModuleParser.js.flow +0 -133
- package/core/Schema.js.flow +0 -2035
- package/core/SchemaUtils.js.flow +0 -120
- package/core/filterContextForNode.js.flow +0 -49
- package/core/getFieldDefinition.js.flow +0 -156
- package/core/getIdentifierForArgumentValue.js.flow +0 -49
- package/core/getIdentifierForSelection.js.flow +0 -68
- package/core/getLiteralArgumentValues.js.flow +0 -32
- package/core/getNormalizationOperationName.js.flow +0 -19
- package/core/inferRootArgumentDefinitions.js.flow +0 -322
- package/index.js.flow +0 -198
- package/language/RelayLanguagePluginInterface.js.flow +0 -283
- package/language/javascript/FindGraphQLTags.js.flow +0 -136
- package/language/javascript/RelayFlowBabelFactories.js.flow +0 -176
- package/language/javascript/RelayFlowGenerator.js.flow +0 -1096
- package/language/javascript/RelayFlowTypeTransformers.js.flow +0 -181
- package/language/javascript/RelayLanguagePluginJavaScript.js.flow +0 -33
- package/language/javascript/formatGeneratedModule.js.flow +0 -65
- package/lib/bin/RelayCompilerBin.js +0 -143
- package/lib/bin/RelayCompilerMain.js +0 -488
- package/lib/bin/__fixtures__/plugin-module.js +0 -16
- package/lib/codegen/CodegenDirectory.js +0 -335
- package/lib/codegen/CodegenRunner.js +0 -433
- package/lib/codegen/CodegenTypes.js +0 -11
- package/lib/codegen/CodegenWatcher.js +0 -271
- package/lib/codegen/NormalizationCodeGenerator.js +0 -487
- package/lib/codegen/ReaderCodeGenerator.js +0 -473
- package/lib/codegen/RelayCodeGenerator.js +0 -75
- package/lib/codegen/RelayFileWriter.js +0 -270
- package/lib/codegen/SourceControl.js +0 -60
- package/lib/codegen/compileRelayArtifacts.js +0 -157
- package/lib/codegen/createPrintRequireModuleDependency.js +0 -19
- package/lib/codegen/sortObjectByKey.js +0 -41
- package/lib/codegen/writeRelayGeneratedFile.js +0 -206
- package/lib/core/ASTCache.js +0 -70
- package/lib/core/ASTConvert.js +0 -198
- package/lib/core/CompilerContext.js +0 -165
- package/lib/core/CompilerError.js +0 -252
- package/lib/core/DotGraphQLParser.js +0 -40
- package/lib/core/GraphQLCompilerProfiler.js +0 -299
- package/lib/core/GraphQLDerivedFromMetadata.js +0 -31
- package/lib/core/GraphQLWatchmanClient.js +0 -150
- package/lib/core/IR.js +0 -11
- package/lib/core/IRPrinter.js +0 -388
- package/lib/core/IRTransformer.js +0 -345
- package/lib/core/IRValidator.js +0 -226
- package/lib/core/IRVisitor.js +0 -45
- package/lib/core/JSModuleParser.js +0 -18
- package/lib/core/RelayCompilerScope.js +0 -183
- package/lib/core/RelayFindGraphQLTags.js +0 -79
- package/lib/core/RelayGraphQLEnumsGenerator.js +0 -50
- package/lib/core/RelayIRTransforms.js +0 -109
- package/lib/core/RelayParser.js +0 -1381
- package/lib/core/RelaySourceModuleParser.js +0 -104
- package/lib/core/Schema.js +0 -1877
- package/lib/core/SchemaUtils.js +0 -98
- package/lib/core/filterContextForNode.js +0 -50
- package/lib/core/getFieldDefinition.js +0 -145
- package/lib/core/getIdentifierForArgumentValue.js +0 -54
- package/lib/core/getIdentifierForSelection.js +0 -49
- package/lib/core/getLiteralArgumentValues.js +0 -26
- package/lib/core/getNormalizationOperationName.js +0 -17
- package/lib/core/inferRootArgumentDefinitions.js +0 -351
- package/lib/index.js +0 -178
- package/lib/language/RelayLanguagePluginInterface.js +0 -26
- package/lib/language/javascript/FindGraphQLTags.js +0 -126
- package/lib/language/javascript/RelayFlowBabelFactories.js +0 -160
- package/lib/language/javascript/RelayFlowGenerator.js +0 -856
- package/lib/language/javascript/RelayFlowTypeTransformers.js +0 -119
- package/lib/language/javascript/RelayLanguagePluginJavaScript.js +0 -30
- package/lib/language/javascript/formatGeneratedModule.js +0 -36
- package/lib/reporters/ConsoleReporter.js +0 -61
- package/lib/reporters/MultiReporter.js +0 -45
- package/lib/reporters/Reporter.js +0 -11
- package/lib/runner/Artifacts.js +0 -323
- package/lib/runner/BufferedFilesystem.js +0 -262
- package/lib/runner/GraphQLASTNodeGroup.js +0 -256
- package/lib/runner/GraphQLASTUtils.js +0 -23
- package/lib/runner/GraphQLNodeMap.js +0 -81
- package/lib/runner/Sources.js +0 -271
- package/lib/runner/StrictMap.js +0 -134
- package/lib/runner/compileArtifacts.js +0 -39
- package/lib/runner/extractAST.js +0 -77
- package/lib/runner/getChangedNodeNames.js +0 -82
- package/lib/runner/getSchemaInstance.js +0 -30
- package/lib/runner/types.js +0 -12
- package/lib/test-utils/TestSchema.js +0 -27
- package/lib/test-utils/parseGraphQLText.js +0 -30
- package/lib/transforms/ApplyFragmentArgumentTransform.js +0 -393
- package/lib/transforms/ClientExtensionsTransform.js +0 -221
- package/lib/transforms/ConnectionTransform.js +0 -639
- package/lib/transforms/DeclarativeConnectionMutationTransform.js +0 -218
- package/lib/transforms/DeferStreamTransform.js +0 -246
- package/lib/transforms/DisallowIdAsAlias.js +0 -40
- package/lib/transforms/DisallowTypenameOnRoot.js +0 -53
- package/lib/transforms/FieldHandleTransform.js +0 -79
- package/lib/transforms/FilterCompilerDirectivesTransform.js +0 -29
- package/lib/transforms/FilterDirectivesTransform.js +0 -42
- package/lib/transforms/FlattenTransform.js +0 -306
- package/lib/transforms/GenerateIDFieldTransform.js +0 -135
- package/lib/transforms/GenerateTypeNameTransform.js +0 -149
- package/lib/transforms/InlineDataFragmentTransform.js +0 -100
- package/lib/transforms/InlineFragmentsTransform.js +0 -61
- package/lib/transforms/MaskTransform.js +0 -117
- package/lib/transforms/MatchTransform.js +0 -434
- package/lib/transforms/ReactFlightComponentTransform.js +0 -158
- package/lib/transforms/RefetchableFragmentTransform.js +0 -249
- package/lib/transforms/RelayDirectiveTransform.js +0 -83
- package/lib/transforms/RequiredFieldTransform.js +0 -369
- package/lib/transforms/SkipClientExtensionsTransform.js +0 -46
- package/lib/transforms/SkipHandleFieldTransform.js +0 -45
- package/lib/transforms/SkipRedundantNodesTransform.js +0 -261
- package/lib/transforms/SkipSplitOperationTransform.js +0 -32
- package/lib/transforms/SkipUnreachableNodeTransform.js +0 -158
- package/lib/transforms/SkipUnusedVariablesTransform.js +0 -75
- package/lib/transforms/SplitModuleImportTransform.js +0 -82
- package/lib/transforms/TestOperationTransform.js +0 -144
- package/lib/transforms/TransformUtils.js +0 -21
- package/lib/transforms/ValidateGlobalVariablesTransform.js +0 -92
- package/lib/transforms/ValidateRequiredArgumentsTransform.js +0 -114
- package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +0 -108
- package/lib/transforms/ValidateUnusedVariablesTransform.js +0 -96
- package/lib/transforms/query-generators/FetchableQueryGenerator.js +0 -157
- package/lib/transforms/query-generators/NodeQueryGenerator.js +0 -166
- package/lib/transforms/query-generators/QueryQueryGenerator.js +0 -48
- package/lib/transforms/query-generators/ViewerQueryGenerator.js +0 -77
- package/lib/transforms/query-generators/index.js +0 -60
- package/lib/transforms/query-generators/utils.js +0 -92
- package/lib/util/CodeMarker.js +0 -80
- package/lib/util/DefaultHandleKey.js +0 -15
- package/lib/util/RelayCompilerCache.js +0 -97
- package/lib/util/Rollout.js +0 -40
- package/lib/util/TimeReporter.js +0 -83
- package/lib/util/areEqualArgValues.js +0 -135
- package/lib/util/argumentContainsVariables.js +0 -37
- package/lib/util/dedupeJSONStringify.js +0 -160
- package/lib/util/generateAbstractTypeRefinementKey.js +0 -24
- package/lib/util/getDefinitionNodeHash.js +0 -22
- package/lib/util/getModuleName.js +0 -32
- package/lib/util/joinArgumentDefinitions.js +0 -67
- package/lib/util/md5.js +0 -17
- package/lib/util/murmurHash.js +0 -86
- package/lib/util/nullthrowsOSS.js +0 -23
- package/lib/util/orList.js +0 -36
- package/lib/util/partitionArray.js +0 -35
- package/relay-compiler.js +0 -17
- package/relay-compiler.min.js +0 -22
- package/reporters/ConsoleReporter.js.flow +0 -81
- package/reporters/MultiReporter.js.flow +0 -43
- package/reporters/Reporter.js.flow +0 -19
- package/runner/Artifacts.js.flow +0 -215
- package/runner/BufferedFilesystem.js.flow +0 -194
- package/runner/GraphQLASTNodeGroup.js.flow +0 -174
- package/runner/GraphQLASTUtils.js.flow +0 -26
- package/runner/GraphQLNodeMap.js.flow +0 -55
- package/runner/Sources.js.flow +0 -227
- package/runner/StrictMap.js.flow +0 -96
- package/runner/compileArtifacts.js.flow +0 -75
- package/runner/extractAST.js.flow +0 -98
- package/runner/getChangedNodeNames.js.flow +0 -48
- package/runner/getSchemaInstance.js.flow +0 -36
- package/runner/types.js.flow +0 -37
- package/test-utils/TestSchema.js.flow +0 -30
- package/test-utils/parseGraphQLText.js.flow +0 -41
- package/transforms/ApplyFragmentArgumentTransform.js.flow +0 -524
- package/transforms/ClientExtensionsTransform.js.flow +0 -224
- package/transforms/ConnectionTransform.js.flow +0 -850
- package/transforms/DeclarativeConnectionMutationTransform.js.flow +0 -245
- package/transforms/DeferStreamTransform.js.flow +0 -263
- package/transforms/DisallowIdAsAlias.js.flow +0 -46
- package/transforms/DisallowTypenameOnRoot.js.flow +0 -44
- package/transforms/FieldHandleTransform.js.flow +0 -77
- package/transforms/FilterCompilerDirectivesTransform.js.flow +0 -33
- package/transforms/FilterDirectivesTransform.js.flow +0 -45
- package/transforms/FlattenTransform.js.flow +0 -458
- package/transforms/GenerateIDFieldTransform.js.flow +0 -151
- package/transforms/GenerateTypeNameTransform.js.flow +0 -159
- package/transforms/InlineDataFragmentTransform.js.flow +0 -123
- package/transforms/InlineFragmentsTransform.js.flow +0 -70
- package/transforms/MaskTransform.js.flow +0 -124
- package/transforms/MatchTransform.js.flow +0 -587
- package/transforms/ReactFlightComponentTransform.js.flow +0 -207
- package/transforms/RefetchableFragmentTransform.js.flow +0 -266
- package/transforms/RelayDirectiveTransform.js.flow +0 -96
- package/transforms/RequiredFieldTransform.js.flow +0 -413
- package/transforms/SkipClientExtensionsTransform.js.flow +0 -54
- package/transforms/SkipHandleFieldTransform.js.flow +0 -44
- package/transforms/SkipRedundantNodesTransform.js.flow +0 -277
- package/transforms/SkipSplitOperationTransform.js.flow +0 -37
- package/transforms/SkipUnreachableNodeTransform.js.flow +0 -148
- package/transforms/SkipUnusedVariablesTransform.js.flow +0 -59
- package/transforms/SplitModuleImportTransform.js.flow +0 -97
- package/transforms/TestOperationTransform.js.flow +0 -142
- package/transforms/TransformUtils.js.flow +0 -26
- package/transforms/ValidateGlobalVariablesTransform.js.flow +0 -80
- package/transforms/ValidateRequiredArgumentsTransform.js.flow +0 -130
- package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +0 -128
- package/transforms/ValidateUnusedVariablesTransform.js.flow +0 -88
- package/transforms/query-generators/FetchableQueryGenerator.js.flow +0 -188
- package/transforms/query-generators/NodeQueryGenerator.js.flow +0 -217
- package/transforms/query-generators/QueryQueryGenerator.js.flow +0 -57
- package/transforms/query-generators/ViewerQueryGenerator.js.flow +0 -97
- package/transforms/query-generators/index.js.flow +0 -89
- package/transforms/query-generators/utils.js.flow +0 -76
- package/util/CodeMarker.js.flow +0 -79
- package/util/DefaultHandleKey.js.flow +0 -17
- package/util/RelayCompilerCache.js.flow +0 -86
- package/util/Rollout.js.flow +0 -39
- package/util/TimeReporter.js.flow +0 -79
- package/util/areEqualArgValues.js.flow +0 -126
- package/util/argumentContainsVariables.js.flow +0 -38
- package/util/dedupeJSONStringify.js.flow +0 -156
- package/util/generateAbstractTypeRefinementKey.js.flow +0 -29
- package/util/getDefinitionNodeHash.js.flow +0 -24
- package/util/getModuleName.js.flow +0 -39
- package/util/joinArgumentDefinitions.js.flow +0 -105
- package/util/md5.js.flow +0 -19
- package/util/murmurHash.js.flow +0 -94
- package/util/nullthrowsOSS.js.flow +0 -25
- package/util/orList.js.flow +0 -37
- package/util/partitionArray.js.flow +0 -37
@@ -1,393 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
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
|
-
* @format
|
9
|
-
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
|
-
'use strict';
|
12
|
-
|
13
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
14
|
-
|
15
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
-
|
17
|
-
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
18
|
-
|
19
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
20
|
-
|
21
|
-
var _require = require('../core/CompilerError'),
|
22
|
-
createCompilerError = _require.createCompilerError,
|
23
|
-
createNonRecoverableUserError = _require.createNonRecoverableUserError;
|
24
|
-
|
25
|
-
var getIdentifierForArgumentValue = require('../core/getIdentifierForArgumentValue');
|
26
|
-
|
27
|
-
var IRTransformer = require('../core/IRTransformer');
|
28
|
-
|
29
|
-
var RelayCompilerScope = require('../core/RelayCompilerScope');
|
30
|
-
|
31
|
-
var murmurHash = require('../util/murmurHash');
|
32
|
-
|
33
|
-
var getFragmentScope = RelayCompilerScope.getFragmentScope,
|
34
|
-
getRootScope = RelayCompilerScope.getRootScope;
|
35
|
-
|
36
|
-
/**
|
37
|
-
* A transform that converts a set of documents containing fragments/fragment
|
38
|
-
* spreads *with* arguments to one where all arguments have been inlined. This
|
39
|
-
* is effectively static currying of functions. Nodes are changed as follows:
|
40
|
-
* - Fragment spreads with arguments are replaced with references to an inlined
|
41
|
-
* version of the referenced fragment.
|
42
|
-
* - Fragments with argument definitions are cloned once per unique set of
|
43
|
-
* arguments, with the name changed to original name + hash and all nested
|
44
|
-
* variable references changed to the value of that variable given its
|
45
|
-
* arguments.
|
46
|
-
* - Field & directive argument variables are replaced with the value of those
|
47
|
-
* variables in context.
|
48
|
-
* - All nodes are cloned with updated children.
|
49
|
-
*
|
50
|
-
* The transform also handles statically passing/failing Condition nodes:
|
51
|
-
* - Literal Conditions with a passing value are elided and their selections
|
52
|
-
* inlined in their parent.
|
53
|
-
* - Literal Conditions with a failing value are removed.
|
54
|
-
* - Nodes that would become empty as a result of the above are removed.
|
55
|
-
*
|
56
|
-
* Note that unreferenced fragments are not added to the output.
|
57
|
-
*/
|
58
|
-
function applyFragmentArgumentTransform(context) {
|
59
|
-
var fragments = new Map();
|
60
|
-
var nextContext = IRTransformer.transform(context, {
|
61
|
-
Root: function Root(node) {
|
62
|
-
var scope = getRootScope(node.argumentDefinitions);
|
63
|
-
return transformNode(context, fragments, scope, node, [node]);
|
64
|
-
},
|
65
|
-
SplitOperation: function SplitOperation(node) {
|
66
|
-
return transformNode(context, fragments, {}, node, [node]);
|
67
|
-
},
|
68
|
-
// Fragments are included below where referenced.
|
69
|
-
// Unreferenced fragments are not included.
|
70
|
-
Fragment: function Fragment() {
|
71
|
-
return null;
|
72
|
-
}
|
73
|
-
});
|
74
|
-
|
75
|
-
var _iterator = (0, _createForOfIteratorHelper2["default"])(fragments.values()),
|
76
|
-
_step;
|
77
|
-
|
78
|
-
try {
|
79
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
80
|
-
var pendingFragment = _step.value;
|
81
|
-
|
82
|
-
if (pendingFragment.kind === 'resolved' && pendingFragment.value) {
|
83
|
-
nextContext = nextContext.add(pendingFragment.value);
|
84
|
-
}
|
85
|
-
}
|
86
|
-
} catch (err) {
|
87
|
-
_iterator.e(err);
|
88
|
-
} finally {
|
89
|
-
_iterator.f();
|
90
|
-
}
|
91
|
-
|
92
|
-
return nextContext;
|
93
|
-
}
|
94
|
-
|
95
|
-
function transformNode(context, fragments, scope, node, errorContext) {
|
96
|
-
var selections = transformSelections(context, fragments, scope, node.selections, errorContext);
|
97
|
-
|
98
|
-
if (!selections) {
|
99
|
-
return null;
|
100
|
-
}
|
101
|
-
|
102
|
-
if (node.hasOwnProperty('directives')) {
|
103
|
-
var directives = transformDirectives(scope, node.directives, errorContext);
|
104
|
-
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
|
105
|
-
directives: directives,
|
106
|
-
selections: selections
|
107
|
-
});
|
108
|
-
}
|
109
|
-
|
110
|
-
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
|
111
|
-
selections: selections
|
112
|
-
});
|
113
|
-
}
|
114
|
-
|
115
|
-
function transformDeferStreamNode(context, fragments, scope, node, errorContext) {
|
116
|
-
var nextNode = transformNode(context, fragments, scope, node, errorContext);
|
117
|
-
|
118
|
-
if (!nextNode) {
|
119
|
-
return null;
|
120
|
-
}
|
121
|
-
|
122
|
-
nextNode;
|
123
|
-
|
124
|
-
if (nextNode["if"]) {
|
125
|
-
var ifVal = transformValue(scope, nextNode["if"], errorContext);
|
126
|
-
|
127
|
-
if (ifVal.kind === 'Literal' && ifVal.value === false && node.selections && node.selections.length === 1) {
|
128
|
-
// Skip Defer/Stream wrapper with literal if: false
|
129
|
-
return node.selections[0];
|
130
|
-
} // $FlowFixMe[cannot-write] nextNode is uniquely owned
|
131
|
-
|
132
|
-
|
133
|
-
nextNode["if"] = ifVal;
|
134
|
-
}
|
135
|
-
|
136
|
-
if (nextNode.useCustomizedBatch) {
|
137
|
-
// $FlowFixMe[cannot-write] nextNode is uniquely owned
|
138
|
-
nextNode.useCustomizedBatch = transformValue(scope, nextNode.useCustomizedBatch, errorContext);
|
139
|
-
}
|
140
|
-
|
141
|
-
if (nextNode.initialCount) {
|
142
|
-
// $FlowFixMe[cannot-write] nextNode is uniquely owned
|
143
|
-
nextNode.initialCount = transformValue(scope, nextNode.initialCount, errorContext);
|
144
|
-
}
|
145
|
-
|
146
|
-
return nextNode;
|
147
|
-
}
|
148
|
-
|
149
|
-
function transformFragmentSpread(context, fragments, scope, spread, errorContext) {
|
150
|
-
var directives = transformDirectives(scope, spread.directives, errorContext);
|
151
|
-
var appliedFragment = transformFragment(context, fragments, scope, spread, spread.args, [].concat((0, _toConsumableArray2["default"])(errorContext), [spread]));
|
152
|
-
|
153
|
-
if (!appliedFragment) {
|
154
|
-
return null;
|
155
|
-
}
|
156
|
-
|
157
|
-
var transformed = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, spread), {}, {
|
158
|
-
kind: 'FragmentSpread',
|
159
|
-
args: [],
|
160
|
-
directives: directives,
|
161
|
-
name: appliedFragment.name
|
162
|
-
});
|
163
|
-
return transformed;
|
164
|
-
}
|
165
|
-
|
166
|
-
function transformField(context, fragments, scope, field, errorContext) {
|
167
|
-
var args = transformArguments(scope, field.args, errorContext);
|
168
|
-
var directives = transformDirectives(scope, field.directives, errorContext);
|
169
|
-
|
170
|
-
if (field.kind === 'LinkedField') {
|
171
|
-
var selections = transformSelections(context, fragments, scope, field.selections, errorContext);
|
172
|
-
|
173
|
-
if (!selections) {
|
174
|
-
return null;
|
175
|
-
}
|
176
|
-
|
177
|
-
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, field), {}, {
|
178
|
-
args: args,
|
179
|
-
directives: directives,
|
180
|
-
selections: selections
|
181
|
-
});
|
182
|
-
} else {
|
183
|
-
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, field), {}, {
|
184
|
-
args: args,
|
185
|
-
directives: directives
|
186
|
-
});
|
187
|
-
}
|
188
|
-
}
|
189
|
-
|
190
|
-
function transformCondition(context, fragments, scope, node, errorContext) {
|
191
|
-
var condition = transformValue(scope, node.condition, errorContext);
|
192
|
-
|
193
|
-
if (!(condition.kind === 'Literal' || condition.kind === 'Variable')) {
|
194
|
-
// This transform does whole-program optimization, errors in
|
195
|
-
// a single document could break invariants and/or cause
|
196
|
-
// additional spurious errors.
|
197
|
-
throw createNonRecoverableUserError('A non-scalar value was applied to an @include or @skip directive, ' + 'the `if` argument value must be a ' + 'variable or a literal Boolean.', [condition.loc]);
|
198
|
-
}
|
199
|
-
|
200
|
-
if (condition.kind === 'Literal' && condition.value !== node.passingValue) {
|
201
|
-
// Dead code, no need to traverse further.
|
202
|
-
return null;
|
203
|
-
}
|
204
|
-
|
205
|
-
var selections = transformSelections(context, fragments, scope, node.selections, errorContext);
|
206
|
-
|
207
|
-
if (!selections) {
|
208
|
-
return null;
|
209
|
-
}
|
210
|
-
|
211
|
-
if (condition.kind === 'Literal' && condition.value === node.passingValue) {
|
212
|
-
// Always passes, return inlined selections
|
213
|
-
return selections;
|
214
|
-
}
|
215
|
-
|
216
|
-
return [(0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
|
217
|
-
condition: condition,
|
218
|
-
selections: selections
|
219
|
-
})];
|
220
|
-
}
|
221
|
-
|
222
|
-
function transformSelections(context, fragments, scope, selections, errorContext) {
|
223
|
-
var nextSelections = null;
|
224
|
-
selections.forEach(function (selection) {
|
225
|
-
var nextSelection;
|
226
|
-
|
227
|
-
if (selection.kind === 'ClientExtension' || selection.kind === 'InlineDataFragmentSpread' || selection.kind === 'InlineFragment' || selection.kind === 'ModuleImport') {
|
228
|
-
nextSelection = transformNode(context, fragments, scope, selection, errorContext);
|
229
|
-
} else if (selection.kind === 'Defer' || selection.kind === 'Stream') {
|
230
|
-
nextSelection = transformDeferStreamNode(context, fragments, scope, selection, errorContext);
|
231
|
-
} else if (selection.kind === 'FragmentSpread') {
|
232
|
-
nextSelection = transformFragmentSpread(context, fragments, scope, selection, errorContext);
|
233
|
-
} else if (selection.kind === 'Condition') {
|
234
|
-
var conditionSelections = transformCondition(context, fragments, scope, selection, errorContext);
|
235
|
-
|
236
|
-
if (conditionSelections) {
|
237
|
-
var _nextSelections;
|
238
|
-
|
239
|
-
nextSelections = nextSelections || [];
|
240
|
-
|
241
|
-
(_nextSelections = nextSelections).push.apply(_nextSelections, (0, _toConsumableArray2["default"])(conditionSelections));
|
242
|
-
}
|
243
|
-
} else if (selection.kind === 'LinkedField' || selection.kind === 'ScalarField') {
|
244
|
-
nextSelection = transformField(context, fragments, scope, selection, errorContext);
|
245
|
-
} else {
|
246
|
-
selection;
|
247
|
-
throw createCompilerError("ApplyFragmentArgumentTransform: Unsupported kind '".concat(selection.kind, "'."), [selection.loc]);
|
248
|
-
}
|
249
|
-
|
250
|
-
if (nextSelection) {
|
251
|
-
nextSelections = nextSelections || [];
|
252
|
-
nextSelections.push(nextSelection);
|
253
|
-
}
|
254
|
-
});
|
255
|
-
return nextSelections;
|
256
|
-
}
|
257
|
-
|
258
|
-
function transformDirectives(scope, directives, errorContext) {
|
259
|
-
return directives.map(function (directive) {
|
260
|
-
var args = transformArguments(scope, directive.args, errorContext);
|
261
|
-
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, directive), {}, {
|
262
|
-
args: args
|
263
|
-
});
|
264
|
-
});
|
265
|
-
}
|
266
|
-
|
267
|
-
function transformArguments(scope, args, errorContext) {
|
268
|
-
return args.map(function (arg) {
|
269
|
-
var value = transformValue(scope, arg.value, errorContext);
|
270
|
-
return value === arg.value ? arg : (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, arg), {}, {
|
271
|
-
value: value
|
272
|
-
});
|
273
|
-
});
|
274
|
-
}
|
275
|
-
|
276
|
-
function transformValue(scope, value, errorContext) {
|
277
|
-
if (value.kind === 'Variable') {
|
278
|
-
var scopeValue = scope[value.variableName];
|
279
|
-
|
280
|
-
if (scopeValue == null) {
|
281
|
-
var _errorContext$;
|
282
|
-
|
283
|
-
// This transform does whole-program optimization, errors in
|
284
|
-
// a single document could break invariants and/or cause
|
285
|
-
// additional spurious errors.
|
286
|
-
throw createNonRecoverableUserError("Variable '$".concat(value.variableName, "' is not in scope."), [(_errorContext$ = errorContext[0]) === null || _errorContext$ === void 0 ? void 0 : _errorContext$.loc, value.loc].filter(Boolean));
|
287
|
-
}
|
288
|
-
|
289
|
-
return scopeValue;
|
290
|
-
} else if (value.kind === 'ObjectValue') {
|
291
|
-
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, value), {}, {
|
292
|
-
fields: value.fields.map(function (field) {
|
293
|
-
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, field), {}, {
|
294
|
-
value: transformValue(scope, field.value, errorContext)
|
295
|
-
});
|
296
|
-
})
|
297
|
-
});
|
298
|
-
} else if (value.kind === 'ListValue') {
|
299
|
-
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, value), {}, {
|
300
|
-
items: value.items.map(function (item) {
|
301
|
-
return transformValue(scope, item, errorContext);
|
302
|
-
})
|
303
|
-
});
|
304
|
-
}
|
305
|
-
|
306
|
-
return value;
|
307
|
-
}
|
308
|
-
/**
|
309
|
-
* Apply arguments to a fragment, creating a new fragment (with the given name)
|
310
|
-
* with all values recursively applied.
|
311
|
-
*/
|
312
|
-
|
313
|
-
|
314
|
-
function transformFragment(context, fragments, parentScope, spread, args, errorContext) {
|
315
|
-
var schema = context.getSchema();
|
316
|
-
var fragment = context.getFragment(spread.name, spread.loc);
|
317
|
-
var argumentsHash = hashArguments(args, parentScope, errorContext);
|
318
|
-
var fragmentName = argumentsHash ? "".concat(fragment.name, "_").concat(argumentsHash) : fragment.name;
|
319
|
-
var appliedFragment = fragments.get(fragmentName);
|
320
|
-
|
321
|
-
if (appliedFragment) {
|
322
|
-
if (appliedFragment.kind === 'resolved') {
|
323
|
-
return appliedFragment.value;
|
324
|
-
} else {
|
325
|
-
// This transform does whole-program optimization, errors in
|
326
|
-
// a single document could break invariants and/or cause
|
327
|
-
// additional spurious errors.
|
328
|
-
throw createNonRecoverableUserError("Found a circular reference from fragment '".concat(fragment.name, "'."), errorContext.map(function (node) {
|
329
|
-
return node.loc;
|
330
|
-
}));
|
331
|
-
}
|
332
|
-
}
|
333
|
-
|
334
|
-
var fragmentScope = getFragmentScope(schema, fragment.argumentDefinitions, args, parentScope, spread); // record that this fragment is pending to detect circular references
|
335
|
-
|
336
|
-
fragments.set(fragmentName, {
|
337
|
-
kind: 'pending'
|
338
|
-
});
|
339
|
-
var transformedFragment = null;
|
340
|
-
var selections = transformSelections(context, fragments, fragmentScope, fragment.selections, errorContext);
|
341
|
-
|
342
|
-
if (selections) {
|
343
|
-
transformedFragment = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, fragment), {}, {
|
344
|
-
selections: selections,
|
345
|
-
name: fragmentName,
|
346
|
-
argumentDefinitions: []
|
347
|
-
});
|
348
|
-
}
|
349
|
-
|
350
|
-
fragments.set(fragmentName, {
|
351
|
-
kind: 'resolved',
|
352
|
-
value: transformedFragment
|
353
|
-
});
|
354
|
-
return transformedFragment;
|
355
|
-
}
|
356
|
-
|
357
|
-
function hashArguments(args, scope, errorContext) {
|
358
|
-
if (!args.length) {
|
359
|
-
return null;
|
360
|
-
}
|
361
|
-
|
362
|
-
var sortedArgs = (0, _toConsumableArray2["default"])(args).sort(function (a, b) {
|
363
|
-
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
364
|
-
});
|
365
|
-
var printedArgs = JSON.stringify(sortedArgs.map(function (arg) {
|
366
|
-
var value;
|
367
|
-
|
368
|
-
if (arg.value.kind === 'Variable') {
|
369
|
-
value = scope[arg.value.variableName];
|
370
|
-
|
371
|
-
if (value == null) {
|
372
|
-
var _errorContext$2;
|
373
|
-
|
374
|
-
// This transform does whole-program optimization, errors in
|
375
|
-
// a single document could break invariants and/or cause
|
376
|
-
// additional spurious errors.
|
377
|
-
throw createNonRecoverableUserError("Variable '$".concat(arg.value.variableName, "' is not in scope."), [(_errorContext$2 = errorContext[0]) === null || _errorContext$2 === void 0 ? void 0 : _errorContext$2.loc, arg.value.loc].filter(Boolean));
|
378
|
-
}
|
379
|
-
} else {
|
380
|
-
value = arg.value;
|
381
|
-
}
|
382
|
-
|
383
|
-
return {
|
384
|
-
name: arg.name,
|
385
|
-
value: getIdentifierForArgumentValue(value)
|
386
|
-
};
|
387
|
-
}));
|
388
|
-
return murmurHash(printedArgs);
|
389
|
-
}
|
390
|
-
|
391
|
-
module.exports = {
|
392
|
-
transform: applyFragmentArgumentTransform
|
393
|
-
};
|
@@ -1,221 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
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
|
-
* @format
|
9
|
-
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
|
-
'use strict';
|
12
|
-
|
13
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
14
|
-
|
15
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
-
|
17
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
18
|
-
|
19
|
-
var _require = require('../core/CompilerError'),
|
20
|
-
createCompilerError = _require.createCompilerError,
|
21
|
-
createUserError = _require.createUserError;
|
22
|
-
|
23
|
-
var IRTransformer = require('../core/IRTransformer');
|
24
|
-
|
25
|
-
var cachesByNode = new Map();
|
26
|
-
|
27
|
-
function clientExtensionTransform(context) {
|
28
|
-
cachesByNode = new Map();
|
29
|
-
return IRTransformer.transform(context, {
|
30
|
-
Fragment: traverseDefinition,
|
31
|
-
Root: traverseDefinition,
|
32
|
-
SplitOperation: traverseDefinition
|
33
|
-
});
|
34
|
-
}
|
35
|
-
|
36
|
-
function traverseDefinition(node) {
|
37
|
-
var compilerContext = this.getContext();
|
38
|
-
var schema = compilerContext.getSchema();
|
39
|
-
var rootType;
|
40
|
-
|
41
|
-
switch (node.kind) {
|
42
|
-
case 'Root':
|
43
|
-
switch (node.operation) {
|
44
|
-
case 'query':
|
45
|
-
rootType = schema.getQueryType();
|
46
|
-
break;
|
47
|
-
|
48
|
-
case 'mutation':
|
49
|
-
rootType = schema.getMutationType();
|
50
|
-
break;
|
51
|
-
|
52
|
-
case 'subscription':
|
53
|
-
rootType = schema.getSubscriptionType();
|
54
|
-
break;
|
55
|
-
|
56
|
-
default:
|
57
|
-
node.operation;
|
58
|
-
}
|
59
|
-
|
60
|
-
break;
|
61
|
-
|
62
|
-
case 'SplitOperation':
|
63
|
-
if (!schema.isServerType(node.type)) {
|
64
|
-
throw createUserError('ClientExtensionTransform: SplitOperation (@module) can be created ' + 'only for fragments that defined on a server type', [node.loc]);
|
65
|
-
}
|
66
|
-
|
67
|
-
rootType = node.type;
|
68
|
-
break;
|
69
|
-
|
70
|
-
case 'Fragment':
|
71
|
-
rootType = node.type;
|
72
|
-
break;
|
73
|
-
|
74
|
-
default:
|
75
|
-
node;
|
76
|
-
}
|
77
|
-
|
78
|
-
if (rootType == null) {
|
79
|
-
throw createUserError("ClientExtensionTransform: Expected the type of `".concat(node.name, "` to have been defined in the schema. Make sure both server and ") + 'client schema are up to date.', [node.loc]);
|
80
|
-
}
|
81
|
-
|
82
|
-
return traverseSelections(node, compilerContext, rootType);
|
83
|
-
}
|
84
|
-
|
85
|
-
function traverseSelections(node, compilerContext, parentType) {
|
86
|
-
// $FlowFixMe[escaped-generic]
|
87
|
-
var nodeCache = cachesByNode.get(node);
|
88
|
-
|
89
|
-
if (nodeCache == null) {
|
90
|
-
nodeCache = new Map(); // $FlowFixMe[escaped-generic]
|
91
|
-
|
92
|
-
cachesByNode.set(node, nodeCache);
|
93
|
-
}
|
94
|
-
|
95
|
-
var result = nodeCache.get(parentType);
|
96
|
-
|
97
|
-
if (result != null) {
|
98
|
-
/* $FlowFixMe[incompatible-return] - TODO: type IRTransformer to allow
|
99
|
-
* changing result type */
|
100
|
-
return result;
|
101
|
-
}
|
102
|
-
|
103
|
-
var schema = compilerContext.getSchema();
|
104
|
-
var clientSelections = [];
|
105
|
-
var serverSelections = cowMap(node.selections, function (selection) {
|
106
|
-
switch (selection.kind) {
|
107
|
-
case 'ClientExtension':
|
108
|
-
throw createCompilerError('Unexpected ClientExtension node before ClientExtensionTransform', [selection.loc]);
|
109
|
-
|
110
|
-
case 'Condition':
|
111
|
-
case 'Defer':
|
112
|
-
case 'InlineDataFragmentSpread':
|
113
|
-
case 'ModuleImport':
|
114
|
-
case 'Stream':
|
115
|
-
return traverseSelections(selection, compilerContext, parentType);
|
116
|
-
|
117
|
-
case 'ScalarField':
|
118
|
-
if (schema.isClientDefinedField(schema.assertCompositeType(schema.getRawType(parentType)), selection)) {
|
119
|
-
clientSelections.push(selection);
|
120
|
-
return null;
|
121
|
-
} else {
|
122
|
-
return selection;
|
123
|
-
}
|
124
|
-
|
125
|
-
case 'LinkedField':
|
126
|
-
{
|
127
|
-
if (schema.isClientDefinedField(schema.assertCompositeType(schema.getRawType(parentType)), selection)) {
|
128
|
-
clientSelections.push(selection);
|
129
|
-
return null;
|
130
|
-
}
|
131
|
-
|
132
|
-
return traverseSelections(selection, compilerContext, selection.type);
|
133
|
-
}
|
134
|
-
|
135
|
-
case 'InlineFragment':
|
136
|
-
{
|
137
|
-
var isClientType = !schema.isServerType(selection.typeCondition);
|
138
|
-
|
139
|
-
if (isClientType) {
|
140
|
-
clientSelections.push(selection);
|
141
|
-
return null;
|
142
|
-
}
|
143
|
-
|
144
|
-
return traverseSelections(selection, compilerContext, selection.typeCondition);
|
145
|
-
}
|
146
|
-
|
147
|
-
case 'FragmentSpread':
|
148
|
-
{
|
149
|
-
return selection;
|
150
|
-
}
|
151
|
-
|
152
|
-
default:
|
153
|
-
selection;
|
154
|
-
throw createCompilerError("ClientExtensionTransform: Unexpected selection of kind `".concat(selection.kind, "`."), [selection.loc]);
|
155
|
-
}
|
156
|
-
});
|
157
|
-
|
158
|
-
if (clientSelections.length === 0) {
|
159
|
-
if (serverSelections === node.selections) {
|
160
|
-
result = node;
|
161
|
-
} else {
|
162
|
-
result = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
|
163
|
-
selections: serverSelections
|
164
|
-
});
|
165
|
-
}
|
166
|
-
} else {
|
167
|
-
result = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
|
168
|
-
selections: [].concat((0, _toConsumableArray2["default"])(serverSelections), [// Group client fields under a single ClientExtension node
|
169
|
-
{
|
170
|
-
kind: 'ClientExtension',
|
171
|
-
loc: node.loc,
|
172
|
-
metadata: null,
|
173
|
-
selections: clientSelections
|
174
|
-
}])
|
175
|
-
});
|
176
|
-
} // $FlowFixMe[escaped-generic]
|
177
|
-
|
178
|
-
|
179
|
-
nodeCache.set(parentType, result);
|
180
|
-
/* $FlowFixMe[incompatible-return] - TODO: type IRTransformer to allow
|
181
|
-
* changing result type */
|
182
|
-
|
183
|
-
return result;
|
184
|
-
}
|
185
|
-
/**
|
186
|
-
* Maps an array with copy-on-write semantics.
|
187
|
-
* `null` return values from the map function are removals.
|
188
|
-
*/
|
189
|
-
|
190
|
-
|
191
|
-
function cowMap(selections, f) {
|
192
|
-
for (var i = 0; i < selections.length; i++) {
|
193
|
-
var prevSelection = selections[i];
|
194
|
-
var nextSelection = f(prevSelection);
|
195
|
-
|
196
|
-
if (prevSelection !== nextSelection) {
|
197
|
-
var result = selections.slice(0, i);
|
198
|
-
|
199
|
-
if (nextSelection != null) {
|
200
|
-
result.push(nextSelection);
|
201
|
-
}
|
202
|
-
|
203
|
-
for (var j = i + 1; j < selections.length; j++) {
|
204
|
-
var innerNextSelection = f(selections[j]);
|
205
|
-
|
206
|
-
if (innerNextSelection != null) {
|
207
|
-
result.push(innerNextSelection);
|
208
|
-
}
|
209
|
-
}
|
210
|
-
|
211
|
-
return result;
|
212
|
-
}
|
213
|
-
} // nothing changed, return original
|
214
|
-
|
215
|
-
|
216
|
-
return selections;
|
217
|
-
}
|
218
|
-
|
219
|
-
module.exports = {
|
220
|
-
transform: clientExtensionTransform
|
221
|
-
};
|