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.
Files changed (220) hide show
  1. package/bin/RelayCompilerBin.js.flow +169 -0
  2. package/bin/RelayCompilerMain.js.flow +515 -0
  3. package/bin/__fixtures__/plugin-module.js.flow +17 -0
  4. package/bin/relay-compiler +8930 -8967
  5. package/codegen/CodegenDirectory.js.flow +375 -0
  6. package/codegen/CodegenRunner.js.flow +432 -0
  7. package/codegen/CodegenTypes.js.flow +28 -0
  8. package/codegen/CodegenWatcher.js.flow +254 -0
  9. package/codegen/NormalizationCodeGenerator.js.flow +563 -0
  10. package/codegen/ReaderCodeGenerator.js.flow +477 -0
  11. package/codegen/RelayCodeGenerator.js.flow +85 -0
  12. package/codegen/RelayFileWriter.js.flow +365 -0
  13. package/codegen/SourceControl.js.flow +58 -0
  14. package/codegen/compileRelayArtifacts.js.flow +182 -0
  15. package/codegen/createPrintRequireModuleDependency.js.flow +21 -0
  16. package/codegen/sortObjectByKey.js.flow +25 -0
  17. package/codegen/writeRelayGeneratedFile.js.flow +223 -0
  18. package/core/ASTCache.js.flow +73 -0
  19. package/core/ASTConvert.js.flow +233 -0
  20. package/core/CompilerContext.js.flow +190 -0
  21. package/core/CompilerError.js.flow +250 -0
  22. package/core/DotGraphQLParser.js.flow +39 -0
  23. package/core/GraphQLCompilerProfiler.js.flow +341 -0
  24. package/core/GraphQLDerivedFromMetadata.js.flow +36 -0
  25. package/core/GraphQLWatchmanClient.js.flow +111 -0
  26. package/core/IR.js.flow +327 -0
  27. package/core/IRPrinter.js.flow +482 -0
  28. package/core/IRTransformer.js.flow +377 -0
  29. package/core/IRValidator.js.flow +260 -0
  30. package/core/IRVisitor.js.flow +150 -0
  31. package/core/JSModuleParser.js.flow +24 -0
  32. package/core/RelayCompilerScope.js.flow +199 -0
  33. package/core/RelayFindGraphQLTags.js.flow +119 -0
  34. package/core/RelayGraphQLEnumsGenerator.js.flow +55 -0
  35. package/core/RelayIRTransforms.js.flow +131 -0
  36. package/core/RelayParser.js.flow +1731 -0
  37. package/core/RelaySourceModuleParser.js.flow +135 -0
  38. package/core/Schema.js.flow +1983 -0
  39. package/core/SchemaUtils.js.flow +120 -0
  40. package/core/filterContextForNode.js.flow +50 -0
  41. package/core/getFieldDefinition.js.flow +156 -0
  42. package/core/getIdentifierForArgumentValue.js.flow +49 -0
  43. package/core/getIdentifierForSelection.js.flow +69 -0
  44. package/core/getLiteralArgumentValues.js.flow +32 -0
  45. package/core/getNormalizationOperationName.js.flow +19 -0
  46. package/core/inferRootArgumentDefinitions.js.flow +323 -0
  47. package/index.js +1 -1
  48. package/index.js.flow +200 -0
  49. package/language/RelayLanguagePluginInterface.js.flow +283 -0
  50. package/language/javascript/FindGraphQLTags.js.flow +232 -0
  51. package/language/javascript/RelayFlowBabelFactories.js.flow +180 -0
  52. package/language/javascript/RelayFlowGenerator.js.flow +1042 -0
  53. package/language/javascript/RelayFlowTypeTransformers.js.flow +184 -0
  54. package/language/javascript/RelayLanguagePluginJavaScript.js.flow +34 -0
  55. package/language/javascript/formatGeneratedModule.js.flow +65 -0
  56. package/lib/bin/RelayCompilerBin.js +24 -7
  57. package/lib/bin/RelayCompilerMain.js +141 -136
  58. package/lib/codegen/CodegenDirectory.js +13 -8
  59. package/lib/codegen/CodegenRunner.js +37 -76
  60. package/lib/codegen/CodegenWatcher.js +13 -21
  61. package/lib/codegen/NormalizationCodeGenerator.js +117 -140
  62. package/lib/codegen/ReaderCodeGenerator.js +76 -117
  63. package/lib/codegen/RelayCodeGenerator.js +17 -6
  64. package/lib/codegen/RelayFileWriter.js +19 -40
  65. package/lib/codegen/compileRelayArtifacts.js +16 -30
  66. package/lib/codegen/sortObjectByKey.js +43 -0
  67. package/lib/codegen/writeRelayGeneratedFile.js +86 -95
  68. package/lib/core/ASTCache.js +2 -4
  69. package/lib/core/CompilerContext.js +2 -4
  70. package/lib/core/CompilerError.js +27 -54
  71. package/lib/core/GraphQLCompilerProfiler.js +8 -12
  72. package/lib/core/GraphQLDerivedFromMetadata.js +1 -10
  73. package/lib/core/GraphQLWatchmanClient.js +4 -12
  74. package/lib/core/IRPrinter.js +23 -21
  75. package/lib/core/IRTransformer.js +8 -16
  76. package/lib/core/IRValidator.js +1 -9
  77. package/lib/core/IRVisitor.js +0 -2
  78. package/lib/core/RelayCompilerScope.js +4 -4
  79. package/lib/core/RelayGraphQLEnumsGenerator.js +12 -15
  80. package/lib/core/RelayIRTransforms.js +16 -14
  81. package/lib/core/RelayParser.js +53 -89
  82. package/lib/core/RelaySourceModuleParser.js +3 -3
  83. package/lib/core/Schema.js +61 -73
  84. package/lib/core/SchemaUtils.js +15 -1
  85. package/lib/core/getFieldDefinition.js +12 -15
  86. package/lib/core/getIdentifierForSelection.js +2 -4
  87. package/lib/core/inferRootArgumentDefinitions.js +33 -73
  88. package/lib/index.js +4 -5
  89. package/lib/language/javascript/FindGraphQLTags.js +4 -3
  90. package/lib/language/javascript/RelayFlowGenerator.js +82 -171
  91. package/lib/language/javascript/RelayFlowTypeTransformers.js +1 -3
  92. package/lib/language/javascript/RelayLanguagePluginJavaScript.js +6 -4
  93. package/lib/language/javascript/formatGeneratedModule.js +11 -2
  94. package/lib/reporters/ConsoleReporter.js +1 -3
  95. package/lib/reporters/MultiReporter.js +1 -3
  96. package/lib/runner/Artifacts.js +69 -170
  97. package/lib/runner/BufferedFilesystem.js +32 -66
  98. package/lib/runner/GraphQLASTNodeGroup.js +54 -120
  99. package/lib/runner/GraphQLNodeMap.js +14 -19
  100. package/lib/runner/Sources.js +51 -85
  101. package/lib/runner/StrictMap.js +21 -37
  102. package/lib/runner/getChangedNodeNames.js +30 -62
  103. package/lib/transforms/ApplyFragmentArgumentTransform.js +73 -59
  104. package/lib/transforms/ClientExtensionsTransform.js +12 -16
  105. package/lib/transforms/ConnectionTransform.js +30 -37
  106. package/lib/transforms/DeclarativeConnectionMutationTransform.js +167 -0
  107. package/lib/transforms/DeferStreamTransform.js +30 -73
  108. package/lib/transforms/DisallowTypenameOnRoot.js +55 -0
  109. package/lib/transforms/FieldHandleTransform.js +6 -2
  110. package/lib/transforms/FlattenTransform.js +18 -45
  111. package/lib/transforms/GenerateIDFieldTransform.js +56 -35
  112. package/lib/transforms/GenerateTypeNameTransform.js +84 -10
  113. package/lib/transforms/InlineDataFragmentTransform.js +9 -4
  114. package/lib/transforms/MaskTransform.js +17 -17
  115. package/lib/transforms/MatchTransform.js +110 -32
  116. package/lib/transforms/RefetchableFragmentTransform.js +21 -38
  117. package/lib/transforms/RelayDirectiveTransform.js +8 -3
  118. package/lib/transforms/SkipClientExtensionsTransform.js +8 -0
  119. package/lib/transforms/SkipHandleFieldTransform.js +6 -2
  120. package/lib/transforms/SkipRedundantNodesTransform.js +7 -4
  121. package/lib/transforms/SkipSplitOperationTransform.js +32 -0
  122. package/lib/transforms/SkipUnreachableNodeTransform.js +9 -10
  123. package/lib/transforms/SkipUnusedVariablesTransform.js +18 -17
  124. package/lib/transforms/SplitModuleImportTransform.js +2 -2
  125. package/lib/transforms/TestOperationTransform.js +26 -22
  126. package/lib/transforms/ValidateGlobalVariablesTransform.js +18 -30
  127. package/lib/transforms/ValidateRequiredArgumentsTransform.js +12 -16
  128. package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +16 -30
  129. package/lib/transforms/ValidateUnusedVariablesTransform.js +18 -30
  130. package/lib/transforms/query-generators/FetchableQueryGenerator.js +161 -0
  131. package/lib/transforms/query-generators/NodeQueryGenerator.js +22 -3
  132. package/lib/transforms/query-generators/QueryQueryGenerator.js +2 -1
  133. package/lib/transforms/query-generators/ViewerQueryGenerator.js +1 -0
  134. package/lib/transforms/query-generators/index.js +23 -6
  135. package/lib/transforms/query-generators/utils.js +17 -16
  136. package/lib/util/RelayCompilerCache.js +2 -4
  137. package/lib/util/argumentContainsVariables.js +37 -0
  138. package/lib/util/dedupeJSONStringify.js +15 -12
  139. package/lib/util/generateAbstractTypeRefinementKey.js +24 -0
  140. package/lib/util/getModuleName.js +3 -5
  141. package/lib/util/joinArgumentDefinitions.js +3 -1
  142. package/package.json +6 -6
  143. package/relay-compiler.js +4 -4
  144. package/relay-compiler.min.js +4 -4
  145. package/reporters/ConsoleReporter.js.flow +81 -0
  146. package/reporters/MultiReporter.js.flow +43 -0
  147. package/reporters/Reporter.js.flow +19 -0
  148. package/runner/Artifacts.js.flow +219 -0
  149. package/runner/BufferedFilesystem.js.flow +194 -0
  150. package/runner/GraphQLASTNodeGroup.js.flow +176 -0
  151. package/runner/GraphQLASTUtils.js.flow +26 -0
  152. package/runner/GraphQLNodeMap.js.flow +55 -0
  153. package/runner/Sources.js.flow +214 -0
  154. package/runner/StrictMap.js.flow +96 -0
  155. package/runner/compileArtifacts.js.flow +76 -0
  156. package/runner/extractAST.js.flow +100 -0
  157. package/runner/getChangedNodeNames.js.flow +48 -0
  158. package/runner/getSchemaInstance.js.flow +36 -0
  159. package/runner/types.js.flow +37 -0
  160. package/transforms/ApplyFragmentArgumentTransform.js.flow +526 -0
  161. package/transforms/ClientExtensionsTransform.js.flow +222 -0
  162. package/transforms/ConnectionTransform.js.flow +856 -0
  163. package/transforms/DeclarativeConnectionMutationTransform.js.flow +157 -0
  164. package/transforms/DeferStreamTransform.js.flow +265 -0
  165. package/transforms/DisallowIdAsAlias.js.flow +47 -0
  166. package/transforms/DisallowTypenameOnRoot.js.flow +45 -0
  167. package/transforms/FieldHandleTransform.js.flow +80 -0
  168. package/transforms/FilterDirectivesTransform.js.flow +45 -0
  169. package/transforms/FlattenTransform.js.flow +453 -0
  170. package/transforms/GenerateIDFieldTransform.js.flow +152 -0
  171. package/transforms/GenerateTypeNameTransform.js.flow +161 -0
  172. package/transforms/InlineDataFragmentTransform.js.flow +125 -0
  173. package/transforms/InlineFragmentsTransform.js.flow +71 -0
  174. package/transforms/MaskTransform.js.flow +126 -0
  175. package/transforms/MatchTransform.js.flow +583 -0
  176. package/transforms/RefetchableFragmentTransform.js.flow +272 -0
  177. package/transforms/RelayDirectiveTransform.js.flow +97 -0
  178. package/transforms/SkipClientExtensionsTransform.js.flow +54 -0
  179. package/transforms/SkipHandleFieldTransform.js.flow +44 -0
  180. package/transforms/SkipRedundantNodesTransform.js.flow +254 -0
  181. package/transforms/SkipSplitOperationTransform.js.flow +37 -0
  182. package/transforms/SkipUnreachableNodeTransform.js.flow +149 -0
  183. package/transforms/SkipUnusedVariablesTransform.js.flow +59 -0
  184. package/transforms/SplitModuleImportTransform.js.flow +98 -0
  185. package/transforms/TestOperationTransform.js.flow +142 -0
  186. package/transforms/TransformUtils.js.flow +26 -0
  187. package/transforms/ValidateGlobalVariablesTransform.js.flow +81 -0
  188. package/transforms/ValidateRequiredArgumentsTransform.js.flow +127 -0
  189. package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +112 -0
  190. package/transforms/ValidateUnusedVariablesTransform.js.flow +89 -0
  191. package/transforms/query-generators/FetchableQueryGenerator.js.flow +189 -0
  192. package/transforms/query-generators/NodeQueryGenerator.js.flow +219 -0
  193. package/transforms/query-generators/QueryQueryGenerator.js.flow +57 -0
  194. package/transforms/query-generators/ViewerQueryGenerator.js.flow +97 -0
  195. package/transforms/query-generators/index.js.flow +90 -0
  196. package/transforms/query-generators/utils.js.flow +76 -0
  197. package/util/CodeMarker.js.flow +79 -0
  198. package/{lib/core/GraphQLIR.js → util/DefaultHandleKey.js.flow} +9 -2
  199. package/util/RelayCompilerCache.js.flow +88 -0
  200. package/util/Rollout.js.flow +39 -0
  201. package/util/TimeReporter.js.flow +79 -0
  202. package/util/areEqualOSS.js.flow +123 -0
  203. package/util/argumentContainsVariables.js.flow +38 -0
  204. package/util/dedupeJSONStringify.js.flow +152 -0
  205. package/util/generateAbstractTypeRefinementKey.js.flow +29 -0
  206. package/util/getDefinitionNodeHash.js.flow +25 -0
  207. package/util/getModuleName.js.flow +39 -0
  208. package/util/joinArgumentDefinitions.js.flow +105 -0
  209. package/util/md5.js.flow +22 -0
  210. package/util/murmurHash.js.flow +94 -0
  211. package/util/nullthrowsOSS.js.flow +25 -0
  212. package/util/orList.js.flow +37 -0
  213. package/util/partitionArray.js.flow +37 -0
  214. package/lib/core/GraphQLCompilerContext.js +0 -165
  215. package/lib/core/GraphQLIRPrinter.js +0 -371
  216. package/lib/core/GraphQLIRTransformer.js +0 -344
  217. package/lib/core/GraphQLIRValidator.js +0 -218
  218. package/lib/core/GraphQLIRVisitor.js +0 -46
  219. package/lib/core/RelayCompilerError.js +0 -277
  220. 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
- };