relay-compiler 0.0.0-main-8ff54d69 → 0.0.0-main-4467ae84
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,76 +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
|
-
* @flow strict-local
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
import type {
|
16
|
-
ArgumentDefinition,
|
17
|
-
Fragment,
|
18
|
-
FragmentSpread,
|
19
|
-
LocalArgumentDefinition,
|
20
|
-
} from '../../core/IR';
|
21
|
-
|
22
|
-
function buildFragmentSpread(fragment: Fragment): FragmentSpread {
|
23
|
-
const args = [];
|
24
|
-
for (const argDef of fragment.argumentDefinitions) {
|
25
|
-
if (argDef.kind !== 'LocalArgumentDefinition') {
|
26
|
-
continue;
|
27
|
-
}
|
28
|
-
args.push({
|
29
|
-
kind: 'Argument',
|
30
|
-
loc: {kind: 'Derived', source: argDef.loc},
|
31
|
-
name: argDef.name,
|
32
|
-
type: argDef.type,
|
33
|
-
value: {
|
34
|
-
kind: 'Variable',
|
35
|
-
loc: {kind: 'Derived', source: argDef.loc},
|
36
|
-
variableName: argDef.name,
|
37
|
-
type: argDef.type,
|
38
|
-
},
|
39
|
-
});
|
40
|
-
}
|
41
|
-
return {
|
42
|
-
args,
|
43
|
-
directives: [],
|
44
|
-
kind: 'FragmentSpread',
|
45
|
-
loc: {kind: 'Derived', source: fragment.loc},
|
46
|
-
metadata: null,
|
47
|
-
name: fragment.name,
|
48
|
-
};
|
49
|
-
}
|
50
|
-
|
51
|
-
function buildOperationArgumentDefinitions(
|
52
|
-
argumentDefinitions: $ReadOnlyArray<ArgumentDefinition>,
|
53
|
-
): $ReadOnlyArray<LocalArgumentDefinition> {
|
54
|
-
const localArgumentDefinitions = argumentDefinitions.map(argDef => {
|
55
|
-
if (argDef.kind === 'LocalArgumentDefinition') {
|
56
|
-
return argDef;
|
57
|
-
} else {
|
58
|
-
return {
|
59
|
-
kind: 'LocalArgumentDefinition',
|
60
|
-
name: argDef.name,
|
61
|
-
type: argDef.type,
|
62
|
-
defaultValue: null,
|
63
|
-
loc: argDef.loc,
|
64
|
-
};
|
65
|
-
}
|
66
|
-
});
|
67
|
-
localArgumentDefinitions.sort((a, b) => {
|
68
|
-
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
69
|
-
});
|
70
|
-
return localArgumentDefinitions;
|
71
|
-
}
|
72
|
-
|
73
|
-
module.exports = {
|
74
|
-
buildFragmentSpread,
|
75
|
-
buildOperationArgumentDefinitions,
|
76
|
-
};
|
package/util/CodeMarker.js.flow
DELETED
@@ -1,79 +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
|
-
* @flow strict
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
/**
|
16
|
-
* Marks a string of code as code to be replaced later.
|
17
|
-
*/
|
18
|
-
function moduleDependency(code: string): string {
|
19
|
-
return `@@MODULE_START@@${code}@@MODULE_END@@`;
|
20
|
-
}
|
21
|
-
|
22
|
-
/**
|
23
|
-
* After JSON.stringify'ing some code that contained parts marked with `mark()`,
|
24
|
-
* this post-processes the JSON to convert the marked code strings to raw code.
|
25
|
-
*
|
26
|
-
* Example:
|
27
|
-
* CodeMarker.postProcess(
|
28
|
-
* JSON.stringify({code: CodeMarker.mark('alert(1)')})
|
29
|
-
* )
|
30
|
-
*/
|
31
|
-
function postProcess(json: string, printModule: string => string): string {
|
32
|
-
return json.replace(
|
33
|
-
/"@@MODULE_START@@(.*?)@@MODULE_END@@"/g,
|
34
|
-
(_, moduleName) => printModule(moduleName),
|
35
|
-
);
|
36
|
-
}
|
37
|
-
|
38
|
-
/**
|
39
|
-
* Transforms a value such that any transitive CodeMarker strings are replaced
|
40
|
-
* with the value of the named module in the given module map.
|
41
|
-
*/
|
42
|
-
function transform(node: mixed, moduleMap: {[string]: mixed, ...}): mixed {
|
43
|
-
if (node == null) {
|
44
|
-
return node;
|
45
|
-
} else if (Array.isArray(node)) {
|
46
|
-
return node.map(item => transform(item, moduleMap));
|
47
|
-
} else if (typeof node === 'object') {
|
48
|
-
const next = {};
|
49
|
-
Object.keys(node).forEach(key => {
|
50
|
-
next[key] = transform(node[key], moduleMap);
|
51
|
-
});
|
52
|
-
return next;
|
53
|
-
} else if (typeof node === 'string') {
|
54
|
-
const match = /^@@MODULE_START@@(.*?)@@MODULE_END@@$/.exec(node);
|
55
|
-
if (match != null) {
|
56
|
-
const moduleName = match[1];
|
57
|
-
if (moduleMap.hasOwnProperty(moduleName)) {
|
58
|
-
return moduleMap[moduleName];
|
59
|
-
} else {
|
60
|
-
throw new Error(
|
61
|
-
`Could not find a value for CodeMarker value '${moduleName}', ` +
|
62
|
-
'make sure to supply one in the module mapping.',
|
63
|
-
);
|
64
|
-
}
|
65
|
-
} else if (node.indexOf('@@MODULE_START') >= 0) {
|
66
|
-
throw new Error(`Found unprocessed CodeMarker value '${node}'.`);
|
67
|
-
}
|
68
|
-
return node;
|
69
|
-
} else {
|
70
|
-
// mixed
|
71
|
-
return node;
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
module.exports = {
|
76
|
-
moduleDependency,
|
77
|
-
postProcess,
|
78
|
-
transform,
|
79
|
-
};
|
@@ -1,17 +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
|
-
* @flow strict
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
module.exports = {
|
16
|
-
DEFAULT_HANDLE_KEY: '',
|
17
|
-
};
|
@@ -1,86 +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
|
-
* @flow strict
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
const Profiler = require('../core/GraphQLCompilerProfiler');
|
16
|
-
const crypto = require('crypto');
|
17
|
-
const fs = require('fs');
|
18
|
-
const os = require('os');
|
19
|
-
const path = require('path');
|
20
|
-
|
21
|
-
/**
|
22
|
-
* A file backed cache. Values are JSON encoded on disk, so only JSON
|
23
|
-
* serializable values should be used.
|
24
|
-
*/
|
25
|
-
class RelayCompilerCache<T> {
|
26
|
-
_name: string;
|
27
|
-
_cacheBreaker: string;
|
28
|
-
_dir: ?string = null;
|
29
|
-
|
30
|
-
/**
|
31
|
-
* @param name Human readable identifier for the cache
|
32
|
-
* @param cacheBreaker This should be changed in order to invalidate existing
|
33
|
-
* caches.
|
34
|
-
*/
|
35
|
-
constructor(name: string, cacheBreaker: string) {
|
36
|
-
this._name = name;
|
37
|
-
this._cacheBreaker = cacheBreaker;
|
38
|
-
}
|
39
|
-
|
40
|
-
_getFile(key: string): string {
|
41
|
-
if (this._dir == null) {
|
42
|
-
// Include username in the cache dir to avoid issues with directories being
|
43
|
-
// owned by a different user.
|
44
|
-
const username = os.userInfo().username;
|
45
|
-
const cacheID = crypto
|
46
|
-
.createHash('md5')
|
47
|
-
.update(this._cacheBreaker)
|
48
|
-
.update(username)
|
49
|
-
.digest('hex');
|
50
|
-
const dir = path.join(os.tmpdir(), `${this._name}-${cacheID}`);
|
51
|
-
if (!fs.existsSync(dir)) {
|
52
|
-
try {
|
53
|
-
fs.mkdirSync(dir);
|
54
|
-
} catch (error) {
|
55
|
-
if (error.code !== 'EEXIST') {
|
56
|
-
throw error;
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
this._dir = dir;
|
61
|
-
}
|
62
|
-
return path.join(this._dir, key);
|
63
|
-
}
|
64
|
-
|
65
|
-
getOrCompute(key: string, compute: () => T): T {
|
66
|
-
return Profiler.run('RelayCompilerCache.getOrCompute', () => {
|
67
|
-
const cacheFile = this._getFile(key);
|
68
|
-
if (fs.existsSync(cacheFile)) {
|
69
|
-
try {
|
70
|
-
return JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
|
71
|
-
} catch {
|
72
|
-
// ignore
|
73
|
-
}
|
74
|
-
}
|
75
|
-
const value = compute();
|
76
|
-
try {
|
77
|
-
fs.writeFileSync(cacheFile, JSON.stringify(value), 'utf8');
|
78
|
-
} catch {
|
79
|
-
// ignore
|
80
|
-
}
|
81
|
-
return value;
|
82
|
-
});
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
module.exports = RelayCompilerCache;
|
package/util/Rollout.js.flow
DELETED
@@ -1,39 +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
|
-
* @flow strict
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
let whitelistsByProject: ?Map<string, Set<string>> = null;
|
16
|
-
|
17
|
-
/**
|
18
|
-
* This module helps gradually rolling out changes to the code generation by
|
19
|
-
* gradually enabling more buckets representing randomly distributed artifacts.
|
20
|
-
*/
|
21
|
-
function set(newWhitelistsByProject: Map<string, Set<string>>) {
|
22
|
-
whitelistsByProject = newWhitelistsByProject;
|
23
|
-
}
|
24
|
-
|
25
|
-
function check(project: string, key: string): boolean {
|
26
|
-
if (whitelistsByProject == null) {
|
27
|
-
return true;
|
28
|
-
}
|
29
|
-
const whitelist = whitelistsByProject.get(project);
|
30
|
-
if (whitelist == null) {
|
31
|
-
return true;
|
32
|
-
}
|
33
|
-
return whitelist.has(key);
|
34
|
-
}
|
35
|
-
|
36
|
-
module.exports = {
|
37
|
-
set,
|
38
|
-
check,
|
39
|
-
};
|
@@ -1,79 +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
|
-
* @format
|
8
|
-
* @flow strict-local
|
9
|
-
* @emails oncall+relay
|
10
|
-
*/
|
11
|
-
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
import type {Reporter} from '../reporters/Reporter';
|
17
|
-
|
18
|
-
const {isPromise} = require('relay-runtime');
|
19
|
-
|
20
|
-
function reportTime<T>(reporter: Reporter, message: string, fn: () => T): T {
|
21
|
-
return reportAndReturnTime(reporter, message, fn)[0];
|
22
|
-
}
|
23
|
-
|
24
|
-
function reportAndReturnTime<T>(
|
25
|
-
reporter: Reporter,
|
26
|
-
message: string,
|
27
|
-
fn: () => T,
|
28
|
-
): [T, number] {
|
29
|
-
const startTime = Date.now();
|
30
|
-
const result = fn();
|
31
|
-
if (isPromise(result)) {
|
32
|
-
throw new Error(
|
33
|
-
'reportAndReturnTime: fn(...) returned an unexpected promise.' +
|
34
|
-
' Please use `reportAndReturnAsyncTime` method instead.',
|
35
|
-
);
|
36
|
-
}
|
37
|
-
const elapsedTime = Date.now() - startTime;
|
38
|
-
reporter.reportTime(message, elapsedTime);
|
39
|
-
return [result, elapsedTime];
|
40
|
-
}
|
41
|
-
|
42
|
-
async function reportAndReturnAsyncTime<T>(
|
43
|
-
reporter: Reporter,
|
44
|
-
message: string,
|
45
|
-
fn: () => ?Promise<T>,
|
46
|
-
): Promise<[T, number]> {
|
47
|
-
const startTime = Date.now();
|
48
|
-
const promise = fn();
|
49
|
-
if (!isPromise(promise)) {
|
50
|
-
throw new Error('reportAsyncTime: fn(...) expected to return a promise.');
|
51
|
-
}
|
52
|
-
const result = await promise;
|
53
|
-
const elapsedTime = Date.now() - startTime;
|
54
|
-
reporter.reportTime(message, elapsedTime);
|
55
|
-
return [result, elapsedTime];
|
56
|
-
}
|
57
|
-
|
58
|
-
async function reportAsyncTime<T>(
|
59
|
-
reporter: Reporter,
|
60
|
-
message: string,
|
61
|
-
fn: () => ?Promise<T>,
|
62
|
-
): Promise<T> {
|
63
|
-
const startTime = Date.now();
|
64
|
-
const promise = fn();
|
65
|
-
if (!isPromise(promise)) {
|
66
|
-
throw new Error('reportAsyncTime: fn(...) expected to return a promise.');
|
67
|
-
}
|
68
|
-
const result = await promise;
|
69
|
-
const elapsedTime = Date.now() - startTime;
|
70
|
-
reporter.reportTime(message, elapsedTime);
|
71
|
-
return result;
|
72
|
-
}
|
73
|
-
|
74
|
-
module.exports = {
|
75
|
-
reportTime,
|
76
|
-
reportAndReturnTime,
|
77
|
-
reportAsyncTime,
|
78
|
-
reportAndReturnAsyncTime,
|
79
|
-
};
|
@@ -1,126 +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
|
-
* @flow
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// TODO: This is only used with `ArgumentValue` types, so it could be simpler.
|
12
|
-
|
13
|
-
// flowlint ambiguous-object-type:error
|
14
|
-
'use strict';
|
15
|
-
|
16
|
-
const aStackPool = [];
|
17
|
-
const bStackPool = [];
|
18
|
-
|
19
|
-
/**
|
20
|
-
* Checks if two values are equal. Values may be primitives, arrays, or objects.
|
21
|
-
* Returns true if both arguments have the same keys and values.
|
22
|
-
*
|
23
|
-
* @see http://underscorejs.org
|
24
|
-
* @copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
|
25
|
-
* @license MIT
|
26
|
-
*/
|
27
|
-
function areEqualArgValues(a: any, b: any): boolean {
|
28
|
-
const aStack = aStackPool.length ? aStackPool.pop() : [];
|
29
|
-
const bStack = bStackPool.length ? bStackPool.pop() : [];
|
30
|
-
const result = eq(a, b, aStack, bStack);
|
31
|
-
aStack.length = 0;
|
32
|
-
bStack.length = 0;
|
33
|
-
aStackPool.push(aStack);
|
34
|
-
bStackPool.push(bStack);
|
35
|
-
return result;
|
36
|
-
}
|
37
|
-
|
38
|
-
function eq(a: any, b: any, aStack: Array<any>, bStack: Array<any>): boolean {
|
39
|
-
if (a === b) {
|
40
|
-
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
41
|
-
return a !== 0 || 1 / a === 1 / b;
|
42
|
-
}
|
43
|
-
if (a == null || b == null) {
|
44
|
-
// a or b can be `null` or `undefined`
|
45
|
-
return false;
|
46
|
-
}
|
47
|
-
if (typeof a !== 'object' || typeof b !== 'object') {
|
48
|
-
return false;
|
49
|
-
}
|
50
|
-
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
51
|
-
const objToStr = Object.prototype.toString;
|
52
|
-
const className = objToStr.call(a);
|
53
|
-
if (className !== objToStr.call(b)) {
|
54
|
-
return false;
|
55
|
-
}
|
56
|
-
switch (className) {
|
57
|
-
case '[object String]':
|
58
|
-
return a === String(b);
|
59
|
-
case '[object Number]':
|
60
|
-
return isNaN(a) || isNaN(b) ? false : a === Number(b);
|
61
|
-
case '[object Date]':
|
62
|
-
case '[object Boolean]':
|
63
|
-
return +a === +b;
|
64
|
-
case '[object RegExp]':
|
65
|
-
return (
|
66
|
-
a.source === b.source &&
|
67
|
-
a.global === b.global &&
|
68
|
-
a.multiline === b.multiline &&
|
69
|
-
a.ignoreCase === b.ignoreCase
|
70
|
-
);
|
71
|
-
}
|
72
|
-
// Assume equality for cyclic structures.
|
73
|
-
let length = aStack.length;
|
74
|
-
while (length--) {
|
75
|
-
if (aStack[length] === a) {
|
76
|
-
return bStack[length] === b;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
aStack.push(a);
|
80
|
-
bStack.push(b);
|
81
|
-
let size = 0;
|
82
|
-
// Recursively compare objects and arrays.
|
83
|
-
if (className === '[object Array]') {
|
84
|
-
size = a.length;
|
85
|
-
if (size !== b.length) {
|
86
|
-
return false;
|
87
|
-
}
|
88
|
-
// Deep compare the contents, ignoring non-numeric properties.
|
89
|
-
while (size--) {
|
90
|
-
if (!eq(a[size], b[size], aStack, bStack)) {
|
91
|
-
return false;
|
92
|
-
}
|
93
|
-
}
|
94
|
-
} else {
|
95
|
-
if (a.constructor !== b.constructor) {
|
96
|
-
return false;
|
97
|
-
}
|
98
|
-
if (a.hasOwnProperty('valueOf') && b.hasOwnProperty('valueOf')) {
|
99
|
-
return a.valueOf() === b.valueOf();
|
100
|
-
}
|
101
|
-
const keys = Object.keys(a);
|
102
|
-
if (keys.length !== Object.keys(b).length) {
|
103
|
-
return false;
|
104
|
-
}
|
105
|
-
for (let i = 0; i < keys.length; i++) {
|
106
|
-
if (keys[i] === '_owner') {
|
107
|
-
// HACK: Comparing deeply nested React trees is slow since you end up
|
108
|
-
// comparing the entire tree (all ancestors and all children) and
|
109
|
-
// likely not what you want if you're comparing two elements with
|
110
|
-
// areEqualArgValues. We bail out here for now.
|
111
|
-
continue;
|
112
|
-
}
|
113
|
-
if (
|
114
|
-
!b.hasOwnProperty(keys[i]) ||
|
115
|
-
!eq(a[keys[i]], b[keys[i]], aStack, bStack)
|
116
|
-
) {
|
117
|
-
return false;
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
121
|
-
aStack.pop();
|
122
|
-
bStack.pop();
|
123
|
-
return true;
|
124
|
-
}
|
125
|
-
|
126
|
-
module.exports = areEqualArgValues;
|
@@ -1,38 +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
|
-
* @flow
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
import type {NormalizationArgument, ReaderArgument} from 'relay-runtime';
|
16
|
-
|
17
|
-
function argumentContainsVariables(
|
18
|
-
arg: ?(ReaderArgument | NormalizationArgument),
|
19
|
-
): boolean {
|
20
|
-
if (arg == null) {
|
21
|
-
return false;
|
22
|
-
}
|
23
|
-
switch (arg.kind) {
|
24
|
-
case 'Variable':
|
25
|
-
return true;
|
26
|
-
case 'Literal':
|
27
|
-
return false;
|
28
|
-
case 'ListValue':
|
29
|
-
return arg.items.some(argumentContainsVariables);
|
30
|
-
case 'ObjectValue':
|
31
|
-
return arg.fields.some(argumentContainsVariables);
|
32
|
-
default:
|
33
|
-
(arg.kind: empty);
|
34
|
-
return false;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
module.exports = argumentContainsVariables;
|
@@ -1,156 +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
|
-
* @flow
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
|
13
|
-
'use strict';
|
14
|
-
|
15
|
-
/**
|
16
|
-
* This function works similar to JSON.stringify except that for the case there
|
17
|
-
* are multiple common subtrees, it generates a string for a IIFE that re-uses
|
18
|
-
* the same objects for the duplicate subtrees.
|
19
|
-
*/
|
20
|
-
function dedupeJSONStringify(jsonValue: mixed): string {
|
21
|
-
const metadataForHash = new Map();
|
22
|
-
const metadataForVal = new WeakMap();
|
23
|
-
const varDefs = [];
|
24
|
-
collectMetadata(jsonValue);
|
25
|
-
collectDuplicates(jsonValue);
|
26
|
-
const code = printJSCode(false, '', jsonValue);
|
27
|
-
return varDefs.length === 0
|
28
|
-
? code
|
29
|
-
: `(function(){\nvar ${varDefs.join(',\n')};\nreturn ${code};\n})()`;
|
30
|
-
|
31
|
-
// Collect common metadata for each object in the value tree, ensuring that
|
32
|
-
// equivalent values have the *same reference* to the same metadata. Note that
|
33
|
-
// the hashes generated are not exactly JSON, but still identify equivalent
|
34
|
-
// values. Runs in linear time due to hashing in a bottom-up recursion.
|
35
|
-
function collectMetadata(value: mixed): string {
|
36
|
-
if (value == null || typeof value !== 'object') {
|
37
|
-
// $FlowFixMe[incompatible-return] - JSON.stringify can return undefined
|
38
|
-
return JSON.stringify(value);
|
39
|
-
}
|
40
|
-
let hash;
|
41
|
-
if (Array.isArray(value)) {
|
42
|
-
hash = '[';
|
43
|
-
for (let i = 0; i < value.length; i++) {
|
44
|
-
hash += collectMetadata(value[i]) + ',';
|
45
|
-
}
|
46
|
-
} else {
|
47
|
-
hash = '{';
|
48
|
-
for (const k in value) {
|
49
|
-
if (value.hasOwnProperty(k) && value[k] !== undefined) {
|
50
|
-
hash += k + ':' + collectMetadata(value[k]) + ',';
|
51
|
-
}
|
52
|
-
}
|
53
|
-
}
|
54
|
-
let metadata = metadataForHash.get(hash);
|
55
|
-
if (!metadata) {
|
56
|
-
metadata = ({value, hash, count: 0}: {|
|
57
|
-
value: mixed,
|
58
|
-
hash: string,
|
59
|
-
count: number,
|
60
|
-
varName?: string,
|
61
|
-
|});
|
62
|
-
metadataForHash.set(hash, metadata);
|
63
|
-
}
|
64
|
-
metadataForVal.set(value, metadata);
|
65
|
-
return hash;
|
66
|
-
}
|
67
|
-
|
68
|
-
// Using top-down recursion, linearly scan the JSON tree to determine which
|
69
|
-
// values should be deduplicated.
|
70
|
-
function collectDuplicates(value: mixed) {
|
71
|
-
if (value == null || typeof value !== 'object') {
|
72
|
-
return;
|
73
|
-
}
|
74
|
-
const metadata = metadataForVal.get(value);
|
75
|
-
// Only consider duplicates with hashes longer than 2 (excludes [] and {}).
|
76
|
-
if (metadata && metadata.hash.length > 2) {
|
77
|
-
metadata.count++;
|
78
|
-
if (metadata.count > 1) {
|
79
|
-
return;
|
80
|
-
}
|
81
|
-
}
|
82
|
-
if (Array.isArray(value)) {
|
83
|
-
for (let i = 0; i < value.length; i++) {
|
84
|
-
collectDuplicates(value[i]);
|
85
|
-
}
|
86
|
-
} else {
|
87
|
-
for (const k in value) {
|
88
|
-
if (value.hasOwnProperty(k) && value[k] !== undefined) {
|
89
|
-
collectDuplicates(value[k]);
|
90
|
-
}
|
91
|
-
}
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
// Stringify JS, replacing duplicates with variable references.
|
96
|
-
function printJSCode(
|
97
|
-
isDupedVar: boolean,
|
98
|
-
depth: string,
|
99
|
-
value: mixed,
|
100
|
-
): string {
|
101
|
-
if (value == null || typeof value !== 'object') {
|
102
|
-
// $FlowFixMe[incompatible-return] : JSON.stringify can return undefined
|
103
|
-
return JSON.stringify(value);
|
104
|
-
}
|
105
|
-
// Only use variable references at depth beyond the top level.
|
106
|
-
if (depth !== '') {
|
107
|
-
const metadata = metadataForVal.get(value);
|
108
|
-
if (metadata && metadata.count > 1) {
|
109
|
-
let varName = metadata.varName;
|
110
|
-
if (varName == null) {
|
111
|
-
const refCode = printJSCode(true, '', value);
|
112
|
-
varName = metadata.varName = 'v' + varDefs.length;
|
113
|
-
varDefs.push(metadata.varName + ' = ' + refCode);
|
114
|
-
}
|
115
|
-
return '(' + varName + '/*: any*/)';
|
116
|
-
}
|
117
|
-
}
|
118
|
-
let str;
|
119
|
-
let isEmpty = true;
|
120
|
-
const depth2 = depth + ' ';
|
121
|
-
if (Array.isArray(value)) {
|
122
|
-
// Empty arrays can only have one inferred flow type and then conflict if
|
123
|
-
// used in different places, this is unsound if we would write to them but
|
124
|
-
// this whole module is based on the idea of a read only JSON tree.
|
125
|
-
if (isDupedVar && value.length === 0) {
|
126
|
-
return '([]/*: any*/)';
|
127
|
-
}
|
128
|
-
str = '[';
|
129
|
-
for (let i = 0; i < value.length; i++) {
|
130
|
-
str +=
|
131
|
-
(isEmpty ? '\n' : ',\n') +
|
132
|
-
depth2 +
|
133
|
-
printJSCode(isDupedVar, depth2, value[i]);
|
134
|
-
isEmpty = false;
|
135
|
-
}
|
136
|
-
str += isEmpty ? ']' : `\n${depth}]`;
|
137
|
-
} else {
|
138
|
-
str = '{';
|
139
|
-
for (const k in value) {
|
140
|
-
if (value.hasOwnProperty(k) && value[k] !== undefined) {
|
141
|
-
str +=
|
142
|
-
(isEmpty ? '\n' : ',\n') +
|
143
|
-
depth2 +
|
144
|
-
JSON.stringify(k) +
|
145
|
-
': ' +
|
146
|
-
printJSCode(isDupedVar, depth2, value[k]);
|
147
|
-
isEmpty = false;
|
148
|
-
}
|
149
|
-
}
|
150
|
-
str += isEmpty ? '}' : `\n${depth}}`;
|
151
|
-
}
|
152
|
-
return str;
|
153
|
-
}
|
154
|
-
}
|
155
|
-
|
156
|
-
module.exports = dedupeJSONStringify;
|