relay-compiler 0.0.0-main-8ff54d69 → 0.0.0-main-38f1c96e
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,249 +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 _require = require('../core/CompilerError'),
|
18
|
-
createUserError = _require.createUserError,
|
19
|
-
eachWithCombinedError = _require.eachWithCombinedError;
|
20
|
-
|
21
|
-
var getLiteralArgumentValues = require('../core/getLiteralArgumentValues');
|
22
|
-
|
23
|
-
var inferRootArgumentDefinitions = require('../core/inferRootArgumentDefinitions');
|
24
|
-
|
25
|
-
var IRVisitor = require('../core/IRVisitor');
|
26
|
-
|
27
|
-
var _require2 = require('./query-generators'),
|
28
|
-
buildRefetchOperation = _require2.buildRefetchOperation;
|
29
|
-
|
30
|
-
var SCHEMA_EXTENSION = "\n directive @refetchable(\n queryName: String!\n ) on FRAGMENT_DEFINITION\n";
|
31
|
-
/**
|
32
|
-
* This transform synthesizes "refetch" queries for fragments that
|
33
|
-
* are trivially refetchable. This is comprised of three main stages:
|
34
|
-
*
|
35
|
-
* 1. Validating that fragments marked with @refetchable qualify for
|
36
|
-
* refetch query generation; mainly this means that the fragment
|
37
|
-
* type is able to be refetched in some canonical way.
|
38
|
-
* 2. Determining the variable definitions to use for each generated
|
39
|
-
* query. GraphQL does not have a notion of fragment-local variables
|
40
|
-
* at all, and although Relay adds this concept developers are still
|
41
|
-
* allowed to reference global variables. This necessitates a
|
42
|
-
* visiting all reachable fragments for each @refetchable fragment,
|
43
|
-
* and finding the union of all global variables expceted to be defined.
|
44
|
-
* 3. Building the refetch queries, a straightforward copying transform from
|
45
|
-
* Fragment to Root IR nodes.
|
46
|
-
*/
|
47
|
-
|
48
|
-
function refetchableFragmentTransform(context) {
|
49
|
-
var schema = context.getSchema();
|
50
|
-
var refetchOperations = buildRefetchMap(context);
|
51
|
-
var nextContext = context;
|
52
|
-
eachWithCombinedError(refetchOperations, function (_ref) {
|
53
|
-
var refetchName = _ref[0],
|
54
|
-
fragment = _ref[1];
|
55
|
-
|
56
|
-
var _buildRefetchOperatio = buildRefetchOperation(schema, fragment, refetchName),
|
57
|
-
identifierField = _buildRefetchOperatio.identifierField,
|
58
|
-
path = _buildRefetchOperatio.path,
|
59
|
-
node = _buildRefetchOperatio.node,
|
60
|
-
transformedFragment = _buildRefetchOperatio.transformedFragment;
|
61
|
-
|
62
|
-
var connectionMetadata = extractConnectionMetadata(context.getSchema(), transformedFragment);
|
63
|
-
nextContext = nextContext.replace((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedFragment), {}, {
|
64
|
-
metadata: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, transformedFragment.metadata || {}), {}, {
|
65
|
-
refetch: {
|
66
|
-
connection: connectionMetadata !== null && connectionMetadata !== void 0 ? connectionMetadata : null,
|
67
|
-
operation: refetchName,
|
68
|
-
fragmentPathInResult: path,
|
69
|
-
identifierField: identifierField
|
70
|
-
}
|
71
|
-
})
|
72
|
-
}));
|
73
|
-
nextContext = nextContext.add((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
|
74
|
-
metadata: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node.metadata || {}), {}, {
|
75
|
-
derivedFrom: transformedFragment.name,
|
76
|
-
isRefetchableQuery: true
|
77
|
-
})
|
78
|
-
}));
|
79
|
-
});
|
80
|
-
return nextContext;
|
81
|
-
}
|
82
|
-
/**
|
83
|
-
* Walk the documents of a compiler context and create a mapping of
|
84
|
-
* refetch operation names to the source fragment from which the refetch
|
85
|
-
* operation should be derived.
|
86
|
-
*/
|
87
|
-
|
88
|
-
|
89
|
-
function buildRefetchMap(context) {
|
90
|
-
var refetchOperations = new Map();
|
91
|
-
eachWithCombinedError(context.documents(), function (node) {
|
92
|
-
if (node.kind !== 'Fragment') {
|
93
|
-
return;
|
94
|
-
}
|
95
|
-
|
96
|
-
var refetchName = getRefetchQueryName(node);
|
97
|
-
|
98
|
-
if (refetchName === null) {
|
99
|
-
return;
|
100
|
-
}
|
101
|
-
|
102
|
-
var previousOperation = refetchOperations.get(refetchName);
|
103
|
-
|
104
|
-
if (previousOperation != null) {
|
105
|
-
throw createUserError("Duplicate definition for @refetchable operation '".concat(refetchName, "' from fragments '").concat(node.name, "' and '").concat(previousOperation.name, "'"), [node.loc, previousOperation.loc]);
|
106
|
-
}
|
107
|
-
|
108
|
-
refetchOperations.set(refetchName, node);
|
109
|
-
});
|
110
|
-
var transformed = inferRootArgumentDefinitions(context);
|
111
|
-
return new Map(Array.from(refetchOperations.entries(), function (_ref2) {
|
112
|
-
var name = _ref2[0],
|
113
|
-
fragment = _ref2[1];
|
114
|
-
return [name, transformed.getFragment(fragment.name)];
|
115
|
-
}));
|
116
|
-
}
|
117
|
-
/**
|
118
|
-
* Validate that any @connection usage is valid for refetching:
|
119
|
-
* - Variables are used for both the "count" and "cursor" arguments
|
120
|
-
* (after/first or before/last)
|
121
|
-
* - Exactly one connection
|
122
|
-
* - Has a stable path to the connection data
|
123
|
-
*
|
124
|
-
* Returns connection metadata to add to the transformed fragment or undefined
|
125
|
-
* if there is no connection.
|
126
|
-
*/
|
127
|
-
|
128
|
-
|
129
|
-
function extractConnectionMetadata(schema, fragment) {
|
130
|
-
var fields = [];
|
131
|
-
var connectionField = null;
|
132
|
-
var path = null;
|
133
|
-
IRVisitor.visit(fragment, {
|
134
|
-
LinkedField: {
|
135
|
-
enter: function enter(field) {
|
136
|
-
fields.push(field);
|
137
|
-
|
138
|
-
if (field.connection === true || field.handles && field.handles.some(function (handle) {
|
139
|
-
return handle.name === 'connection';
|
140
|
-
})) {
|
141
|
-
// Disallow multiple @connections
|
142
|
-
if (connectionField != null) {
|
143
|
-
throw createUserError("Invalid use of @refetchable with @connection in fragment '".concat(fragment.name, "', at most once @connection can appear in a refetchable fragment."), [field.loc]);
|
144
|
-
} // Disallow connections within plurals
|
145
|
-
|
146
|
-
|
147
|
-
var pluralOnPath = fields.find(function (pathField) {
|
148
|
-
return schema.isList(schema.getNullableType(pathField.type));
|
149
|
-
});
|
150
|
-
|
151
|
-
if (pluralOnPath) {
|
152
|
-
throw createUserError("Invalid use of @refetchable with @connection in fragment '".concat(fragment.name, "', refetchable connections cannot appear inside plural fields."), [field.loc, pluralOnPath.loc]);
|
153
|
-
}
|
154
|
-
|
155
|
-
connectionField = field;
|
156
|
-
path = fields.map(function (pathField) {
|
157
|
-
return pathField.alias;
|
158
|
-
});
|
159
|
-
}
|
160
|
-
},
|
161
|
-
leave: function leave() {
|
162
|
-
fields.pop();
|
163
|
-
}
|
164
|
-
}
|
165
|
-
});
|
166
|
-
|
167
|
-
if (connectionField == null || path == null) {
|
168
|
-
return;
|
169
|
-
} // Validate arguments: if either of before/last appear they must both appear
|
170
|
-
// and use variables (not scalar values)
|
171
|
-
|
172
|
-
|
173
|
-
var backward = null;
|
174
|
-
var before = findArgument(connectionField, 'before');
|
175
|
-
var last = findArgument(connectionField, 'last');
|
176
|
-
|
177
|
-
if (before || last) {
|
178
|
-
if (!before || !last || before.value.kind !== 'Variable' || last.value.kind !== 'Variable') {
|
179
|
-
throw createUserError("Invalid use of @refetchable with @connection in fragment '".concat(fragment.name, "', refetchable connections must use variables for the before and last arguments."), [connectionField.loc, before && before.value.kind !== 'Variable' ? before.value.loc : null, last && last.value.kind !== 'Variable' ? last.value.loc : null].filter(Boolean));
|
180
|
-
}
|
181
|
-
|
182
|
-
backward = {
|
183
|
-
count: last.value.variableName,
|
184
|
-
cursor: before.value.variableName
|
185
|
-
};
|
186
|
-
} // Validate arguments: if either of after/first appear they must both appear
|
187
|
-
// and use variables (not scalar values)
|
188
|
-
|
189
|
-
|
190
|
-
var forward = null;
|
191
|
-
var after = findArgument(connectionField, 'after');
|
192
|
-
var first = findArgument(connectionField, 'first');
|
193
|
-
|
194
|
-
if (after || first) {
|
195
|
-
if (!after || !first || after.value.kind !== 'Variable' || first.value.kind !== 'Variable') {
|
196
|
-
throw createUserError("Invalid use of @refetchable with @connection in fragment '".concat(fragment.name, "', refetchable connections must use variables for the after and first arguments."), [connectionField.loc, after && after.value.kind !== 'Variable' ? after.value.loc : null, first && first.value.kind !== 'Variable' ? first.value.loc : null].filter(Boolean));
|
197
|
-
}
|
198
|
-
|
199
|
-
forward = {
|
200
|
-
count: first.value.variableName,
|
201
|
-
cursor: after.value.variableName
|
202
|
-
};
|
203
|
-
}
|
204
|
-
|
205
|
-
return {
|
206
|
-
forward: forward,
|
207
|
-
backward: backward,
|
208
|
-
path: path
|
209
|
-
};
|
210
|
-
}
|
211
|
-
|
212
|
-
function getRefetchQueryName(fragment) {
|
213
|
-
var refetchableDirective = fragment.directives.find(function (directive) {
|
214
|
-
return directive.name === 'refetchable';
|
215
|
-
});
|
216
|
-
|
217
|
-
if (refetchableDirective == null) {
|
218
|
-
return null;
|
219
|
-
}
|
220
|
-
|
221
|
-
var refetchArguments = getLiteralArgumentValues(refetchableDirective.args);
|
222
|
-
var queryName = refetchArguments.queryName;
|
223
|
-
|
224
|
-
if (queryName == null) {
|
225
|
-
throw createUserError("Expected the 'queryName' argument of @refetchable to be provided", [refetchableDirective.loc]);
|
226
|
-
} else if (typeof queryName !== 'string') {
|
227
|
-
var _queryNameArg$loc;
|
228
|
-
|
229
|
-
var queryNameArg = refetchableDirective.args.find(function (arg) {
|
230
|
-
return arg.name === 'queryName';
|
231
|
-
});
|
232
|
-
throw createUserError("Expected the 'queryName' argument of @refetchable to be a string, got '".concat(String(queryName), "'."), [(_queryNameArg$loc = queryNameArg === null || queryNameArg === void 0 ? void 0 : queryNameArg.loc) !== null && _queryNameArg$loc !== void 0 ? _queryNameArg$loc : refetchableDirective.loc]);
|
233
|
-
}
|
234
|
-
|
235
|
-
return queryName;
|
236
|
-
}
|
237
|
-
|
238
|
-
function findArgument(field, argumentName) {
|
239
|
-
var _field$args$find;
|
240
|
-
|
241
|
-
return (_field$args$find = field.args.find(function (arg) {
|
242
|
-
return arg.name === argumentName;
|
243
|
-
})) !== null && _field$args$find !== void 0 ? _field$args$find : null;
|
244
|
-
}
|
245
|
-
|
246
|
-
module.exports = {
|
247
|
-
SCHEMA_EXTENSION: SCHEMA_EXTENSION,
|
248
|
-
transform: refetchableFragmentTransform
|
249
|
-
};
|
@@ -1,83 +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 getLiteralArgumentValues = require('../core/getLiteralArgumentValues');
|
18
|
-
|
19
|
-
var IRTransformer = require('../core/IRTransformer');
|
20
|
-
|
21
|
-
var invariant = require('invariant');
|
22
|
-
|
23
|
-
var RELAY = 'relay';
|
24
|
-
var SCHEMA_EXTENSION = "\ndirective @relay(\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) on FRAGMENT_DEFINITION | FRAGMENT_SPREAD\n";
|
25
|
-
/**
|
26
|
-
* A transform that extracts `@relay(plural: Boolean)` directives and converts
|
27
|
-
* them to metadata that can be accessed at runtime.
|
28
|
-
*/
|
29
|
-
|
30
|
-
function relayDirectiveTransform(context) {
|
31
|
-
return IRTransformer.transform(context, {
|
32
|
-
Fragment: visitRelayMetadata(fragmentMetadata),
|
33
|
-
FragmentSpread: visitRelayMetadata(fragmentSpreadMetadata)
|
34
|
-
});
|
35
|
-
}
|
36
|
-
|
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
|
-
|
44
|
-
if (!relayDirective) {
|
45
|
-
return this.traverse(node);
|
46
|
-
}
|
47
|
-
|
48
|
-
var argValues = getLiteralArgumentValues(relayDirective.args);
|
49
|
-
var metadata = metadataFn(argValues);
|
50
|
-
return this.traverse((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
|
51
|
-
directives: node.directives.filter(function (directive) {
|
52
|
-
return directive !== relayDirective;
|
53
|
-
}),
|
54
|
-
// $FlowFixMe[cannot-spread-indexer]
|
55
|
-
metadata: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node.metadata || {}), metadata)
|
56
|
-
}));
|
57
|
-
};
|
58
|
-
}
|
59
|
-
|
60
|
-
function fragmentMetadata(_ref2) {
|
61
|
-
var mask = _ref2.mask,
|
62
|
-
plural = _ref2.plural;
|
63
|
-
!(plural === undefined || typeof plural === 'boolean') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayDirectiveTransform: Expected the "plural" argument to @relay ' + 'to be a boolean literal if specified.') : invariant(false) : void 0;
|
64
|
-
!(mask === undefined || typeof mask === 'boolean') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayDirectiveTransform: Expected the "mask" argument to @relay ' + 'to be a boolean literal if specified.') : invariant(false) : void 0;
|
65
|
-
return {
|
66
|
-
mask: mask,
|
67
|
-
plural: plural
|
68
|
-
};
|
69
|
-
}
|
70
|
-
|
71
|
-
function fragmentSpreadMetadata(_ref3) {
|
72
|
-
var mask = _ref3.mask;
|
73
|
-
!(mask === undefined || typeof mask === 'boolean') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayDirectiveTransform: Expected the "mask" argument to @relay ' + 'to be a boolean literal if specified.') : invariant(false) : void 0;
|
74
|
-
return {
|
75
|
-
mask: mask
|
76
|
-
};
|
77
|
-
}
|
78
|
-
|
79
|
-
module.exports = {
|
80
|
-
RELAY: RELAY,
|
81
|
-
SCHEMA_EXTENSION: SCHEMA_EXTENSION,
|
82
|
-
transform: relayDirectiveTransform
|
83
|
-
};
|
@@ -1,369 +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 _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
16
|
-
|
17
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
18
|
-
|
19
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
20
|
-
|
21
|
-
var _require = require('../core/CompilerError'),
|
22
|
-
createCompilerError = _require.createCompilerError,
|
23
|
-
createUserError = _require.createUserError;
|
24
|
-
|
25
|
-
var IRTransformer = require('../core/IRTransformer');
|
26
|
-
|
27
|
-
var partitionArray = require('../util/partitionArray');
|
28
|
-
|
29
|
-
var _require2 = require('relay-runtime'),
|
30
|
-
RelayFeatureFlags = _require2.RelayFeatureFlags;
|
31
|
-
|
32
|
-
var SCHEMA_EXTENSION = "\n enum RequiredFieldAction {\n NONE\n LOG\n THROW\n }\n directive @required(\n action: RequiredFieldAction!\n ) on FIELD\n";
|
33
|
-
/**
|
34
|
-
* This transform rewrites ScalarField and LinkedField nodes with a @required
|
35
|
-
* directive into fields with the directives stripped and sets the `required`
|
36
|
-
* and `path` metadata values.
|
37
|
-
*/
|
38
|
-
|
39
|
-
function requiredFieldTransform(context) {
|
40
|
-
var schema = context.getSchema();
|
41
|
-
return IRTransformer.transform(context, {
|
42
|
-
LinkedField: visitLinkedField,
|
43
|
-
ScalarField: vistitScalarField,
|
44
|
-
InlineFragment: visitInlineFragment,
|
45
|
-
Fragment: visitFragment,
|
46
|
-
Root: visitRoot
|
47
|
-
}, function (node) {
|
48
|
-
return {
|
49
|
-
schema: schema,
|
50
|
-
documentName: node.name,
|
51
|
-
path: [],
|
52
|
-
pathRequiredMap: new Map(),
|
53
|
-
currentNodeRequiredChildren: new Map(),
|
54
|
-
requiredChildrenMap: new Map(),
|
55
|
-
parentAbstractInlineFragment: null
|
56
|
-
};
|
57
|
-
});
|
58
|
-
}
|
59
|
-
|
60
|
-
function visitFragment(fragment, state) {
|
61
|
-
return addChildrenCanBubbleMetadata(this.traverse(fragment, state), state);
|
62
|
-
}
|
63
|
-
|
64
|
-
function visitRoot(root, state) {
|
65
|
-
return addChildrenCanBubbleMetadata(this.traverse(root, state), state);
|
66
|
-
}
|
67
|
-
|
68
|
-
function visitInlineFragment(fragment, state) {
|
69
|
-
var _state$parentAbstract;
|
70
|
-
|
71
|
-
// Ideally we could allow @required when the direct parent inline fragment was
|
72
|
-
// on a concrete type, but we would need to solve this bug in our Flow type
|
73
|
-
// generation first: T65695438
|
74
|
-
var parentAbstractInlineFragment = (_state$parentAbstract = state.parentAbstractInlineFragment) !== null && _state$parentAbstract !== void 0 ? _state$parentAbstract : getAbstractInlineFragment(fragment, state.schema);
|
75
|
-
return this.traverse(fragment, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
|
76
|
-
parentAbstractInlineFragment: parentAbstractInlineFragment
|
77
|
-
}));
|
78
|
-
}
|
79
|
-
|
80
|
-
function getAbstractInlineFragment(fragment, schema) {
|
81
|
-
var typeCondition = fragment.typeCondition;
|
82
|
-
|
83
|
-
if (schema.isAbstractType(typeCondition)) {
|
84
|
-
return fragment;
|
85
|
-
}
|
86
|
-
|
87
|
-
return null;
|
88
|
-
} // Convert action to a number so that we can numerically compare their severity.
|
89
|
-
|
90
|
-
|
91
|
-
function getActionSeverity(action) {
|
92
|
-
switch (action) {
|
93
|
-
case 'NONE':
|
94
|
-
return 0;
|
95
|
-
|
96
|
-
case 'LOG':
|
97
|
-
return 1;
|
98
|
-
|
99
|
-
case 'THROW':
|
100
|
-
return 2;
|
101
|
-
|
102
|
-
default:
|
103
|
-
action;
|
104
|
-
throw createCompilerError("Unhandled action type ".concat(action));
|
105
|
-
}
|
106
|
-
}
|
107
|
-
|
108
|
-
function visitLinkedField(field, state) {
|
109
|
-
var path = [].concat((0, _toConsumableArray2["default"])(state.path), [field.alias]);
|
110
|
-
var newState = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, state), {}, {
|
111
|
-
currentNodeRequiredChildren: new Map(),
|
112
|
-
path: path,
|
113
|
-
parentAbstractInlineFragment: null
|
114
|
-
});
|
115
|
-
var newField = this.traverse(field, newState);
|
116
|
-
var pathName = path.join('.');
|
117
|
-
assertCompatibleRequiredChildren(field, pathName, newState);
|
118
|
-
newField = applyDirectives(newField, pathName, state.documentName);
|
119
|
-
assertCompatibleNullability(newField, pathName, newState.pathRequiredMap);
|
120
|
-
var directiveMetadata = getRequiredDirectiveMetadata(newField);
|
121
|
-
|
122
|
-
if (directiveMetadata != null) {
|
123
|
-
assertParentIsNotInvalidInlineFragmet(state.schema, directiveMetadata, state.parentAbstractInlineFragment);
|
124
|
-
state.currentNodeRequiredChildren.set(field.alias, newField);
|
125
|
-
var severity = getActionSeverity(directiveMetadata.action); // Assert that all @required children have at least this severity.
|
126
|
-
|
127
|
-
newState.currentNodeRequiredChildren.forEach(function (childField) {
|
128
|
-
var childMetadata = getRequiredDirectiveMetadata(childField);
|
129
|
-
|
130
|
-
if (childMetadata == null) {
|
131
|
-
return;
|
132
|
-
}
|
133
|
-
|
134
|
-
if (getActionSeverity(childMetadata.action) < severity) {
|
135
|
-
throw createUserError("The @required field [1] may not have an `action` less severe than that of its @required parent [2]. [1] should probably be `action: ".concat(directiveMetadata.action, "`."), [childMetadata.actionLoc, directiveMetadata.actionLoc]);
|
136
|
-
}
|
137
|
-
});
|
138
|
-
}
|
139
|
-
|
140
|
-
state.requiredChildrenMap.set(pathName, newState.currentNodeRequiredChildren);
|
141
|
-
return addChildrenCanBubbleMetadata(newField, newState);
|
142
|
-
}
|
143
|
-
|
144
|
-
function vistitScalarField(field, state) {
|
145
|
-
var pathName = [].concat((0, _toConsumableArray2["default"])(state.path), [field.alias]).join('.');
|
146
|
-
var newField = applyDirectives(field, pathName, state.documentName);
|
147
|
-
var directiveMetadata = getRequiredDirectiveMetadata(newField);
|
148
|
-
|
149
|
-
if (directiveMetadata != null) {
|
150
|
-
assertParentIsNotInvalidInlineFragmet(state.schema, directiveMetadata, state.parentAbstractInlineFragment);
|
151
|
-
state.currentNodeRequiredChildren.set(field.alias, newField);
|
152
|
-
}
|
153
|
-
|
154
|
-
assertCompatibleNullability(newField, pathName, state.pathRequiredMap);
|
155
|
-
return newField;
|
156
|
-
}
|
157
|
-
|
158
|
-
function addChildrenCanBubbleMetadata(node, state) {
|
159
|
-
var _iterator = (0, _createForOfIteratorHelper2["default"])(state.currentNodeRequiredChildren.values()),
|
160
|
-
_step;
|
161
|
-
|
162
|
-
try {
|
163
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
164
|
-
var child = _step.value;
|
165
|
-
var requiredMetadata = getRequiredDirectiveMetadata(child);
|
166
|
-
|
167
|
-
if (requiredMetadata != null && requiredMetadata.action !== 'THROW') {
|
168
|
-
var metadata = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node.metadata), {}, {
|
169
|
-
childrenCanBubbleNull: true
|
170
|
-
});
|
171
|
-
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
|
172
|
-
metadata: metadata
|
173
|
-
});
|
174
|
-
}
|
175
|
-
}
|
176
|
-
} catch (err) {
|
177
|
-
_iterator.e(err);
|
178
|
-
} finally {
|
179
|
-
_iterator.f();
|
180
|
-
}
|
181
|
-
|
182
|
-
return node;
|
183
|
-
}
|
184
|
-
|
185
|
-
function assertParentIsNotInvalidInlineFragmet(schema, directiveMetadata, parentAbstractInlineFragment) {
|
186
|
-
if (parentAbstractInlineFragment == null) {
|
187
|
-
return;
|
188
|
-
}
|
189
|
-
|
190
|
-
var typeCondition = parentAbstractInlineFragment.typeCondition;
|
191
|
-
|
192
|
-
if (schema.isUnion(typeCondition)) {
|
193
|
-
throw createUserError('The @required directive [1] may not be used anywhere within an inline fragment on a union type [2].', [directiveMetadata.directiveLoc, parentAbstractInlineFragment.loc]);
|
194
|
-
} else if (schema.isInterface(typeCondition)) {
|
195
|
-
throw createUserError('The @required directive [1] may not be used anywhere within an inline fragment on an interface type [2].', [directiveMetadata.directiveLoc, parentAbstractInlineFragment.loc]);
|
196
|
-
} else {
|
197
|
-
throw createCompilerError('Unexpected abstract inline fragment type.', [parentAbstractInlineFragment.loc]);
|
198
|
-
}
|
199
|
-
} // Check that this field's nullability matches all other instances.
|
200
|
-
|
201
|
-
|
202
|
-
function assertCompatibleNullability(field, pathName, pathRequiredMap) {
|
203
|
-
var existingField = pathRequiredMap.get(pathName);
|
204
|
-
|
205
|
-
if (existingField == null) {
|
206
|
-
pathRequiredMap.set(pathName, field);
|
207
|
-
return;
|
208
|
-
}
|
209
|
-
|
210
|
-
var requiredMetadata = getRequiredDirectiveMetadata(field);
|
211
|
-
var existingRequiredMetadata = getRequiredDirectiveMetadata(existingField);
|
212
|
-
|
213
|
-
if ((requiredMetadata === null || requiredMetadata === void 0 ? void 0 : requiredMetadata.action) === (existingRequiredMetadata === null || existingRequiredMetadata === void 0 ? void 0 : existingRequiredMetadata.action)) {
|
214
|
-
return;
|
215
|
-
}
|
216
|
-
|
217
|
-
if (requiredMetadata == null) {
|
218
|
-
throw createUserError("The field \"".concat(field.alias, "\" is @required in [1] but not in [2]."), [existingField.loc, field.loc]);
|
219
|
-
}
|
220
|
-
|
221
|
-
if (existingRequiredMetadata == null) {
|
222
|
-
throw createUserError("The field \"".concat(field.alias, "\" is @required in [1] but not in [2]."), [field.loc, existingField.loc]);
|
223
|
-
}
|
224
|
-
|
225
|
-
throw createUserError("The field \"".concat(field.alias, "\" has a different @required action in [1] than in [2]."), [requiredMetadata.actionLoc, existingRequiredMetadata.actionLoc]);
|
226
|
-
} // Metadata is untyped, so we use this utility function to do the type coersion.
|
227
|
-
|
228
|
-
|
229
|
-
function getRequiredDirectiveMetadata(field) {
|
230
|
-
var _field$metadata;
|
231
|
-
|
232
|
-
return (_field$metadata = field.metadata) === null || _field$metadata === void 0 ? void 0 : _field$metadata.required;
|
233
|
-
} // Check that this field has the same required children as all other instances.
|
234
|
-
|
235
|
-
|
236
|
-
function assertCompatibleRequiredChildren(field, fieldPath, _ref) {
|
237
|
-
var currentNodeRequiredChildren = _ref.currentNodeRequiredChildren,
|
238
|
-
pathRequiredMap = _ref.pathRequiredMap,
|
239
|
-
requiredChildrenMap = _ref.requiredChildrenMap;
|
240
|
-
var previouslyRequiredChildren = requiredChildrenMap.get(fieldPath);
|
241
|
-
|
242
|
-
if (previouslyRequiredChildren == null) {
|
243
|
-
return;
|
244
|
-
} // Check if this field has a required child field which was previously omitted.
|
245
|
-
|
246
|
-
|
247
|
-
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(currentNodeRequiredChildren),
|
248
|
-
_step2;
|
249
|
-
|
250
|
-
try {
|
251
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
252
|
-
var _step2$value = _step2.value,
|
253
|
-
path = _step2$value[0],
|
254
|
-
childField = _step2$value[1];
|
255
|
-
|
256
|
-
if (!previouslyRequiredChildren.has(path)) {
|
257
|
-
var otherParent = pathRequiredMap.get(fieldPath);
|
258
|
-
|
259
|
-
if (otherParent == null) {
|
260
|
-
throw createCompilerError("Could not find other parent node at path \"".concat(fieldPath, "\"."), [childField.loc]);
|
261
|
-
}
|
262
|
-
|
263
|
-
throw createMissingRequiredFieldError(childField, otherParent);
|
264
|
-
}
|
265
|
-
} // Check if a previous reference to this field had a required child field which we are missing.
|
266
|
-
|
267
|
-
} catch (err) {
|
268
|
-
_iterator2.e(err);
|
269
|
-
} finally {
|
270
|
-
_iterator2.f();
|
271
|
-
}
|
272
|
-
|
273
|
-
var _iterator3 = (0, _createForOfIteratorHelper2["default"])(previouslyRequiredChildren),
|
274
|
-
_step3;
|
275
|
-
|
276
|
-
try {
|
277
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
278
|
-
var _step3$value = _step3.value,
|
279
|
-
_path = _step3$value[0],
|
280
|
-
_childField = _step3$value[1];
|
281
|
-
|
282
|
-
if (!currentNodeRequiredChildren.has(_path)) {
|
283
|
-
throw createMissingRequiredFieldError(_childField, field);
|
284
|
-
}
|
285
|
-
}
|
286
|
-
} catch (err) {
|
287
|
-
_iterator3.e(err);
|
288
|
-
} finally {
|
289
|
-
_iterator3.f();
|
290
|
-
}
|
291
|
-
}
|
292
|
-
|
293
|
-
function createMissingRequiredFieldError(requiredChild, missingParent) {
|
294
|
-
var alias = requiredChild.alias;
|
295
|
-
return createUserError("The field \"".concat(alias, "\" is marked as @required in [1] but is missing in [2]."), [requiredChild.loc, missingParent.loc]);
|
296
|
-
} // TODO T74397896: Remove prefix gating once @required is rolled out more broadly.
|
297
|
-
|
298
|
-
|
299
|
-
function featureIsEnabled(documentName) {
|
300
|
-
var featureFlag = RelayFeatureFlags.ENABLE_REQUIRED_DIRECTIVES;
|
301
|
-
|
302
|
-
if (typeof featureFlag === 'boolean') {
|
303
|
-
return featureFlag;
|
304
|
-
} else if (featureFlag === 'LIMITED') {
|
305
|
-
return documentName.startsWith('RelayRequiredTest');
|
306
|
-
} else if (typeof featureFlag === 'string') {
|
307
|
-
return featureFlag.split('|').some(function (prefix) {
|
308
|
-
return documentName.startsWith(prefix);
|
309
|
-
});
|
310
|
-
}
|
311
|
-
|
312
|
-
return false;
|
313
|
-
} // Strip and validate @required directives, and convert them to metadata.
|
314
|
-
|
315
|
-
|
316
|
-
function applyDirectives(field, pathName, documentName) {
|
317
|
-
var _partitionArray = partitionArray(field.directives, function (directive) {
|
318
|
-
return directive.name === 'required';
|
319
|
-
}),
|
320
|
-
requiredDirectives = _partitionArray[0],
|
321
|
-
otherDirectives = _partitionArray[1];
|
322
|
-
|
323
|
-
if (requiredDirectives.length === 0) {
|
324
|
-
return field;
|
325
|
-
}
|
326
|
-
|
327
|
-
if (!featureIsEnabled(documentName)) {
|
328
|
-
throw new createUserError( // Purposefully don't include details in this error message, since we
|
329
|
-
// don't want folks adopting this feature until it's been tested more.
|
330
|
-
'The @required directive is experimental and not yet supported for use in product code', requiredDirectives.map(function (x) {
|
331
|
-
return x.loc;
|
332
|
-
}));
|
333
|
-
}
|
334
|
-
|
335
|
-
if (requiredDirectives.length > 1) {
|
336
|
-
throw new createUserError('Did not expect multiple @required directives.', requiredDirectives.map(function (x) {
|
337
|
-
return x.loc;
|
338
|
-
}));
|
339
|
-
}
|
340
|
-
|
341
|
-
var requiredDirective = requiredDirectives[0];
|
342
|
-
var arg = requiredDirective.args[0]; // I would expect this check to be handled by the schema validation, but...
|
343
|
-
|
344
|
-
if (arg == null) {
|
345
|
-
throw createUserError('The @required directive requires an `action` argument.', [requiredDirective.loc]);
|
346
|
-
}
|
347
|
-
|
348
|
-
if (arg.value.kind !== 'Literal') {
|
349
|
-
throw createUserError('Expected @required `action` argument to be a literal.', [arg.value.loc]);
|
350
|
-
}
|
351
|
-
|
352
|
-
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, field), {}, {
|
353
|
-
directives: otherDirectives,
|
354
|
-
metadata: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, field.metadata), {}, {
|
355
|
-
required: {
|
356
|
-
action: arg.value.value,
|
357
|
-
actionLoc: arg.loc,
|
358
|
-
directiveLoc: requiredDirective.loc,
|
359
|
-
path: pathName
|
360
|
-
}
|
361
|
-
})
|
362
|
-
});
|
363
|
-
} // Transform @required directive to metadata
|
364
|
-
|
365
|
-
|
366
|
-
module.exports = {
|
367
|
-
SCHEMA_EXTENSION: SCHEMA_EXTENSION,
|
368
|
-
transform: requiredFieldTransform
|
369
|
-
};
|