relay-compiler 8.0.0 → 10.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/RelayCompilerBin.js.flow +169 -0
- package/bin/RelayCompilerMain.js.flow +515 -0
- package/bin/__fixtures__/plugin-module.js.flow +17 -0
- package/bin/relay-compiler +8930 -8967
- package/codegen/CodegenDirectory.js.flow +375 -0
- package/codegen/CodegenRunner.js.flow +432 -0
- package/codegen/CodegenTypes.js.flow +28 -0
- package/codegen/CodegenWatcher.js.flow +254 -0
- package/codegen/NormalizationCodeGenerator.js.flow +563 -0
- package/codegen/ReaderCodeGenerator.js.flow +477 -0
- package/codegen/RelayCodeGenerator.js.flow +85 -0
- package/codegen/RelayFileWriter.js.flow +365 -0
- package/codegen/SourceControl.js.flow +58 -0
- package/codegen/compileRelayArtifacts.js.flow +182 -0
- package/codegen/createPrintRequireModuleDependency.js.flow +21 -0
- package/codegen/sortObjectByKey.js.flow +25 -0
- package/codegen/writeRelayGeneratedFile.js.flow +223 -0
- package/core/ASTCache.js.flow +73 -0
- package/core/ASTConvert.js.flow +233 -0
- package/core/CompilerContext.js.flow +190 -0
- package/core/CompilerError.js.flow +250 -0
- package/core/DotGraphQLParser.js.flow +39 -0
- package/core/GraphQLCompilerProfiler.js.flow +341 -0
- package/core/GraphQLDerivedFromMetadata.js.flow +36 -0
- package/core/GraphQLWatchmanClient.js.flow +111 -0
- package/core/IR.js.flow +327 -0
- package/core/IRPrinter.js.flow +482 -0
- package/core/IRTransformer.js.flow +377 -0
- package/core/IRValidator.js.flow +260 -0
- package/core/IRVisitor.js.flow +150 -0
- package/core/JSModuleParser.js.flow +24 -0
- package/core/RelayCompilerScope.js.flow +199 -0
- package/core/RelayFindGraphQLTags.js.flow +119 -0
- package/core/RelayGraphQLEnumsGenerator.js.flow +55 -0
- package/core/RelayIRTransforms.js.flow +131 -0
- package/core/RelayParser.js.flow +1731 -0
- package/core/RelaySourceModuleParser.js.flow +135 -0
- package/core/Schema.js.flow +1983 -0
- package/core/SchemaUtils.js.flow +120 -0
- package/core/filterContextForNode.js.flow +50 -0
- package/core/getFieldDefinition.js.flow +156 -0
- package/core/getIdentifierForArgumentValue.js.flow +49 -0
- package/core/getIdentifierForSelection.js.flow +69 -0
- package/core/getLiteralArgumentValues.js.flow +32 -0
- package/core/getNormalizationOperationName.js.flow +19 -0
- package/core/inferRootArgumentDefinitions.js.flow +323 -0
- package/index.js +1 -1
- package/index.js.flow +200 -0
- package/language/RelayLanguagePluginInterface.js.flow +283 -0
- package/language/javascript/FindGraphQLTags.js.flow +232 -0
- package/language/javascript/RelayFlowBabelFactories.js.flow +180 -0
- package/language/javascript/RelayFlowGenerator.js.flow +1042 -0
- package/language/javascript/RelayFlowTypeTransformers.js.flow +184 -0
- package/language/javascript/RelayLanguagePluginJavaScript.js.flow +34 -0
- package/language/javascript/formatGeneratedModule.js.flow +65 -0
- package/lib/bin/RelayCompilerBin.js +24 -7
- package/lib/bin/RelayCompilerMain.js +141 -136
- package/lib/codegen/CodegenDirectory.js +13 -8
- package/lib/codegen/CodegenRunner.js +37 -76
- package/lib/codegen/CodegenWatcher.js +13 -21
- package/lib/codegen/NormalizationCodeGenerator.js +117 -140
- package/lib/codegen/ReaderCodeGenerator.js +76 -117
- package/lib/codegen/RelayCodeGenerator.js +17 -6
- package/lib/codegen/RelayFileWriter.js +19 -40
- package/lib/codegen/compileRelayArtifacts.js +16 -30
- package/lib/codegen/sortObjectByKey.js +43 -0
- package/lib/codegen/writeRelayGeneratedFile.js +86 -95
- package/lib/core/ASTCache.js +2 -4
- package/lib/core/CompilerContext.js +2 -4
- package/lib/core/CompilerError.js +27 -54
- package/lib/core/GraphQLCompilerProfiler.js +8 -12
- package/lib/core/GraphQLDerivedFromMetadata.js +1 -10
- package/lib/core/GraphQLWatchmanClient.js +4 -12
- package/lib/core/IRPrinter.js +23 -21
- package/lib/core/IRTransformer.js +8 -16
- package/lib/core/IRValidator.js +1 -9
- package/lib/core/IRVisitor.js +0 -2
- package/lib/core/RelayCompilerScope.js +4 -4
- package/lib/core/RelayGraphQLEnumsGenerator.js +12 -15
- package/lib/core/RelayIRTransforms.js +16 -14
- package/lib/core/RelayParser.js +53 -89
- package/lib/core/RelaySourceModuleParser.js +3 -3
- package/lib/core/Schema.js +61 -73
- package/lib/core/SchemaUtils.js +15 -1
- package/lib/core/getFieldDefinition.js +12 -15
- package/lib/core/getIdentifierForSelection.js +2 -4
- package/lib/core/inferRootArgumentDefinitions.js +33 -73
- package/lib/index.js +4 -5
- package/lib/language/javascript/FindGraphQLTags.js +4 -3
- package/lib/language/javascript/RelayFlowGenerator.js +82 -171
- package/lib/language/javascript/RelayFlowTypeTransformers.js +1 -3
- package/lib/language/javascript/RelayLanguagePluginJavaScript.js +6 -4
- package/lib/language/javascript/formatGeneratedModule.js +11 -2
- package/lib/reporters/ConsoleReporter.js +1 -3
- package/lib/reporters/MultiReporter.js +1 -3
- package/lib/runner/Artifacts.js +69 -170
- package/lib/runner/BufferedFilesystem.js +32 -66
- package/lib/runner/GraphQLASTNodeGroup.js +54 -120
- package/lib/runner/GraphQLNodeMap.js +14 -19
- package/lib/runner/Sources.js +51 -85
- package/lib/runner/StrictMap.js +21 -37
- package/lib/runner/getChangedNodeNames.js +30 -62
- package/lib/transforms/ApplyFragmentArgumentTransform.js +73 -59
- package/lib/transforms/ClientExtensionsTransform.js +12 -16
- package/lib/transforms/ConnectionTransform.js +30 -37
- package/lib/transforms/DeclarativeConnectionMutationTransform.js +167 -0
- package/lib/transforms/DeferStreamTransform.js +30 -73
- package/lib/transforms/DisallowTypenameOnRoot.js +55 -0
- package/lib/transforms/FieldHandleTransform.js +6 -2
- package/lib/transforms/FlattenTransform.js +18 -45
- package/lib/transforms/GenerateIDFieldTransform.js +56 -35
- package/lib/transforms/GenerateTypeNameTransform.js +84 -10
- package/lib/transforms/InlineDataFragmentTransform.js +9 -4
- package/lib/transforms/MaskTransform.js +17 -17
- package/lib/transforms/MatchTransform.js +110 -32
- package/lib/transforms/RefetchableFragmentTransform.js +21 -38
- package/lib/transforms/RelayDirectiveTransform.js +8 -3
- package/lib/transforms/SkipClientExtensionsTransform.js +8 -0
- package/lib/transforms/SkipHandleFieldTransform.js +6 -2
- package/lib/transforms/SkipRedundantNodesTransform.js +7 -4
- package/lib/transforms/SkipSplitOperationTransform.js +32 -0
- package/lib/transforms/SkipUnreachableNodeTransform.js +9 -10
- package/lib/transforms/SkipUnusedVariablesTransform.js +18 -17
- package/lib/transforms/SplitModuleImportTransform.js +2 -2
- package/lib/transforms/TestOperationTransform.js +26 -22
- package/lib/transforms/ValidateGlobalVariablesTransform.js +18 -30
- package/lib/transforms/ValidateRequiredArgumentsTransform.js +12 -16
- package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +16 -30
- package/lib/transforms/ValidateUnusedVariablesTransform.js +18 -30
- package/lib/transforms/query-generators/FetchableQueryGenerator.js +161 -0
- package/lib/transforms/query-generators/NodeQueryGenerator.js +22 -3
- package/lib/transforms/query-generators/QueryQueryGenerator.js +2 -1
- package/lib/transforms/query-generators/ViewerQueryGenerator.js +1 -0
- package/lib/transforms/query-generators/index.js +23 -6
- package/lib/transforms/query-generators/utils.js +17 -16
- package/lib/util/RelayCompilerCache.js +2 -4
- package/lib/util/argumentContainsVariables.js +37 -0
- package/lib/util/dedupeJSONStringify.js +15 -12
- package/lib/util/generateAbstractTypeRefinementKey.js +24 -0
- package/lib/util/getModuleName.js +3 -5
- package/lib/util/joinArgumentDefinitions.js +3 -1
- package/package.json +6 -6
- package/relay-compiler.js +4 -4
- package/relay-compiler.min.js +4 -4
- package/reporters/ConsoleReporter.js.flow +81 -0
- package/reporters/MultiReporter.js.flow +43 -0
- package/reporters/Reporter.js.flow +19 -0
- package/runner/Artifacts.js.flow +219 -0
- package/runner/BufferedFilesystem.js.flow +194 -0
- package/runner/GraphQLASTNodeGroup.js.flow +176 -0
- package/runner/GraphQLASTUtils.js.flow +26 -0
- package/runner/GraphQLNodeMap.js.flow +55 -0
- package/runner/Sources.js.flow +214 -0
- package/runner/StrictMap.js.flow +96 -0
- package/runner/compileArtifacts.js.flow +76 -0
- package/runner/extractAST.js.flow +100 -0
- package/runner/getChangedNodeNames.js.flow +48 -0
- package/runner/getSchemaInstance.js.flow +36 -0
- package/runner/types.js.flow +37 -0
- package/transforms/ApplyFragmentArgumentTransform.js.flow +526 -0
- package/transforms/ClientExtensionsTransform.js.flow +222 -0
- package/transforms/ConnectionTransform.js.flow +856 -0
- package/transforms/DeclarativeConnectionMutationTransform.js.flow +157 -0
- package/transforms/DeferStreamTransform.js.flow +265 -0
- package/transforms/DisallowIdAsAlias.js.flow +47 -0
- package/transforms/DisallowTypenameOnRoot.js.flow +45 -0
- package/transforms/FieldHandleTransform.js.flow +80 -0
- package/transforms/FilterDirectivesTransform.js.flow +45 -0
- package/transforms/FlattenTransform.js.flow +453 -0
- package/transforms/GenerateIDFieldTransform.js.flow +152 -0
- package/transforms/GenerateTypeNameTransform.js.flow +161 -0
- package/transforms/InlineDataFragmentTransform.js.flow +125 -0
- package/transforms/InlineFragmentsTransform.js.flow +71 -0
- package/transforms/MaskTransform.js.flow +126 -0
- package/transforms/MatchTransform.js.flow +583 -0
- package/transforms/RefetchableFragmentTransform.js.flow +272 -0
- package/transforms/RelayDirectiveTransform.js.flow +97 -0
- package/transforms/SkipClientExtensionsTransform.js.flow +54 -0
- package/transforms/SkipHandleFieldTransform.js.flow +44 -0
- package/transforms/SkipRedundantNodesTransform.js.flow +254 -0
- package/transforms/SkipSplitOperationTransform.js.flow +37 -0
- package/transforms/SkipUnreachableNodeTransform.js.flow +149 -0
- package/transforms/SkipUnusedVariablesTransform.js.flow +59 -0
- package/transforms/SplitModuleImportTransform.js.flow +98 -0
- package/transforms/TestOperationTransform.js.flow +142 -0
- package/transforms/TransformUtils.js.flow +26 -0
- package/transforms/ValidateGlobalVariablesTransform.js.flow +81 -0
- package/transforms/ValidateRequiredArgumentsTransform.js.flow +127 -0
- package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +112 -0
- package/transforms/ValidateUnusedVariablesTransform.js.flow +89 -0
- package/transforms/query-generators/FetchableQueryGenerator.js.flow +189 -0
- package/transforms/query-generators/NodeQueryGenerator.js.flow +219 -0
- package/transforms/query-generators/QueryQueryGenerator.js.flow +57 -0
- package/transforms/query-generators/ViewerQueryGenerator.js.flow +97 -0
- package/transforms/query-generators/index.js.flow +90 -0
- package/transforms/query-generators/utils.js.flow +76 -0
- package/util/CodeMarker.js.flow +79 -0
- package/{lib/core/GraphQLIR.js → util/DefaultHandleKey.js.flow} +9 -2
- package/util/RelayCompilerCache.js.flow +88 -0
- package/util/Rollout.js.flow +39 -0
- package/util/TimeReporter.js.flow +79 -0
- package/util/areEqualOSS.js.flow +123 -0
- package/util/argumentContainsVariables.js.flow +38 -0
- package/util/dedupeJSONStringify.js.flow +152 -0
- package/util/generateAbstractTypeRefinementKey.js.flow +29 -0
- package/util/getDefinitionNodeHash.js.flow +25 -0
- package/util/getModuleName.js.flow +39 -0
- package/util/joinArgumentDefinitions.js.flow +105 -0
- package/util/md5.js.flow +22 -0
- package/util/murmurHash.js.flow +94 -0
- package/util/nullthrowsOSS.js.flow +25 -0
- package/util/orList.js.flow +37 -0
- package/util/partitionArray.js.flow +37 -0
- package/lib/core/GraphQLCompilerContext.js +0 -165
- package/lib/core/GraphQLIRPrinter.js +0 -371
- package/lib/core/GraphQLIRTransformer.js +0 -344
- package/lib/core/GraphQLIRValidator.js +0 -218
- package/lib/core/GraphQLIRVisitor.js +0 -46
- package/lib/core/RelayCompilerError.js +0 -277
- package/lib/transforms/ConnectionFieldTransform.js +0 -276
@@ -1,371 +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
|
-
'use strict';
|
11
|
-
|
12
|
-
var invariant = require("fbjs/lib/invariant");
|
13
|
-
|
14
|
-
var _require = require('../util/DefaultHandleKey'),
|
15
|
-
DEFAULT_HANDLE_KEY = _require.DEFAULT_HANDLE_KEY;
|
16
|
-
|
17
|
-
var INDENT = ' ';
|
18
|
-
/**
|
19
|
-
* Converts a GraphQLIR node into a GraphQL string. Custom Relay
|
20
|
-
* extensions (directives) are not supported; to print fragments with
|
21
|
-
* variables or fragment spreads with arguments, transform the node
|
22
|
-
* prior to printing.
|
23
|
-
*/
|
24
|
-
|
25
|
-
function print(schema, node) {
|
26
|
-
switch (node.kind) {
|
27
|
-
case 'Fragment':
|
28
|
-
return "fragment ".concat(node.name, " on ").concat(schema.getTypeString(node.type)) + printFragmentArgumentDefinitions(schema, node.argumentDefinitions) + printDirectives(schema, node.directives) + printSelections(schema, node, '', {}) + '\n';
|
29
|
-
|
30
|
-
case 'Root':
|
31
|
-
return "".concat(node.operation, " ").concat(node.name) + printArgumentDefinitions(schema, node.argumentDefinitions) + printDirectives(schema, node.directives) + printSelections(schema, node, '', {}) + '\n';
|
32
|
-
|
33
|
-
case 'SplitOperation':
|
34
|
-
return "SplitOperation ".concat(node.name, " on ").concat(schema.getTypeString(node.type)) + printSelections(schema, node, '', {}) + '\n';
|
35
|
-
|
36
|
-
default:
|
37
|
-
node;
|
38
|
-
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'GraphQLIRPrinter: Unsupported IR node `%s`.', node.kind) : invariant(false) : void 0;
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
function printSelections(schema, node, indent, options) {
|
43
|
-
var selections = node.selections;
|
44
|
-
|
45
|
-
if (selections == null) {
|
46
|
-
return '';
|
47
|
-
}
|
48
|
-
|
49
|
-
var printed = selections.map(function (selection) {
|
50
|
-
return printSelection(schema, selection, indent, options);
|
51
|
-
});
|
52
|
-
return printed.length ? " {\n".concat(indent + INDENT).concat(printed.join('\n' + indent + INDENT), "\n").concat(indent).concat((options === null || options === void 0 ? void 0 : options.isClientExtension) === true ? '# ' : '', "}") : '';
|
53
|
-
}
|
54
|
-
/**
|
55
|
-
* Prints a field without subselections.
|
56
|
-
*/
|
57
|
-
|
58
|
-
|
59
|
-
function printField(schema, field, options) {
|
60
|
-
var _ref;
|
61
|
-
|
62
|
-
var parentDirectives = (_ref = options === null || options === void 0 ? void 0 : options.parentDirectives) !== null && _ref !== void 0 ? _ref : '';
|
63
|
-
var isClientExtension = (options === null || options === void 0 ? void 0 : options.isClientExtension) === true;
|
64
|
-
return (isClientExtension ? '# ' : '') + (field.alias === field.name ? field.name : field.alias + ': ' + field.name) + printArguments(schema, field.args) + parentDirectives + printDirectives(schema, field.directives) + printHandles(schema, field);
|
65
|
-
}
|
66
|
-
|
67
|
-
function printSelection(schema, selection, indent, options) {
|
68
|
-
var _ref2;
|
69
|
-
|
70
|
-
var str;
|
71
|
-
var parentDirectives = (_ref2 = options === null || options === void 0 ? void 0 : options.parentDirectives) !== null && _ref2 !== void 0 ? _ref2 : '';
|
72
|
-
var isClientExtension = (options === null || options === void 0 ? void 0 : options.isClientExtension) === true;
|
73
|
-
|
74
|
-
if (selection.kind === 'LinkedField' || selection.kind === 'ConnectionField') {
|
75
|
-
str = printField(schema, selection, {
|
76
|
-
parentDirectives: parentDirectives,
|
77
|
-
isClientExtension: isClientExtension
|
78
|
-
});
|
79
|
-
str += printSelections(schema, selection, indent + INDENT, {
|
80
|
-
isClientExtension: isClientExtension
|
81
|
-
});
|
82
|
-
} else if (selection.kind === 'ModuleImport' || selection.kind === 'Connection') {
|
83
|
-
str = selection.selections.map(function (matchSelection) {
|
84
|
-
return printSelection(schema, matchSelection, indent, {
|
85
|
-
parentDirectives: parentDirectives,
|
86
|
-
isClientExtension: isClientExtension
|
87
|
-
});
|
88
|
-
}).join('\n' + indent + INDENT);
|
89
|
-
} else if (selection.kind === 'ScalarField') {
|
90
|
-
str = printField(schema, selection, {
|
91
|
-
parentDirectives: parentDirectives,
|
92
|
-
isClientExtension: isClientExtension
|
93
|
-
});
|
94
|
-
} else if (selection.kind === 'InlineFragment') {
|
95
|
-
str = '';
|
96
|
-
|
97
|
-
if (isClientExtension) {
|
98
|
-
str += '# ';
|
99
|
-
}
|
100
|
-
|
101
|
-
str += '... on ' + schema.getTypeString(selection.typeCondition);
|
102
|
-
str += parentDirectives;
|
103
|
-
str += printDirectives(schema, selection.directives);
|
104
|
-
str += printSelections(schema, selection, indent + INDENT, {
|
105
|
-
isClientExtension: isClientExtension
|
106
|
-
});
|
107
|
-
} else if (selection.kind === 'FragmentSpread') {
|
108
|
-
str = '';
|
109
|
-
|
110
|
-
if (isClientExtension) {
|
111
|
-
str += '# ';
|
112
|
-
}
|
113
|
-
|
114
|
-
str += '...' + selection.name;
|
115
|
-
str += parentDirectives;
|
116
|
-
str += printFragmentArguments(schema, selection.args);
|
117
|
-
str += printDirectives(schema, selection.directives);
|
118
|
-
} else if (selection.kind === 'InlineDataFragmentSpread') {
|
119
|
-
str = "# ".concat(selection.name, " @inline") + "\n".concat(indent).concat(INDENT, "...") + parentDirectives + printSelections(schema, selection, indent + INDENT, {});
|
120
|
-
} else if (selection.kind === 'Condition') {
|
121
|
-
var value = printValue(schema, selection.condition, null); // For Flow
|
122
|
-
|
123
|
-
!(value != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'GraphQLIRPrinter: Expected a variable for condition, got a literal `null`.') : invariant(false) : void 0;
|
124
|
-
var condStr = selection.passingValue ? ' @include' : ' @skip';
|
125
|
-
condStr += '(if: ' + value + ')';
|
126
|
-
condStr += parentDirectives; // For multi-selection conditions, pushes the condition down to each
|
127
|
-
|
128
|
-
var subSelections = selection.selections.map(function (sel) {
|
129
|
-
return printSelection(schema, sel, indent, {
|
130
|
-
parentDirectives: condStr,
|
131
|
-
isClientExtension: isClientExtension
|
132
|
-
});
|
133
|
-
});
|
134
|
-
str = subSelections.join('\n' + INDENT);
|
135
|
-
} else if (selection.kind === 'Stream') {
|
136
|
-
var streamStr = " @stream(label: \"".concat(selection.label, "\"");
|
137
|
-
|
138
|
-
if (selection["if"] !== null) {
|
139
|
-
var _printValue;
|
140
|
-
|
141
|
-
streamStr += ", if: ".concat((_printValue = printValue(schema, selection["if"], null)) !== null && _printValue !== void 0 ? _printValue : '');
|
142
|
-
}
|
143
|
-
|
144
|
-
if (selection.initialCount !== null) {
|
145
|
-
var _printValue2;
|
146
|
-
|
147
|
-
streamStr += ", initial_count: ".concat((_printValue2 = printValue(schema, selection.initialCount, null)) !== null && _printValue2 !== void 0 ? _printValue2 : '');
|
148
|
-
}
|
149
|
-
|
150
|
-
streamStr += ')';
|
151
|
-
streamStr += parentDirectives;
|
152
|
-
|
153
|
-
var _subSelections = selection.selections.map(function (sel) {
|
154
|
-
return printSelection(schema, sel, indent, {
|
155
|
-
parentDirectives: streamStr,
|
156
|
-
isClientExtension: isClientExtension
|
157
|
-
});
|
158
|
-
});
|
159
|
-
|
160
|
-
str = _subSelections.join('\n' + INDENT);
|
161
|
-
} else if (selection.kind === 'Defer') {
|
162
|
-
var deferStr = " @defer(label: \"".concat(selection.label, "\"");
|
163
|
-
|
164
|
-
if (selection["if"] !== null) {
|
165
|
-
var _printValue3;
|
166
|
-
|
167
|
-
deferStr += ", if: ".concat((_printValue3 = printValue(schema, selection["if"], null)) !== null && _printValue3 !== void 0 ? _printValue3 : '');
|
168
|
-
}
|
169
|
-
|
170
|
-
deferStr += ')';
|
171
|
-
deferStr += parentDirectives;
|
172
|
-
|
173
|
-
if (selection.selections.every(function (subSelection) {
|
174
|
-
return subSelection.kind === 'InlineFragment' || subSelection.kind === 'FragmentSpread';
|
175
|
-
})) {
|
176
|
-
var _subSelections2 = selection.selections.map(function (sel) {
|
177
|
-
return printSelection(schema, sel, indent, {
|
178
|
-
parentDirectives: deferStr,
|
179
|
-
isClientExtension: isClientExtension
|
180
|
-
});
|
181
|
-
});
|
182
|
-
|
183
|
-
str = _subSelections2.join('\n' + INDENT);
|
184
|
-
} else {
|
185
|
-
if (selection.metadata != null && selection.metadata.fragmentTypeCondition != null) {
|
186
|
-
str = "... on ".concat(schema.getTypeString(selection.metadata.fragmentTypeCondition)) + deferStr;
|
187
|
-
} else {
|
188
|
-
str = '...' + deferStr;
|
189
|
-
}
|
190
|
-
|
191
|
-
str += printSelections(schema, selection, indent + INDENT, {
|
192
|
-
isClientExtension: isClientExtension
|
193
|
-
});
|
194
|
-
}
|
195
|
-
} else if (selection.kind === 'ClientExtension') {
|
196
|
-
!(isClientExtension === false) ? process.env.NODE_ENV !== "production" ? invariant(false, 'GraphQLIRPrinter: Did not expect to encounter a ClientExtension node ' + 'as a descendant of another ClientExtension node.') : invariant(false) : void 0;
|
197
|
-
str = '# Client-only selections:\n' + indent + INDENT + selection.selections.map(function (sel) {
|
198
|
-
return printSelection(schema, sel, indent, {
|
199
|
-
parentDirectives: parentDirectives,
|
200
|
-
isClientExtension: true
|
201
|
-
});
|
202
|
-
}).join('\n' + indent + INDENT);
|
203
|
-
} else {
|
204
|
-
selection;
|
205
|
-
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'GraphQLIRPrinter: Unknown selection kind `%s`.', selection.kind) : invariant(false) : void 0;
|
206
|
-
}
|
207
|
-
|
208
|
-
return str;
|
209
|
-
}
|
210
|
-
|
211
|
-
function printArgumentDefinitions(schema, argumentDefinitions) {
|
212
|
-
var printed = argumentDefinitions.map(function (def) {
|
213
|
-
var str = "$".concat(def.name, ": ").concat(schema.getTypeString(def.type));
|
214
|
-
|
215
|
-
if (def.defaultValue != null) {
|
216
|
-
str += ' = ' + printLiteral(schema, def.defaultValue, def.type);
|
217
|
-
}
|
218
|
-
|
219
|
-
return str;
|
220
|
-
});
|
221
|
-
return printed.length ? "(\n".concat(INDENT).concat(printed.join('\n' + INDENT), "\n)") : '';
|
222
|
-
}
|
223
|
-
|
224
|
-
function printFragmentArgumentDefinitions(schema, argumentDefinitions) {
|
225
|
-
var printed;
|
226
|
-
argumentDefinitions.forEach(function (def) {
|
227
|
-
if (def.kind !== 'LocalArgumentDefinition') {
|
228
|
-
return;
|
229
|
-
}
|
230
|
-
|
231
|
-
printed = printed || [];
|
232
|
-
var str = "".concat(def.name, ": {type: \"").concat(schema.getTypeString(def.type), "\"");
|
233
|
-
|
234
|
-
if (def.defaultValue != null) {
|
235
|
-
str += ", defaultValue: ".concat(printLiteral(schema, def.defaultValue, def.type));
|
236
|
-
}
|
237
|
-
|
238
|
-
str += '}';
|
239
|
-
printed.push(str);
|
240
|
-
});
|
241
|
-
return printed && printed.length ? " @argumentDefinitions(\n".concat(INDENT).concat(printed.join('\n' + INDENT), "\n)") : '';
|
242
|
-
}
|
243
|
-
|
244
|
-
function printHandles(schema, field) {
|
245
|
-
if (!field.handles) {
|
246
|
-
return '';
|
247
|
-
}
|
248
|
-
|
249
|
-
var printed = field.handles.map(function (handle) {
|
250
|
-
// For backward compatibility and also because this module is shared by ComponentScript.
|
251
|
-
var key = handle.key === DEFAULT_HANDLE_KEY ? '' : ", key: \"".concat(handle.key, "\"");
|
252
|
-
var filters = handle.filters == null ? '' : ", filters: ".concat(JSON.stringify(Array.from(handle.filters).sort()));
|
253
|
-
return "@__clientField(handle: \"".concat(handle.name, "\"").concat(key).concat(filters, ")");
|
254
|
-
});
|
255
|
-
return printed.length ? ' ' + printed.join(' ') : '';
|
256
|
-
}
|
257
|
-
|
258
|
-
function printDirectives(schema, directives) {
|
259
|
-
var printed = directives.map(function (directive) {
|
260
|
-
return '@' + directive.name + printArguments(schema, directive.args);
|
261
|
-
});
|
262
|
-
return printed.length ? ' ' + printed.join(' ') : '';
|
263
|
-
}
|
264
|
-
|
265
|
-
function printFragmentArguments(schema, args) {
|
266
|
-
var printedArgs = printArguments(schema, args);
|
267
|
-
|
268
|
-
if (!printedArgs.length) {
|
269
|
-
return '';
|
270
|
-
}
|
271
|
-
|
272
|
-
return " @arguments".concat(printedArgs);
|
273
|
-
}
|
274
|
-
|
275
|
-
function printArguments(schema, args) {
|
276
|
-
var printed = [];
|
277
|
-
args.forEach(function (arg) {
|
278
|
-
var printedValue = printValue(schema, arg.value, arg.type);
|
279
|
-
|
280
|
-
if (printedValue != null) {
|
281
|
-
printed.push(arg.name + ': ' + printedValue);
|
282
|
-
}
|
283
|
-
});
|
284
|
-
return printed.length ? '(' + printed.join(', ') + ')' : '';
|
285
|
-
}
|
286
|
-
|
287
|
-
function printValue(schema, value, type) {
|
288
|
-
if (type != null && schema.isNonNull(type)) {
|
289
|
-
type = schema.getNullableType(type);
|
290
|
-
}
|
291
|
-
|
292
|
-
if (value.kind === 'Variable') {
|
293
|
-
return '$' + value.variableName;
|
294
|
-
} else if (value.value != null) {
|
295
|
-
return printLiteral(schema, value.value, type);
|
296
|
-
} else {
|
297
|
-
return null;
|
298
|
-
}
|
299
|
-
}
|
300
|
-
|
301
|
-
function printLiteral(schema, value, type) {
|
302
|
-
if (value == null) {
|
303
|
-
var _JSON$stringify;
|
304
|
-
|
305
|
-
return (_JSON$stringify = JSON.stringify(value)) !== null && _JSON$stringify !== void 0 ? _JSON$stringify : 'null';
|
306
|
-
}
|
307
|
-
|
308
|
-
if (type != null && schema.isNonNull(type)) {
|
309
|
-
type = schema.getNullableType(type);
|
310
|
-
}
|
311
|
-
|
312
|
-
if (type && schema.isEnum(type)) {
|
313
|
-
var _JSON$stringify2;
|
314
|
-
|
315
|
-
var result = schema.serialize(schema.assertEnumType(type), value);
|
316
|
-
|
317
|
-
if (result == null && typeof value === 'string') {
|
318
|
-
// For backwards compatibility, print invalid input values as-is. This
|
319
|
-
// can occur with literals defined as an @argumentDefinitions
|
320
|
-
// defaultValue.
|
321
|
-
result = value;
|
322
|
-
}
|
323
|
-
|
324
|
-
!(typeof result === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'GraphQLIRPrinter: Expected value of type %s to be a valid enum value, got `%s`.', schema.getTypeString(type), (_JSON$stringify2 = JSON.stringify(value)) !== null && _JSON$stringify2 !== void 0 ? _JSON$stringify2 : 'null') : invariant(false) : void 0;
|
325
|
-
return result;
|
326
|
-
} else if (type && (schema.isId(type) || schema.isInt(type))) {
|
327
|
-
var _JSON$stringify3;
|
328
|
-
|
329
|
-
return (_JSON$stringify3 = JSON.stringify(value)) !== null && _JSON$stringify3 !== void 0 ? _JSON$stringify3 : '';
|
330
|
-
} else if (type && schema.isScalar(type)) {
|
331
|
-
var _JSON$stringify4;
|
332
|
-
|
333
|
-
var _result = schema.serialize(schema.assertScalarType(type), value);
|
334
|
-
|
335
|
-
return (_JSON$stringify4 = JSON.stringify(_result)) !== null && _JSON$stringify4 !== void 0 ? _JSON$stringify4 : '';
|
336
|
-
} else if (Array.isArray(value)) {
|
337
|
-
!(type && schema.isList(type)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'GraphQLIRPrinter: Need a type in order to print arrays.') : invariant(false) : void 0;
|
338
|
-
var itemType = schema.getListItemType(type);
|
339
|
-
return '[' + value.map(function (item) {
|
340
|
-
return printLiteral(schema, item, itemType);
|
341
|
-
}).join(', ') + ']';
|
342
|
-
} else if (type && schema.isList(type) && value != null) {
|
343
|
-
// Not an array, but still a list. Treat as list-of-one as per spec 3.1.7:
|
344
|
-
// http://facebook.github.io/graphql/October2016/#sec-Lists
|
345
|
-
return printLiteral(schema, value, schema.getListItemType(type));
|
346
|
-
} else if (typeof value === 'object' && value != null) {
|
347
|
-
var fields = [];
|
348
|
-
!(type && schema.isInputObject(type)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'GraphQLIRPrinter: Need an InputObject type to print objects.') : invariant(false) : void 0;
|
349
|
-
var inputType = schema.assertInputObjectType(type);
|
350
|
-
|
351
|
-
for (var key in value) {
|
352
|
-
if (value.hasOwnProperty(key)) {
|
353
|
-
var fieldConfig = schema.getFieldConfig(schema.expectField(inputType, key));
|
354
|
-
fields.push(key + ': ' + printLiteral(schema, value[key], fieldConfig.type));
|
355
|
-
}
|
356
|
-
}
|
357
|
-
|
358
|
-
return '{' + fields.join(', ') + '}';
|
359
|
-
} else {
|
360
|
-
var _JSON$stringify5;
|
361
|
-
|
362
|
-
return (_JSON$stringify5 = JSON.stringify(value)) !== null && _JSON$stringify5 !== void 0 ? _JSON$stringify5 : 'null';
|
363
|
-
}
|
364
|
-
}
|
365
|
-
|
366
|
-
module.exports = {
|
367
|
-
print: print,
|
368
|
-
printField: printField,
|
369
|
-
printArguments: printArguments,
|
370
|
-
printDirectives: printDirectives
|
371
|
-
};
|