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.
Files changed (263) hide show
  1. package/cli.js +23 -0
  2. package/index.js +19 -3
  3. package/linux-x64/relay +0 -0
  4. package/macos-x64/relay +0 -0
  5. package/package.json +2 -24
  6. package/win-x64/relay.exe +0 -0
  7. package/bin/RelayCompilerBin.js.flow +0 -168
  8. package/bin/RelayCompilerMain.js.flow +0 -515
  9. package/bin/__fixtures__/plugin-module.js.flow +0 -17
  10. package/bin/relay-compiler +0 -19068
  11. package/codegen/CodegenDirectory.js.flow +0 -372
  12. package/codegen/CodegenRunner.js.flow +0 -424
  13. package/codegen/CodegenTypes.js.flow +0 -28
  14. package/codegen/CodegenWatcher.js.flow +0 -250
  15. package/codegen/NormalizationCodeGenerator.js.flow +0 -566
  16. package/codegen/ReaderCodeGenerator.js.flow +0 -510
  17. package/codegen/RelayCodeGenerator.js.flow +0 -85
  18. package/codegen/RelayFileWriter.js.flow +0 -365
  19. package/codegen/SourceControl.js.flow +0 -58
  20. package/codegen/compileRelayArtifacts.js.flow +0 -181
  21. package/codegen/createPrintRequireModuleDependency.js.flow +0 -19
  22. package/codegen/sortObjectByKey.js.flow +0 -25
  23. package/codegen/writeRelayGeneratedFile.js.flow +0 -235
  24. package/core/ASTCache.js.flow +0 -73
  25. package/core/ASTConvert.js.flow +0 -230
  26. package/core/CompilerContext.js.flow +0 -189
  27. package/core/CompilerError.js.flow +0 -255
  28. package/core/DotGraphQLParser.js.flow +0 -37
  29. package/core/GraphQLCompilerProfiler.js.flow +0 -341
  30. package/core/GraphQLDerivedFromMetadata.js.flow +0 -36
  31. package/core/GraphQLWatchmanClient.js.flow +0 -109
  32. package/core/IR.js.flow +0 -326
  33. package/core/IRPrinter.js.flow +0 -472
  34. package/core/IRTransformer.js.flow +0 -376
  35. package/core/IRValidator.js.flow +0 -259
  36. package/core/IRVisitor.js.flow +0 -150
  37. package/core/JSModuleParser.js.flow +0 -24
  38. package/core/RelayCompilerScope.js.flow +0 -199
  39. package/core/RelayFindGraphQLTags.js.flow +0 -118
  40. package/core/RelayGraphQLEnumsGenerator.js.flow +0 -55
  41. package/core/RelayIRTransforms.js.flow +0 -138
  42. package/core/RelayParser.js.flow +0 -1741
  43. package/core/RelaySourceModuleParser.js.flow +0 -133
  44. package/core/Schema.js.flow +0 -2035
  45. package/core/SchemaUtils.js.flow +0 -120
  46. package/core/filterContextForNode.js.flow +0 -49
  47. package/core/getFieldDefinition.js.flow +0 -156
  48. package/core/getIdentifierForArgumentValue.js.flow +0 -49
  49. package/core/getIdentifierForSelection.js.flow +0 -68
  50. package/core/getLiteralArgumentValues.js.flow +0 -32
  51. package/core/getNormalizationOperationName.js.flow +0 -19
  52. package/core/inferRootArgumentDefinitions.js.flow +0 -322
  53. package/index.js.flow +0 -198
  54. package/language/RelayLanguagePluginInterface.js.flow +0 -283
  55. package/language/javascript/FindGraphQLTags.js.flow +0 -136
  56. package/language/javascript/RelayFlowBabelFactories.js.flow +0 -176
  57. package/language/javascript/RelayFlowGenerator.js.flow +0 -1096
  58. package/language/javascript/RelayFlowTypeTransformers.js.flow +0 -181
  59. package/language/javascript/RelayLanguagePluginJavaScript.js.flow +0 -33
  60. package/language/javascript/formatGeneratedModule.js.flow +0 -65
  61. package/lib/bin/RelayCompilerBin.js +0 -143
  62. package/lib/bin/RelayCompilerMain.js +0 -488
  63. package/lib/bin/__fixtures__/plugin-module.js +0 -16
  64. package/lib/codegen/CodegenDirectory.js +0 -335
  65. package/lib/codegen/CodegenRunner.js +0 -433
  66. package/lib/codegen/CodegenTypes.js +0 -11
  67. package/lib/codegen/CodegenWatcher.js +0 -271
  68. package/lib/codegen/NormalizationCodeGenerator.js +0 -487
  69. package/lib/codegen/ReaderCodeGenerator.js +0 -473
  70. package/lib/codegen/RelayCodeGenerator.js +0 -75
  71. package/lib/codegen/RelayFileWriter.js +0 -270
  72. package/lib/codegen/SourceControl.js +0 -60
  73. package/lib/codegen/compileRelayArtifacts.js +0 -157
  74. package/lib/codegen/createPrintRequireModuleDependency.js +0 -19
  75. package/lib/codegen/sortObjectByKey.js +0 -41
  76. package/lib/codegen/writeRelayGeneratedFile.js +0 -206
  77. package/lib/core/ASTCache.js +0 -70
  78. package/lib/core/ASTConvert.js +0 -198
  79. package/lib/core/CompilerContext.js +0 -165
  80. package/lib/core/CompilerError.js +0 -252
  81. package/lib/core/DotGraphQLParser.js +0 -40
  82. package/lib/core/GraphQLCompilerProfiler.js +0 -299
  83. package/lib/core/GraphQLDerivedFromMetadata.js +0 -31
  84. package/lib/core/GraphQLWatchmanClient.js +0 -150
  85. package/lib/core/IR.js +0 -11
  86. package/lib/core/IRPrinter.js +0 -388
  87. package/lib/core/IRTransformer.js +0 -345
  88. package/lib/core/IRValidator.js +0 -226
  89. package/lib/core/IRVisitor.js +0 -45
  90. package/lib/core/JSModuleParser.js +0 -18
  91. package/lib/core/RelayCompilerScope.js +0 -183
  92. package/lib/core/RelayFindGraphQLTags.js +0 -79
  93. package/lib/core/RelayGraphQLEnumsGenerator.js +0 -50
  94. package/lib/core/RelayIRTransforms.js +0 -109
  95. package/lib/core/RelayParser.js +0 -1381
  96. package/lib/core/RelaySourceModuleParser.js +0 -104
  97. package/lib/core/Schema.js +0 -1877
  98. package/lib/core/SchemaUtils.js +0 -98
  99. package/lib/core/filterContextForNode.js +0 -50
  100. package/lib/core/getFieldDefinition.js +0 -145
  101. package/lib/core/getIdentifierForArgumentValue.js +0 -54
  102. package/lib/core/getIdentifierForSelection.js +0 -49
  103. package/lib/core/getLiteralArgumentValues.js +0 -26
  104. package/lib/core/getNormalizationOperationName.js +0 -17
  105. package/lib/core/inferRootArgumentDefinitions.js +0 -351
  106. package/lib/index.js +0 -178
  107. package/lib/language/RelayLanguagePluginInterface.js +0 -26
  108. package/lib/language/javascript/FindGraphQLTags.js +0 -126
  109. package/lib/language/javascript/RelayFlowBabelFactories.js +0 -160
  110. package/lib/language/javascript/RelayFlowGenerator.js +0 -856
  111. package/lib/language/javascript/RelayFlowTypeTransformers.js +0 -119
  112. package/lib/language/javascript/RelayLanguagePluginJavaScript.js +0 -30
  113. package/lib/language/javascript/formatGeneratedModule.js +0 -36
  114. package/lib/reporters/ConsoleReporter.js +0 -61
  115. package/lib/reporters/MultiReporter.js +0 -45
  116. package/lib/reporters/Reporter.js +0 -11
  117. package/lib/runner/Artifacts.js +0 -323
  118. package/lib/runner/BufferedFilesystem.js +0 -262
  119. package/lib/runner/GraphQLASTNodeGroup.js +0 -256
  120. package/lib/runner/GraphQLASTUtils.js +0 -23
  121. package/lib/runner/GraphQLNodeMap.js +0 -81
  122. package/lib/runner/Sources.js +0 -271
  123. package/lib/runner/StrictMap.js +0 -134
  124. package/lib/runner/compileArtifacts.js +0 -39
  125. package/lib/runner/extractAST.js +0 -77
  126. package/lib/runner/getChangedNodeNames.js +0 -82
  127. package/lib/runner/getSchemaInstance.js +0 -30
  128. package/lib/runner/types.js +0 -12
  129. package/lib/test-utils/TestSchema.js +0 -27
  130. package/lib/test-utils/parseGraphQLText.js +0 -30
  131. package/lib/transforms/ApplyFragmentArgumentTransform.js +0 -393
  132. package/lib/transforms/ClientExtensionsTransform.js +0 -221
  133. package/lib/transforms/ConnectionTransform.js +0 -639
  134. package/lib/transforms/DeclarativeConnectionMutationTransform.js +0 -218
  135. package/lib/transforms/DeferStreamTransform.js +0 -246
  136. package/lib/transforms/DisallowIdAsAlias.js +0 -40
  137. package/lib/transforms/DisallowTypenameOnRoot.js +0 -53
  138. package/lib/transforms/FieldHandleTransform.js +0 -79
  139. package/lib/transforms/FilterCompilerDirectivesTransform.js +0 -29
  140. package/lib/transforms/FilterDirectivesTransform.js +0 -42
  141. package/lib/transforms/FlattenTransform.js +0 -306
  142. package/lib/transforms/GenerateIDFieldTransform.js +0 -135
  143. package/lib/transforms/GenerateTypeNameTransform.js +0 -149
  144. package/lib/transforms/InlineDataFragmentTransform.js +0 -100
  145. package/lib/transforms/InlineFragmentsTransform.js +0 -61
  146. package/lib/transforms/MaskTransform.js +0 -117
  147. package/lib/transforms/MatchTransform.js +0 -434
  148. package/lib/transforms/ReactFlightComponentTransform.js +0 -158
  149. package/lib/transforms/RefetchableFragmentTransform.js +0 -249
  150. package/lib/transforms/RelayDirectiveTransform.js +0 -83
  151. package/lib/transforms/RequiredFieldTransform.js +0 -369
  152. package/lib/transforms/SkipClientExtensionsTransform.js +0 -46
  153. package/lib/transforms/SkipHandleFieldTransform.js +0 -45
  154. package/lib/transforms/SkipRedundantNodesTransform.js +0 -261
  155. package/lib/transforms/SkipSplitOperationTransform.js +0 -32
  156. package/lib/transforms/SkipUnreachableNodeTransform.js +0 -158
  157. package/lib/transforms/SkipUnusedVariablesTransform.js +0 -75
  158. package/lib/transforms/SplitModuleImportTransform.js +0 -82
  159. package/lib/transforms/TestOperationTransform.js +0 -144
  160. package/lib/transforms/TransformUtils.js +0 -21
  161. package/lib/transforms/ValidateGlobalVariablesTransform.js +0 -92
  162. package/lib/transforms/ValidateRequiredArgumentsTransform.js +0 -114
  163. package/lib/transforms/ValidateServerOnlyDirectivesTransform.js +0 -108
  164. package/lib/transforms/ValidateUnusedVariablesTransform.js +0 -96
  165. package/lib/transforms/query-generators/FetchableQueryGenerator.js +0 -157
  166. package/lib/transforms/query-generators/NodeQueryGenerator.js +0 -166
  167. package/lib/transforms/query-generators/QueryQueryGenerator.js +0 -48
  168. package/lib/transforms/query-generators/ViewerQueryGenerator.js +0 -77
  169. package/lib/transforms/query-generators/index.js +0 -60
  170. package/lib/transforms/query-generators/utils.js +0 -92
  171. package/lib/util/CodeMarker.js +0 -80
  172. package/lib/util/DefaultHandleKey.js +0 -15
  173. package/lib/util/RelayCompilerCache.js +0 -97
  174. package/lib/util/Rollout.js +0 -40
  175. package/lib/util/TimeReporter.js +0 -83
  176. package/lib/util/areEqualArgValues.js +0 -135
  177. package/lib/util/argumentContainsVariables.js +0 -37
  178. package/lib/util/dedupeJSONStringify.js +0 -160
  179. package/lib/util/generateAbstractTypeRefinementKey.js +0 -24
  180. package/lib/util/getDefinitionNodeHash.js +0 -22
  181. package/lib/util/getModuleName.js +0 -32
  182. package/lib/util/joinArgumentDefinitions.js +0 -67
  183. package/lib/util/md5.js +0 -17
  184. package/lib/util/murmurHash.js +0 -86
  185. package/lib/util/nullthrowsOSS.js +0 -23
  186. package/lib/util/orList.js +0 -36
  187. package/lib/util/partitionArray.js +0 -35
  188. package/relay-compiler.js +0 -17
  189. package/relay-compiler.min.js +0 -22
  190. package/reporters/ConsoleReporter.js.flow +0 -81
  191. package/reporters/MultiReporter.js.flow +0 -43
  192. package/reporters/Reporter.js.flow +0 -19
  193. package/runner/Artifacts.js.flow +0 -215
  194. package/runner/BufferedFilesystem.js.flow +0 -194
  195. package/runner/GraphQLASTNodeGroup.js.flow +0 -174
  196. package/runner/GraphQLASTUtils.js.flow +0 -26
  197. package/runner/GraphQLNodeMap.js.flow +0 -55
  198. package/runner/Sources.js.flow +0 -227
  199. package/runner/StrictMap.js.flow +0 -96
  200. package/runner/compileArtifacts.js.flow +0 -75
  201. package/runner/extractAST.js.flow +0 -98
  202. package/runner/getChangedNodeNames.js.flow +0 -48
  203. package/runner/getSchemaInstance.js.flow +0 -36
  204. package/runner/types.js.flow +0 -37
  205. package/test-utils/TestSchema.js.flow +0 -30
  206. package/test-utils/parseGraphQLText.js.flow +0 -41
  207. package/transforms/ApplyFragmentArgumentTransform.js.flow +0 -524
  208. package/transforms/ClientExtensionsTransform.js.flow +0 -224
  209. package/transforms/ConnectionTransform.js.flow +0 -850
  210. package/transforms/DeclarativeConnectionMutationTransform.js.flow +0 -245
  211. package/transforms/DeferStreamTransform.js.flow +0 -263
  212. package/transforms/DisallowIdAsAlias.js.flow +0 -46
  213. package/transforms/DisallowTypenameOnRoot.js.flow +0 -44
  214. package/transforms/FieldHandleTransform.js.flow +0 -77
  215. package/transforms/FilterCompilerDirectivesTransform.js.flow +0 -33
  216. package/transforms/FilterDirectivesTransform.js.flow +0 -45
  217. package/transforms/FlattenTransform.js.flow +0 -458
  218. package/transforms/GenerateIDFieldTransform.js.flow +0 -151
  219. package/transforms/GenerateTypeNameTransform.js.flow +0 -159
  220. package/transforms/InlineDataFragmentTransform.js.flow +0 -123
  221. package/transforms/InlineFragmentsTransform.js.flow +0 -70
  222. package/transforms/MaskTransform.js.flow +0 -124
  223. package/transforms/MatchTransform.js.flow +0 -587
  224. package/transforms/ReactFlightComponentTransform.js.flow +0 -207
  225. package/transforms/RefetchableFragmentTransform.js.flow +0 -266
  226. package/transforms/RelayDirectiveTransform.js.flow +0 -96
  227. package/transforms/RequiredFieldTransform.js.flow +0 -413
  228. package/transforms/SkipClientExtensionsTransform.js.flow +0 -54
  229. package/transforms/SkipHandleFieldTransform.js.flow +0 -44
  230. package/transforms/SkipRedundantNodesTransform.js.flow +0 -277
  231. package/transforms/SkipSplitOperationTransform.js.flow +0 -37
  232. package/transforms/SkipUnreachableNodeTransform.js.flow +0 -148
  233. package/transforms/SkipUnusedVariablesTransform.js.flow +0 -59
  234. package/transforms/SplitModuleImportTransform.js.flow +0 -97
  235. package/transforms/TestOperationTransform.js.flow +0 -142
  236. package/transforms/TransformUtils.js.flow +0 -26
  237. package/transforms/ValidateGlobalVariablesTransform.js.flow +0 -80
  238. package/transforms/ValidateRequiredArgumentsTransform.js.flow +0 -130
  239. package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +0 -128
  240. package/transforms/ValidateUnusedVariablesTransform.js.flow +0 -88
  241. package/transforms/query-generators/FetchableQueryGenerator.js.flow +0 -188
  242. package/transforms/query-generators/NodeQueryGenerator.js.flow +0 -217
  243. package/transforms/query-generators/QueryQueryGenerator.js.flow +0 -57
  244. package/transforms/query-generators/ViewerQueryGenerator.js.flow +0 -97
  245. package/transforms/query-generators/index.js.flow +0 -89
  246. package/transforms/query-generators/utils.js.flow +0 -76
  247. package/util/CodeMarker.js.flow +0 -79
  248. package/util/DefaultHandleKey.js.flow +0 -17
  249. package/util/RelayCompilerCache.js.flow +0 -86
  250. package/util/Rollout.js.flow +0 -39
  251. package/util/TimeReporter.js.flow +0 -79
  252. package/util/areEqualArgValues.js.flow +0 -126
  253. package/util/argumentContainsVariables.js.flow +0 -38
  254. package/util/dedupeJSONStringify.js.flow +0 -156
  255. package/util/generateAbstractTypeRefinementKey.js.flow +0 -29
  256. package/util/getDefinitionNodeHash.js.flow +0 -24
  257. package/util/getModuleName.js.flow +0 -39
  258. package/util/joinArgumentDefinitions.js.flow +0 -105
  259. package/util/md5.js.flow +0 -19
  260. package/util/murmurHash.js.flow +0 -94
  261. package/util/nullthrowsOSS.js.flow +0 -25
  262. package/util/orList.js.flow +0 -37
  263. package/util/partitionArray.js.flow +0 -37
@@ -1,1381 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
- // flowlint ambiguous-object-type:error
11
- 'use strict';
12
-
13
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
14
-
15
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
- var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
18
-
19
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
20
-
21
- var _require = require('../util/DefaultHandleKey'),
22
- DEFAULT_HANDLE_KEY = _require.DEFAULT_HANDLE_KEY;
23
-
24
- var orList = require('../util/orList');
25
-
26
- var partitionArray = require('../util/partitionArray');
27
-
28
- var _require2 = require('./CompilerError'),
29
- createCompilerError = _require2.createCompilerError,
30
- createUserError = _require2.createUserError,
31
- eachWithCombinedError = _require2.eachWithCombinedError;
32
-
33
- var _require3 = require('./getFieldDefinition'),
34
- getFieldDefinitionLegacy = _require3.getFieldDefinitionLegacy;
35
-
36
- var Profiler = require('./GraphQLCompilerProfiler');
37
-
38
- var _require4 = require('./SchemaUtils'),
39
- isExecutableDefinitionAST = _require4.isExecutableDefinitionAST;
40
-
41
- var _require5 = require('graphql'),
42
- Source = _require5.Source,
43
- parseGraphQL = _require5.parse,
44
- parseType = _require5.parseType,
45
- print = _require5.print;
46
-
47
- var ARGUMENT_DEFINITIONS = 'argumentDefinitions';
48
- var ARGUMENTS = 'arguments';
49
- var DEPRECATED_UNCHECKED_ARGUMENTS = 'uncheckedArguments_DEPRECATED';
50
- var DIRECTIVE_WHITELIST = new Set([ARGUMENT_DEFINITIONS, DEPRECATED_UNCHECKED_ARGUMENTS, ARGUMENTS]);
51
- /**
52
- * @internal
53
- *
54
- * This directive is not intended for use by developers directly. To set a field
55
- * handle in product code use a compiler plugin.
56
- */
57
-
58
- var CLIENT_FIELD = '__clientField';
59
- var CLIENT_FIELD_HANDLE = 'handle';
60
- var CLIENT_FIELD_KEY = 'key';
61
- var CLIENT_FIELD_FILTERS = 'filters';
62
- var INCLUDE = 'include';
63
- var SKIP = 'skip';
64
- var IF = 'if';
65
- /**
66
- * Transforms GraphQL text into Relay Compiler's internal, strongly-typed
67
- * intermediate representation (IR).
68
- */
69
-
70
- function parse(schema, text, filename) {
71
- var ast = parseGraphQL(new Source(text, filename));
72
- var parser = new RelayParser(schema.extend(ast), ast.definitions);
73
- return parser.transform();
74
- }
75
- /**
76
- * Transforms untyped GraphQL parse trees (ASTs) into Relay Compiler's
77
- * internal, strongly-typed intermediate representation (IR).
78
- */
79
-
80
-
81
- function transform(schema, definitions) {
82
- return Profiler.run('RelayParser.transform', function () {
83
- var parser = new RelayParser(schema, definitions);
84
- return parser.transform();
85
- });
86
- }
87
- /**
88
- * @private
89
- */
90
-
91
-
92
- var RelayParser = /*#__PURE__*/function () {
93
- function RelayParser(schema, definitions) {
94
- var _this = this;
95
-
96
- this._definitions = new Map(); // leaving this configurable to make it easy to experiment w changing later
97
-
98
- this._getFieldDefinition = getFieldDefinitionLegacy;
99
- this._schema = schema;
100
- var duplicated = new Set();
101
- definitions.forEach(function (def) {
102
- if (isExecutableDefinitionAST(def)) {
103
- var name = getName(def);
104
-
105
- if (_this._definitions.has(name)) {
106
- duplicated.add(name);
107
- return;
108
- }
109
-
110
- _this._definitions.set(name, def);
111
- }
112
- });
113
-
114
- if (duplicated.size) {
115
- throw createUserError('RelayParser: Encountered duplicate definitions for one or more ' + 'documents: each document must have a unique name. Duplicated documents:\n' + Array.from(duplicated, function (name) {
116
- return "- ".concat(name);
117
- }).join('\n'));
118
- }
119
- }
120
-
121
- var _proto = RelayParser.prototype;
122
-
123
- _proto.transform = function transform() {
124
- var _this2 = this;
125
-
126
- var nodes = [];
127
- var entries = new Map(); // Construct a mapping of name to definition ast + variable definitions.
128
- // This allows the subsequent AST -> IR tranformation to reference the
129
- // defined arguments of referenced fragments.
130
-
131
- eachWithCombinedError(this._definitions, function (_ref) {
132
- var name = _ref[0],
133
- definition = _ref[1];
134
-
135
- var variableDefinitions = _this2._buildArgumentDefinitions(definition);
136
-
137
- entries.set(name, {
138
- definition: definition,
139
- variableDefinitions: variableDefinitions
140
- });
141
- }); // Convert the ASTs to IR.
142
-
143
- eachWithCombinedError(entries.values(), function (_ref2) {
144
- var definition = _ref2.definition,
145
- variableDefinitions = _ref2.variableDefinitions;
146
- var node = parseDefinition(_this2._schema, _this2._getFieldDefinition, entries, definition, variableDefinitions);
147
- nodes.push(node);
148
- });
149
- return nodes;
150
- }
151
- /**
152
- * Constructs a mapping of variable names to definitions for the given
153
- * operation/fragment definition.
154
- */
155
- ;
156
-
157
- _proto._buildArgumentDefinitions = function _buildArgumentDefinitions(definition) {
158
- switch (definition.kind) {
159
- case 'OperationDefinition':
160
- return this._buildOperationArgumentDefinitions(definition);
161
-
162
- case 'FragmentDefinition':
163
- return this._buildFragmentArgumentDefinitions(definition);
164
-
165
- default:
166
- definition;
167
- throw createCompilerError("Unexpected ast kind '".concat(definition.kind, "'."), [definition]);
168
- }
169
- }
170
- /**
171
- * Constructs a mapping of variable names to definitions using the
172
- * variables defined in `@argumentDefinitions`.
173
- */
174
- ;
175
-
176
- _proto._buildFragmentArgumentDefinitions = function _buildFragmentArgumentDefinitions(fragment) {
177
- var _this3 = this;
178
-
179
- var variableDirectives = (fragment.directives || []).filter(function (directive) {
180
- return getName(directive) === ARGUMENT_DEFINITIONS;
181
- });
182
-
183
- if (!variableDirectives.length) {
184
- return new Map();
185
- }
186
-
187
- if (variableDirectives.length !== 1) {
188
- throw createUserError("Directive @".concat(ARGUMENT_DEFINITIONS, " may be defined at most once per ") + 'fragment.', null, variableDirectives);
189
- }
190
-
191
- var variableDirective = variableDirectives[0]; // work, below accesses all report arguments could still be null/undefined.
192
-
193
- var args = variableDirective.arguments;
194
-
195
- if (variableDirective == null || !Array.isArray(args)) {
196
- return new Map();
197
- }
198
-
199
- if (!args.length) {
200
- throw createUserError("Directive @".concat(ARGUMENT_DEFINITIONS, " requires arguments: remove the ") + 'directive to skip defining local variables for this fragment.', null, [variableDirective]);
201
- }
202
-
203
- var variables = new Map();
204
- args.forEach(function (arg) {
205
- var _defaultValue$value;
206
-
207
- var argName = getName(arg);
208
- var previousVariable = variables.get(argName);
209
-
210
- if (previousVariable != null) {
211
- throw createUserError("Duplicate definition for variable '$".concat(argName, "'."), null, [previousVariable.ast, arg]);
212
- }
213
-
214
- if (arg.value.kind !== 'ObjectValue') {
215
- throw createUserError("Expected definition for variable '$".concat(argName, "' to be an object ") + "with the shape: '{type: string, defaultValue?: mixed}.", null, [arg.value]);
216
- }
217
-
218
- var defaultValueNode;
219
- var typeString;
220
- arg.value.fields.forEach(function (field) {
221
- var name = getName(field);
222
-
223
- if (name === 'type') {
224
- typeString = transformLiteralValue(field.value, field);
225
- } else if (name === 'defaultValue') {
226
- defaultValueNode = field.value;
227
- } else {
228
- throw createUserError("Expected definition for variable '$".concat(argName, "' to be an object ") + "with the shape: '{type: string, defaultValue?: mixed}.", null, [arg.value]);
229
- }
230
- });
231
-
232
- if (typeof typeString !== 'string') {
233
- throw createUserError("Expected definition for variable '$".concat(argName, "' to be an object ") + "with the shape: '{type: string, defaultValue?: mixed}.", null, [arg.value]);
234
- }
235
-
236
- var typeFromAST = _this3._schema.getTypeFromAST(parseType(typeString));
237
-
238
- if (typeFromAST == null) {
239
- throw createUserError( // $FlowFixMe[incompatible-type]
240
- "Unknown type \"".concat(typeString, "\" referenced in the argument definitions."), null, [arg]);
241
- }
242
-
243
- var type = _this3._schema.asInputType(typeFromAST);
244
-
245
- if (type == null) {
246
- throw createUserError( // $FlowFixMe[incompatible-type]
247
- "Expected type \"".concat(typeString, "\" to be an input type in the \"").concat(arg.name.value, "\" argument definitions."), null, [arg.value]);
248
- }
249
-
250
- var defaultValue = defaultValueNode != null ? transformValue(_this3._schema, defaultValueNode, type, function (variableAst) {
251
- throw createUserError("Expected 'defaultValue' to be a literal, got a variable.", null, [variableAst]);
252
- }) : null;
253
-
254
- if (defaultValue != null && defaultValue.kind !== 'Literal') {
255
- throw createUserError("Expected 'defaultValue' to be a literal, got a variable.", [defaultValue.loc]);
256
- }
257
-
258
- variables.set(argName, {
259
- ast: arg,
260
- defaultValue: (_defaultValue$value = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.value) !== null && _defaultValue$value !== void 0 ? _defaultValue$value : null,
261
- defined: true,
262
- name: argName,
263
- type: type
264
- });
265
- });
266
- return variables;
267
- }
268
- /**
269
- * Constructs a mapping of variable names to definitions using the
270
- * standard GraphQL syntax for variable definitions.
271
- */
272
- ;
273
-
274
- _proto._buildOperationArgumentDefinitions = function _buildOperationArgumentDefinitions(operation) {
275
- var schema = this._schema;
276
- var variableDefinitions = new Map();
277
- (operation.variableDefinitions || []).forEach(function (def) {
278
- var name = getName(def.variable);
279
- var typeFromAST = schema.getTypeFromAST(def.type);
280
-
281
- if (typeFromAST == null) {
282
- throw createUserError("Unknown type: '".concat(getTypeName(def.type), "'."), null, [def.type]);
283
- }
284
-
285
- var type = schema.asInputType(typeFromAST);
286
-
287
- if (type == null) {
288
- throw createUserError("Expected type \"".concat(getTypeName(def.type), "\" to be an input type."), null, [def.type]);
289
- }
290
-
291
- var defaultValue = def.defaultValue ? transformLiteralValue(def.defaultValue, def) : null;
292
- var previousDefinition = variableDefinitions.get(name);
293
-
294
- if (previousDefinition != null) {
295
- throw createUserError("Duplicate definition for variable '$".concat(name, "'."), null, [previousDefinition.ast, def]);
296
- }
297
-
298
- variableDefinitions.set(name, {
299
- ast: def,
300
- defaultValue: defaultValue,
301
- defined: true,
302
- name: name,
303
- type: type
304
- });
305
- });
306
- return variableDefinitions;
307
- };
308
-
309
- return RelayParser;
310
- }();
311
- /**
312
- * @private
313
- */
314
-
315
-
316
- function parseDefinition(schema, getFieldDefinition, entries, definition, variableDefinitions) {
317
- var parser = new GraphQLDefinitionParser(schema, getFieldDefinition, entries, definition, variableDefinitions);
318
- return parser.transform();
319
- }
320
- /**
321
- * @private
322
- */
323
-
324
-
325
- var GraphQLDefinitionParser = /*#__PURE__*/function () {
326
- function GraphQLDefinitionParser(schema, getFieldDefinition, entries, definition, variableDefinitions) {
327
- this._definition = definition;
328
- this._entries = entries;
329
- this._getFieldDefinition = getFieldDefinition;
330
- this._schema = schema;
331
- this._variableDefinitions = variableDefinitions;
332
- this._unknownVariables = new Map();
333
- }
334
-
335
- var _proto2 = GraphQLDefinitionParser.prototype;
336
-
337
- _proto2.transform = function transform() {
338
- var definition = this._definition;
339
-
340
- switch (definition.kind) {
341
- case 'OperationDefinition':
342
- return this._transformOperation(definition);
343
-
344
- case 'FragmentDefinition':
345
- return this._transformFragment(definition);
346
-
347
- default:
348
- definition;
349
- throw createCompilerError("Unsupported definition type ".concat(definition.kind), [definition]);
350
- }
351
- };
352
-
353
- _proto2._recordAndVerifyVariableReference = function _recordAndVerifyVariableReference(variable, name, usedAsType) {
354
- // Special case for variables used in @arguments where we currently
355
- // aren't guaranteed to be able to resolve the type.
356
- if (usedAsType == null) {
357
- if (!this._variableDefinitions.has(name) && !this._unknownVariables.has(name)) {
358
- this._unknownVariables.set(name, {
359
- ast: variable,
360
- type: null
361
- });
362
- }
363
-
364
- return;
365
- }
366
-
367
- var variableDefinition = this._variableDefinitions.get(name);
368
-
369
- if (variableDefinition != null) {
370
- // If the variable is defined, all usages must be compatible
371
- var effectiveType = variableDefinition.type;
372
-
373
- if (variableDefinition.defaultValue != null) {
374
- // If a default value is defined then it is guaranteed to be used
375
- // at runtime such that the effective type of the variable is non-null
376
- effectiveType = this._schema.getNonNullType(this._schema.getNullableType(effectiveType));
377
- }
378
-
379
- if (!this._schema.isTypeSubTypeOf(effectiveType, usedAsType)) {
380
- throw createUserError("Variable '$".concat(name, "' was defined as type '").concat(String(variableDefinition.type), "' but used in a location expecting the type '").concat(String(usedAsType), "'"), null, [variableDefinition.ast, variable]);
381
- }
382
- } else {
383
- var previous = this._unknownVariables.get(name);
384
-
385
- if (!previous || !previous.type) {
386
- // No previous usage, current type is strongest
387
- this._unknownVariables.set(name, {
388
- ast: variable,
389
- type: usedAsType
390
- });
391
- } else {
392
- var previousVariable = previous.ast,
393
- previousType = previous.type;
394
-
395
- if (!(this._schema.isTypeSubTypeOf(usedAsType, previousType) || this._schema.isTypeSubTypeOf(previousType, usedAsType))) {
396
- throw createUserError("Variable '$".concat(name, "' was used in locations expecting the conflicting types '").concat(String(previousType), "' and '").concat(String(usedAsType), "'."), null, [previousVariable, variable]);
397
- } // If the new used type has stronger requirements, use that type as reference,
398
- // otherwise keep referencing the previous type
399
-
400
-
401
- if (this._schema.isTypeSubTypeOf(usedAsType, previousType)) {
402
- this._unknownVariables.set(name, {
403
- ast: variable,
404
- type: usedAsType
405
- });
406
- }
407
- }
408
- }
409
- };
410
-
411
- _proto2._getDirectiveLocations = function _getDirectiveLocations() {
412
- if (!this._directiveLocations) {
413
- var directiveDefs = this._schema.getDirectives();
414
-
415
- this._directiveLocations = new Map();
416
-
417
- var _iterator = (0, _createForOfIteratorHelper2["default"])(directiveDefs),
418
- _step;
419
-
420
- try {
421
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
422
- var def = _step.value;
423
-
424
- this._directiveLocations.set(def.name, def.locations);
425
- }
426
- } catch (err) {
427
- _iterator.e(err);
428
- } finally {
429
- _iterator.f();
430
- }
431
- }
432
-
433
- return this._directiveLocations;
434
- };
435
-
436
- _proto2._validateDirectivesLocation = function _validateDirectivesLocation(directives, allowedLocaction) {
437
- if (!directives || !directives.length) {
438
- return;
439
- }
440
-
441
- var directiveLocs = this._getDirectiveLocations();
442
-
443
- var mismatches = directives.filter(function (directive) {
444
- var name = getName(directive);
445
-
446
- if (DIRECTIVE_WHITELIST.has(name)) {
447
- return false;
448
- }
449
-
450
- var locs = directiveLocs.get(name);
451
-
452
- if (locs == null) {
453
- throw createUserError("Unknown directive '".concat(name, "'."), null, [directive]);
454
- }
455
-
456
- return !locs.some(function (loc) {
457
- return loc === allowedLocaction;
458
- });
459
- });
460
-
461
- if (mismatches.length) {
462
- var invalidDirectives = mismatches.map(function (directive) {
463
- return '@' + getName(directive);
464
- }).join(', ');
465
- throw createUserError("Invalid directives ".concat(invalidDirectives, " found on ").concat(allowedLocaction, "."), null, mismatches);
466
- }
467
- };
468
-
469
- _proto2._transformFragment = function _transformFragment(fragment) {
470
- var directives = this._transformDirectives((fragment.directives || []).filter(function (directive) {
471
- return getName(directive) !== ARGUMENT_DEFINITIONS;
472
- }), 'FRAGMENT_DEFINITION');
473
-
474
- var typeFromAST = this._schema.getTypeFromAST(fragment.typeCondition);
475
-
476
- if (typeFromAST == null) {
477
- throw createUserError("Fragment \"".concat(fragment.name.value, "\" cannot condition on unknown ") + "type \"".concat(String(fragment.typeCondition.name.value), "\"."), null, [fragment.typeCondition]);
478
- }
479
-
480
- var type = this._schema.asCompositeType(typeFromAST);
481
-
482
- if (type == null) {
483
- throw createUserError("Fragment \"".concat(fragment.name.value, "\" cannot condition on non composite ") + "type \"".concat(String(type), "\"."), null, [fragment.typeCondition]);
484
- }
485
-
486
- var selections = this._transformSelections(fragment.selectionSet, type, fragment.typeCondition);
487
-
488
- var argumentDefinitions = (0, _toConsumableArray2["default"])(buildArgumentDefinitions(this._variableDefinitions));
489
-
490
- var _iterator2 = (0, _createForOfIteratorHelper2["default"])(this._unknownVariables),
491
- _step2;
492
-
493
- try {
494
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
495
- var _step2$value = _step2.value,
496
- name = _step2$value[0],
497
- variableReference = _step2$value[1];
498
- argumentDefinitions.push({
499
- kind: 'RootArgumentDefinition',
500
- loc: buildLocation(variableReference.ast.loc),
501
- name: name,
502
- type: variableReference.type
503
- });
504
- }
505
- } catch (err) {
506
- _iterator2.e(err);
507
- } finally {
508
- _iterator2.f();
509
- }
510
-
511
- return {
512
- kind: 'Fragment',
513
- directives: directives,
514
- loc: buildLocation(fragment.loc),
515
- metadata: null,
516
- name: getName(fragment),
517
- selections: selections,
518
- type: type,
519
- // $FlowFixMe[incompatible-return] - could be null
520
- argumentDefinitions: argumentDefinitions
521
- };
522
- };
523
-
524
- _proto2._getLocationFromOperation = function _getLocationFromOperation(definition) {
525
- switch (definition.operation) {
526
- case 'query':
527
- return 'QUERY';
528
-
529
- case 'mutation':
530
- return 'MUTATION';
531
-
532
- case 'subscription':
533
- return 'SUBSCRIPTION';
534
-
535
- default:
536
- definition.operation;
537
- throw createCompilerError("Unknown operation type '".concat(definition.operation, "'."), null, [definition]);
538
- }
539
- };
540
-
541
- _proto2._transformOperation = function _transformOperation(definition) {
542
- var name = getName(definition);
543
-
544
- var directives = this._transformDirectives(definition.directives || [], this._getLocationFromOperation(definition));
545
-
546
- var type;
547
- var operation;
548
- var schema = this._schema;
549
-
550
- switch (definition.operation) {
551
- case 'query':
552
- operation = 'query';
553
- type = schema.expectQueryType();
554
- break;
555
-
556
- case 'mutation':
557
- operation = 'mutation';
558
- type = schema.expectMutationType();
559
- break;
560
-
561
- case 'subscription':
562
- operation = 'subscription';
563
- type = schema.expectSubscriptionType();
564
- break;
565
-
566
- default:
567
- definition.operation;
568
- throw createCompilerError("Unknown operation type '".concat(definition.operation, "'."), null, [definition]);
569
- }
570
-
571
- if (!definition.selectionSet) {
572
- throw createUserError('Expected operation to have selections.', null, [definition]);
573
- }
574
-
575
- var selections = this._transformSelections(definition.selectionSet, type);
576
-
577
- var argumentDefinitions = buildArgumentDefinitions(this._variableDefinitions);
578
-
579
- if (this._unknownVariables.size !== 0) {
580
- throw createUserError("Query '".concat(name, "' references undefined variables."), null, Array.from(this._unknownVariables.values(), function (variableReference) {
581
- return variableReference.ast;
582
- }));
583
- }
584
-
585
- return {
586
- kind: 'Root',
587
- operation: operation,
588
- loc: buildLocation(definition.loc),
589
- metadata: null,
590
- name: name,
591
- argumentDefinitions: argumentDefinitions,
592
- directives: directives,
593
- selections: selections,
594
- type: type
595
- };
596
- };
597
-
598
- _proto2._transformSelections = function _transformSelections(selectionSet, parentType, parentTypeAST) {
599
- var _this4 = this;
600
-
601
- return selectionSet.selections.map(function (selection) {
602
- var node;
603
-
604
- if (selection.kind === 'Field') {
605
- node = _this4._transformField(selection, parentType);
606
- } else if (selection.kind === 'FragmentSpread') {
607
- node = _this4._transformFragmentSpread(selection, parentType, parentTypeAST);
608
- } else if (selection.kind === 'InlineFragment') {
609
- node = _this4._transformInlineFragment(selection, parentType, parentTypeAST);
610
- } else {
611
- selection.kind;
612
- throw createCompilerError("Unknown ast kind '".concat(selection.kind, "'."), [selection]);
613
- }
614
-
615
- var _this4$_splitConditio = _this4._splitConditions(node.directives),
616
- conditions = _this4$_splitConditio[0],
617
- directives = _this4$_splitConditio[1];
618
-
619
- var conditionalNodes = applyConditions(conditions, // $FlowFixMe[incompatible-call]
620
- [(0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
621
- directives: directives
622
- })]);
623
-
624
- if (conditionalNodes.length !== 1) {
625
- throw createCompilerError('Expected exactly one condition node.', null, selection.directives);
626
- }
627
-
628
- return conditionalNodes[0];
629
- });
630
- };
631
-
632
- _proto2._transformInlineFragment = function _transformInlineFragment(fragment, parentType, parentTypeAST) {
633
- var schema = this._schema;
634
- var typeCondition = fragment.typeCondition != null ? schema.getTypeFromAST(fragment.typeCondition) : parentType;
635
-
636
- if (typeCondition == null) {
637
- var _fragment$typeConditi;
638
-
639
- throw createUserError('Inline fragments can only be on object, interface or union types' + ", got unknown type '".concat(getTypeName(fragment.typeCondition), "'."), null, [(_fragment$typeConditi = fragment.typeCondition) !== null && _fragment$typeConditi !== void 0 ? _fragment$typeConditi : fragment]);
640
- }
641
-
642
- var typeConditionName = schema.getTypeString(typeCondition);
643
- typeCondition = schema.asCompositeType(typeCondition);
644
-
645
- if (typeCondition == null) {
646
- var _fragment$typeConditi2;
647
-
648
- throw createUserError('Inline fragments can only be on object, interface or union types' + ", got '".concat(typeConditionName, "'."), null, [(_fragment$typeConditi2 = fragment.typeCondition) !== null && _fragment$typeConditi2 !== void 0 ? _fragment$typeConditi2 : fragment]);
649
- }
650
-
651
- var rawParentType = this._schema.assertCompositeType(this._schema.getRawType(parentType));
652
-
653
- checkFragmentSpreadTypeCompatibility(this._schema, typeCondition, rawParentType, null, fragment.typeCondition, parentTypeAST);
654
-
655
- var directives = this._transformDirectives(fragment.directives || [], 'INLINE_FRAGMENT');
656
-
657
- var selections = this._transformSelections(fragment.selectionSet, typeCondition, fragment.typeCondition);
658
-
659
- return {
660
- kind: 'InlineFragment',
661
- directives: directives,
662
- loc: buildLocation(fragment.loc),
663
- metadata: null,
664
- selections: selections,
665
- typeCondition: typeCondition
666
- };
667
- };
668
-
669
- _proto2._transformFragmentSpread = function _transformFragmentSpread(fragmentSpread, parentType, parentTypeAST) {
670
- var _this5 = this;
671
-
672
- var fragmentName = getName(fragmentSpread);
673
-
674
- var _partitionArray = partitionArray(fragmentSpread.directives || [], function (directive) {
675
- var name = getName(directive);
676
- return name === ARGUMENTS || name === DEPRECATED_UNCHECKED_ARGUMENTS;
677
- }),
678
- argumentDirectives = _partitionArray[0],
679
- otherDirectives = _partitionArray[1];
680
-
681
- if (argumentDirectives.length > 1) {
682
- throw createUserError("Directive @".concat(ARGUMENTS, " may be used at most once per a fragment spread."), null, argumentDirectives);
683
- }
684
-
685
- var fragmentDefinition = this._entries.get(fragmentName);
686
-
687
- if (fragmentDefinition == null) {
688
- throw createUserError("Unknown fragment '".concat(fragmentName, "'."), null, [fragmentSpread.name]);
689
- }
690
-
691
- var fragmentTypeNode = getFragmentType(fragmentDefinition.definition);
692
-
693
- var fragmentType = this._schema.assertCompositeType(this._schema.expectTypeFromAST(fragmentTypeNode));
694
-
695
- var rawParentType = this._schema.assertCompositeType(this._schema.getRawType(parentType));
696
-
697
- checkFragmentSpreadTypeCompatibility(this._schema, fragmentType, rawParentType, fragmentSpread.name.value, fragmentSpread, parentTypeAST);
698
- var fragmentArgumentDefinitions = fragmentDefinition.variableDefinitions;
699
- var argumentsDirective = argumentDirectives[0];
700
- var args;
701
-
702
- if (argumentsDirective != null) {
703
- var isDeprecatedUncheckedArguments = getName(argumentsDirective) === DEPRECATED_UNCHECKED_ARGUMENTS;
704
- var hasInvalidArgument = false;
705
- args = (argumentsDirective.arguments || []).map(function (arg) {
706
- var _argumentDefinition$t;
707
-
708
- var argName = getName(arg);
709
- var argValue = arg.value;
710
- var argumentDefinition = fragmentArgumentDefinitions.get(argName);
711
- var argumentType = (_argumentDefinition$t = argumentDefinition === null || argumentDefinition === void 0 ? void 0 : argumentDefinition.type) !== null && _argumentDefinition$t !== void 0 ? _argumentDefinition$t : null;
712
-
713
- if (argValue.kind === 'Variable') {
714
- if (argumentDefinition == null && !isDeprecatedUncheckedArguments) {
715
- throw createUserError("Variable @".concat(ARGUMENTS, " values are only supported when the ") + "argument is defined with @".concat(ARGUMENT_DEFINITIONS, ". Check ") + "the definition of fragment '".concat(fragmentName, "'."), null, [arg.value, fragmentDefinition.definition]);
716
- }
717
-
718
- hasInvalidArgument = hasInvalidArgument || argumentDefinition == null; // TODO: check the type of the variable and use the type
719
-
720
- return {
721
- kind: 'Argument',
722
- loc: buildLocation(arg.loc),
723
- name: argName,
724
- value: _this5._transformVariable(argValue, null),
725
- type: null
726
- };
727
- } else {
728
- if (argumentType == null) {
729
- throw createUserError("Literal @".concat(ARGUMENTS, " values are only supported when the ") + "argument is defined with @".concat(ARGUMENT_DEFINITIONS, ". Check ") + "the definition of fragment '".concat(fragmentName, "'."), null, [arg.value, fragmentDefinition.definition]);
730
- }
731
-
732
- var value = _this5._transformValue(argValue, argumentType);
733
-
734
- return {
735
- kind: 'Argument',
736
- loc: buildLocation(arg.loc),
737
- name: argName,
738
- value: value,
739
- type: argumentType
740
- };
741
- }
742
- });
743
-
744
- if (isDeprecatedUncheckedArguments && !hasInvalidArgument) {
745
- throw createUserError("Invalid use of @".concat(DEPRECATED_UNCHECKED_ARGUMENTS, ": all arguments ") + "are defined, use @".concat(ARGUMENTS, " instead."), null, [argumentsDirective]);
746
- }
747
- }
748
-
749
- var directives = this._transformDirectives(otherDirectives, 'FRAGMENT_SPREAD');
750
-
751
- return {
752
- kind: 'FragmentSpread',
753
- args: args || [],
754
- metadata: null,
755
- loc: buildLocation(fragmentSpread.loc),
756
- name: fragmentName,
757
- directives: directives
758
- };
759
- };
760
-
761
- _proto2._transformField = function _transformField(field, parentType) {
762
- var _field$alias$value, _field$alias;
763
-
764
- var schema = this._schema;
765
- var name = getName(field);
766
-
767
- var fieldDef = this._getFieldDefinition(schema, parentType, name, field);
768
-
769
- if (fieldDef == null) {
770
- throw createUserError("Unknown field '".concat(name, "' on type '").concat(schema.getTypeString(parentType), "'."), null, [field]);
771
- }
772
-
773
- var alias = (_field$alias$value = (_field$alias = field.alias) === null || _field$alias === void 0 ? void 0 : _field$alias.value) !== null && _field$alias$value !== void 0 ? _field$alias$value : name;
774
-
775
- var args = this._transformArguments(field.arguments || [], schema.getFieldArgs(fieldDef), fieldDef);
776
-
777
- var _partitionArray2 = partitionArray(field.directives || [], function (directive) {
778
- return getName(directive) !== CLIENT_FIELD;
779
- }),
780
- otherDirectives = _partitionArray2[0],
781
- clientFieldDirectives = _partitionArray2[1];
782
-
783
- var directives = this._transformDirectives(otherDirectives, 'FIELD');
784
-
785
- var type = schema.getFieldType(fieldDef);
786
-
787
- var handles = this._transformHandle(name, args, clientFieldDirectives);
788
-
789
- if (schema.isLeafType(schema.getRawType(type))) {
790
- if (field.selectionSet && field.selectionSet.selections && field.selectionSet.selections.length) {
791
- throw createUserError("Expected no selections for scalar field '".concat(name, "'."), null, [field]);
792
- }
793
-
794
- return {
795
- kind: 'ScalarField',
796
- alias: alias,
797
- args: args,
798
- directives: directives,
799
- handles: handles,
800
- loc: buildLocation(field.loc),
801
- metadata: null,
802
- name: name,
803
- type: schema.assertScalarFieldType(type)
804
- };
805
- } else {
806
- var selections = field.selectionSet ? this._transformSelections(field.selectionSet, type) : null;
807
-
808
- if (selections == null || selections.length === 0) {
809
- throw createUserError("Expected at least one selection for non-scalar field '".concat(name, "' on type '").concat(schema.getTypeString(type), "'."), null, [field]);
810
- }
811
-
812
- return {
813
- kind: 'LinkedField',
814
- alias: alias,
815
- args: args,
816
- connection: false,
817
- directives: directives,
818
- handles: handles,
819
- loc: buildLocation(field.loc),
820
- metadata: null,
821
- name: name,
822
- selections: selections,
823
- type: schema.assertLinkedFieldType(type)
824
- };
825
- }
826
- };
827
-
828
- _proto2._transformHandle = function _transformHandle(fieldName, fieldArgs, clientFieldDirectives) {
829
- var handles = null;
830
- clientFieldDirectives.forEach(function (clientFieldDirective) {
831
- var handleArgument = (clientFieldDirective.arguments || []).find(function (arg) {
832
- return getName(arg) === CLIENT_FIELD_HANDLE;
833
- });
834
-
835
- if (handleArgument) {
836
- var name = null;
837
- var key = DEFAULT_HANDLE_KEY;
838
- var filters = null;
839
- var maybeHandle = transformLiteralValue(handleArgument.value, handleArgument);
840
-
841
- if (typeof maybeHandle !== 'string') {
842
- throw createUserError("Expected a string literal argument for the @".concat(CLIENT_FIELD, " directive."), null, [handleArgument.value]);
843
- }
844
-
845
- name = maybeHandle;
846
- var keyArgument = (clientFieldDirective.arguments || []).find(function (arg) {
847
- return getName(arg) === CLIENT_FIELD_KEY;
848
- });
849
-
850
- if (keyArgument) {
851
- var maybeKey = transformLiteralValue(keyArgument.value, keyArgument);
852
-
853
- if (typeof maybeKey !== 'string') {
854
- throw createUserError("Expected a string literal argument for the @".concat(CLIENT_FIELD, " directive."), null, [keyArgument.value]);
855
- }
856
-
857
- key = maybeKey;
858
- }
859
-
860
- var filtersArgument = (clientFieldDirective.arguments || []).find(function (arg) {
861
- return getName(arg) === CLIENT_FIELD_FILTERS;
862
- });
863
-
864
- if (filtersArgument) {
865
- var maybeFilters = transformLiteralValue(filtersArgument.value, filtersArgument);
866
-
867
- if (!(Array.isArray(maybeFilters) && maybeFilters.every(function (filter) {
868
- return typeof filter === 'string' && fieldArgs.some(function (fieldArg) {
869
- return fieldArg.name === filter;
870
- });
871
- }))) {
872
- throw createUserError("Expected an array of argument names on field '".concat(fieldName, "'."), null, [filtersArgument.value]);
873
- } // $FlowFixMe[incompatible-cast]
874
-
875
-
876
- filters = maybeFilters;
877
- }
878
-
879
- var dynamicKeyArgument = (clientFieldDirective.arguments || []).find(function (arg) {
880
- return getName(arg) === 'dynamicKey_UNSTABLE';
881
- });
882
-
883
- if (dynamicKeyArgument != null) {
884
- throw createUserError('Dynamic keys are only supported with @connection.', null, [dynamicKeyArgument.value]);
885
- }
886
-
887
- handles = handles || [];
888
- handles.push({
889
- name: name,
890
- key: key,
891
- filters: filters,
892
- dynamicKey: null
893
- });
894
- }
895
- });
896
- return handles;
897
- };
898
-
899
- _proto2._transformDirectives = function _transformDirectives(directives, location) {
900
- var _this6 = this;
901
-
902
- this._validateDirectivesLocation(directives, location);
903
-
904
- return directives.map(function (directive) {
905
- var name = getName(directive);
906
-
907
- var directiveDef = _this6._schema.getDirective(name);
908
-
909
- if (directiveDef == null) {
910
- throw createUserError("Unknown directive '".concat(name, "'."), null, [directive]);
911
- }
912
-
913
- var args = _this6._transformArguments(directive.arguments || [], directiveDef.args.map(function (item) {
914
- return {
915
- name: item.name,
916
- type: item.type,
917
- defaultValue: item.defaultValue
918
- };
919
- }), null, name);
920
-
921
- return {
922
- kind: 'Directive',
923
- loc: buildLocation(directive.loc),
924
- name: name,
925
- args: args
926
- };
927
- });
928
- };
929
-
930
- _proto2._transformArguments = function _transformArguments(args, argumentDefinitions, field, directiveName) {
931
- var _this7 = this;
932
-
933
- return args.map(function (arg) {
934
- var argName = getName(arg);
935
- var argDef = argumentDefinitions.find(function (def) {
936
- return def.name === argName;
937
- });
938
-
939
- if (argDef == null) {
940
- var message = "Unknown argument '".concat(argName, "'") + (field ? " on field '".concat(_this7._schema.getFieldName(field), "'") + " of type '".concat(_this7._schema.getTypeString(_this7._schema.getFieldParentType(field)), "'.") : directiveName != null ? " on directive '@".concat(directiveName, "'.") : '.');
941
- throw createUserError(message, null, [arg]);
942
- }
943
-
944
- var value = _this7._transformValue(arg.value, argDef.type);
945
-
946
- return {
947
- kind: 'Argument',
948
- loc: buildLocation(arg.loc),
949
- name: argName,
950
- value: value,
951
- type: argDef.type
952
- };
953
- });
954
- };
955
-
956
- _proto2._splitConditions = function _splitConditions(mixedDirectives) {
957
- var _partitionArray3 = partitionArray(mixedDirectives, function (directive) {
958
- return directive.name === INCLUDE || directive.name === SKIP;
959
- }),
960
- conditionDirectives = _partitionArray3[0],
961
- otherDirectives = _partitionArray3[1];
962
-
963
- var conditions = conditionDirectives.map(function (directive) {
964
- var passingValue = directive.name === INCLUDE;
965
- var arg = directive.args[0];
966
-
967
- if (arg == null || arg.name !== IF) {
968
- throw createUserError("Expected an 'if' argument to @".concat(directive.name, "."), [directive.loc]);
969
- }
970
-
971
- if (!(arg.value.kind === 'Variable' || arg.value.kind === 'Literal')) {
972
- throw createUserError("Expected the 'if' argument to @".concat(directive.name, " to be a variable or literal."), [directive.loc]);
973
- }
974
-
975
- return {
976
- kind: 'Condition',
977
- condition: arg.value,
978
- loc: directive.loc,
979
- passingValue: passingValue,
980
- selections: []
981
- };
982
- });
983
- var sortedConditions = conditions.sort(function (a, b) {
984
- if (a.condition.kind === 'Variable' && b.condition.kind === 'Variable') {
985
- return a.condition.variableName < b.condition.variableName ? -1 : a.condition.variableName > b.condition.variableName ? 1 : 0;
986
- } else {
987
- // sort literals earlier, variables later
988
- return a.condition.kind === 'Variable' ? 1 : b.condition.kind === 'Variable' ? -1 : 0;
989
- }
990
- });
991
- return [sortedConditions, otherDirectives];
992
- };
993
-
994
- _proto2._transformVariable = function _transformVariable(ast, usedAsType) {
995
- var variableName = getName(ast);
996
-
997
- this._recordAndVerifyVariableReference(ast, variableName, usedAsType);
998
-
999
- return {
1000
- kind: 'Variable',
1001
- loc: buildLocation(ast.loc),
1002
- variableName: variableName,
1003
- type: usedAsType
1004
- };
1005
- };
1006
-
1007
- _proto2._transformValue = function _transformValue(ast, type) {
1008
- var _this8 = this;
1009
-
1010
- return transformValue(this._schema, ast, type, function (variableAst, variableType) {
1011
- return _this8._transformVariable(variableAst, variableType);
1012
- });
1013
- };
1014
-
1015
- return GraphQLDefinitionParser;
1016
- }();
1017
- /**
1018
- * Transforms and validates argument values according to the expected
1019
- * type.
1020
- */
1021
-
1022
-
1023
- function transformValue(schema, ast, type, transformVariable) {
1024
- if (ast.kind === 'Variable') {
1025
- // Special case variables since there is no value to parse
1026
- return transformVariable(ast, type);
1027
- } else if (ast.kind === 'NullValue') {
1028
- // Special case null literals since there is no value to parse
1029
- if (schema.isNonNull(type)) {
1030
- throw createUserError("Expected a value matching type '".concat(String(type), "'."), null, [ast]);
1031
- }
1032
-
1033
- return {
1034
- kind: 'Literal',
1035
- loc: buildLocation(ast.loc),
1036
- value: null
1037
- };
1038
- } else {
1039
- return transformNonNullLiteral(schema, ast, type, transformVariable);
1040
- }
1041
- }
1042
- /**
1043
- * Transforms and validates non-null literal (non-variable) values
1044
- * according to the expected type.
1045
- */
1046
-
1047
-
1048
- function transformNonNullLiteral(schema, ast, type, transformVariable) {
1049
- // Transform the value based on the type without a non-null wrapper.
1050
- // Note that error messages should still use the original `type`
1051
- // since that accurately describes to the user what the expected
1052
- // type is (using nullableType would suggest that `null` is legal
1053
- // even when it may not be, for example).
1054
- var nullableType = schema.getNullableType(type);
1055
-
1056
- if (schema.isList(nullableType)) {
1057
- if (ast.kind !== 'ListValue') {
1058
- // Parse singular (non-list) values flowing into a list type
1059
- // as scalars, ie without wrapping them in an array.
1060
- if (!schema.isInputType(schema.getListItemType(nullableType))) {
1061
- throw createUserError("Expected type ".concat(schema.getTypeString(nullableType), " to be an input type."), null, [ast]);
1062
- }
1063
-
1064
- return transformValue(schema, ast, schema.assertInputType(schema.getListItemType(nullableType)), transformVariable);
1065
- }
1066
-
1067
- var itemType = schema.assertInputType(schema.getListItemType(nullableType));
1068
- var literalList = [];
1069
- var items = [];
1070
- var areAllItemsScalar = true;
1071
- ast.values.forEach(function (item) {
1072
- var itemValue = transformValue(schema, item, itemType, transformVariable);
1073
-
1074
- if (itemValue.kind === 'Literal') {
1075
- literalList.push(itemValue.value);
1076
- }
1077
-
1078
- items.push(itemValue);
1079
- areAllItemsScalar = areAllItemsScalar && itemValue.kind === 'Literal';
1080
- });
1081
-
1082
- if (areAllItemsScalar) {
1083
- return {
1084
- kind: 'Literal',
1085
- loc: buildLocation(ast.loc),
1086
- value: literalList
1087
- };
1088
- } else {
1089
- return {
1090
- kind: 'ListValue',
1091
- loc: buildLocation(ast.loc),
1092
- items: items
1093
- };
1094
- }
1095
- } else if (schema.isInputObject(nullableType)) {
1096
- if (ast.kind !== 'ObjectValue') {
1097
- throw createUserError("Expected a value matching type '".concat(schema.getTypeString(type), "'."), null, [ast]);
1098
- }
1099
-
1100
- var literalObject = {};
1101
- var fields = [];
1102
- var areAllFieldsScalar = true;
1103
- var inputType = schema.assertInputObjectType(nullableType);
1104
- var requiredFieldNames = new Set(schema.getFields(inputType).filter(function (field) {
1105
- return schema.isNonNull(schema.getFieldType(field));
1106
- }).map(function (field) {
1107
- return schema.getFieldName(field);
1108
- }));
1109
- var seenFields = new Map();
1110
- ast.fields.forEach(function (field) {
1111
- var fieldName = getName(field);
1112
- var seenField = seenFields.get(fieldName);
1113
-
1114
- if (seenField) {
1115
- throw createUserError("Duplicated field name '".concat(fieldName, "' in the input object."), null, [field, seenField]);
1116
- }
1117
-
1118
- var fieldID = schema.getFieldByName(inputType, fieldName);
1119
-
1120
- if (!fieldID) {
1121
- throw createUserError("Unknown field '".concat(fieldName, "' on type '").concat(schema.getTypeString(inputType), "'."), null, [field]);
1122
- }
1123
-
1124
- var fieldConfig = schema.getFieldConfig(fieldID);
1125
- var fieldType = schema.assertInputType(fieldConfig.type);
1126
- var fieldValue = transformValue(schema, field.value, fieldType, transformVariable);
1127
-
1128
- if (fieldValue.kind === 'Literal') {
1129
- literalObject[field.name.value] = fieldValue.value;
1130
- }
1131
-
1132
- fields.push({
1133
- kind: 'ObjectFieldValue',
1134
- loc: buildLocation(field.loc),
1135
- name: fieldName,
1136
- value: fieldValue
1137
- });
1138
- seenFields.set(fieldName, field);
1139
- requiredFieldNames["delete"](fieldName);
1140
- areAllFieldsScalar = areAllFieldsScalar && fieldValue.kind === 'Literal';
1141
- });
1142
-
1143
- if (requiredFieldNames.size > 0) {
1144
- var requiredFieldStr = Array.from(requiredFieldNames).map(function (item) {
1145
- return "'".concat(item, "'");
1146
- }).join(', ');
1147
- throw createUserError("Missing non-optional field".concat(requiredFieldNames.size > 1 ? 's:' : '', " ").concat(requiredFieldStr, " for input type '").concat(schema.getTypeString(inputType), "'."), null, [ast]);
1148
- }
1149
-
1150
- if (areAllFieldsScalar) {
1151
- return {
1152
- kind: 'Literal',
1153
- loc: buildLocation(ast.loc),
1154
- value: literalObject
1155
- };
1156
- } else {
1157
- return {
1158
- kind: 'ObjectValue',
1159
- loc: buildLocation(ast.loc),
1160
- fields: fields
1161
- };
1162
- }
1163
- } else if (schema.isId(nullableType)) {
1164
- // GraphQLID's parseLiteral() always returns the string value. However
1165
- // the int/string distinction may be important at runtime, so this
1166
- // transform parses int/string literals into the corresponding JS types.
1167
- if (ast.kind === 'IntValue') {
1168
- return {
1169
- kind: 'Literal',
1170
- loc: buildLocation(ast.loc),
1171
- value: parseInt(ast.value, 10)
1172
- };
1173
- } else if (ast.kind === 'StringValue') {
1174
- return {
1175
- kind: 'Literal',
1176
- loc: buildLocation(ast.loc),
1177
- value: ast.value
1178
- };
1179
- } else {
1180
- throw createUserError("Invalid value, expected a value matching type '".concat(schema.getTypeString(type), "'."), null, [ast]);
1181
- }
1182
- } else if (schema.isEnum(nullableType)) {
1183
- var enumType = schema.assertEnumType(nullableType);
1184
- var value = schema.parseLiteral(enumType, ast);
1185
-
1186
- if (value == null) {
1187
- var suggestions = schema.getEnumValues(enumType); // parseLiteral() should return a non-null JavaScript value
1188
- // if the ast value is valid for the type.
1189
-
1190
- throw createUserError("Expected a value matching type '".concat(schema.getTypeString(type), "'. Possible values: ").concat(orList(suggestions), "?'"), null, [ast]);
1191
- }
1192
-
1193
- return {
1194
- kind: 'Literal',
1195
- loc: buildLocation(ast.loc),
1196
- value: value
1197
- };
1198
- } else if (schema.isScalar(nullableType)) {
1199
- var _value = schema.parseLiteral(schema.assertScalarType(nullableType), ast);
1200
-
1201
- if (_value == null) {
1202
- // parseLiteral() should return a non-null JavaScript value
1203
- // if the ast value is valid for the type.
1204
- throw createUserError("Expected a value matching type '".concat(schema.getTypeString(type), "'."), null, [ast]);
1205
- }
1206
-
1207
- return {
1208
- kind: 'Literal',
1209
- loc: buildLocation(ast.loc),
1210
- value: _value
1211
- };
1212
- } else {
1213
- throw createCompilerError("Unsupported type '".concat(schema.getTypeString(type), "' for input value, expected a GraphQLList, ") + 'GraphQLInputObjectType, GraphQLEnumType, or GraphQLScalarType.', null, [ast]);
1214
- }
1215
- }
1216
- /**
1217
- * @private
1218
- */
1219
-
1220
-
1221
- function transformLiteralValue(ast, context) {
1222
- switch (ast.kind) {
1223
- case 'IntValue':
1224
- return parseInt(ast.value, 10);
1225
-
1226
- case 'FloatValue':
1227
- return parseFloat(ast.value);
1228
-
1229
- case 'StringValue':
1230
- return ast.value;
1231
-
1232
- case 'BooleanValue':
1233
- // Note: duplicated because Flow does not understand fall-through cases
1234
- return ast.value;
1235
-
1236
- case 'EnumValue':
1237
- // Note: duplicated because Flow does not understand fall-through cases
1238
- return ast.value;
1239
-
1240
- case 'ListValue':
1241
- return ast.values.map(function (item) {
1242
- return transformLiteralValue(item, context);
1243
- });
1244
-
1245
- case 'NullValue':
1246
- return null;
1247
-
1248
- case 'ObjectValue':
1249
- {
1250
- var objectValue = {};
1251
- ast.fields.forEach(function (field) {
1252
- var fieldName = getName(field);
1253
- var value = transformLiteralValue(field.value, context);
1254
- objectValue[fieldName] = value;
1255
- });
1256
- return objectValue;
1257
- }
1258
-
1259
- case 'Variable':
1260
- throw createUserError('Unexpected variable where a literal (static) value is required.', null, [ast, context]);
1261
-
1262
- default:
1263
- ast.kind;
1264
- throw createCompilerError("Unknown ast kind '".concat(ast.kind, "'."), [ast]);
1265
- }
1266
- }
1267
- /**
1268
- * @private
1269
- */
1270
-
1271
-
1272
- function buildArgumentDefinitions(variables) {
1273
- return Array.from(variables.values(), function (_ref3) {
1274
- var ast = _ref3.ast,
1275
- name = _ref3.name,
1276
- defaultValue = _ref3.defaultValue,
1277
- type = _ref3.type;
1278
- return {
1279
- kind: 'LocalArgumentDefinition',
1280
- loc: buildLocation(ast.loc),
1281
- name: name,
1282
- type: type,
1283
- defaultValue: defaultValue
1284
- };
1285
- });
1286
- }
1287
- /**
1288
- * @private
1289
- */
1290
-
1291
-
1292
- function buildLocation(loc) {
1293
- if (loc == null) {
1294
- return {
1295
- kind: 'Unknown'
1296
- };
1297
- }
1298
-
1299
- return {
1300
- kind: 'Source',
1301
- start: loc.start,
1302
- end: loc.end,
1303
- source: loc.source
1304
- };
1305
- }
1306
- /**
1307
- * @private
1308
- */
1309
-
1310
-
1311
- function applyConditions(conditions, selections) {
1312
- var nextSelections = selections;
1313
- conditions.forEach(function (condition) {
1314
- nextSelections = [(0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, condition), {}, {
1315
- selections: nextSelections
1316
- })];
1317
- });
1318
- return nextSelections;
1319
- }
1320
- /**
1321
- * @private
1322
- */
1323
-
1324
-
1325
- function getName(ast) {
1326
- var _ast$name;
1327
-
1328
- var name = (_ast$name = ast.name) === null || _ast$name === void 0 ? void 0 : _ast$name.value;
1329
-
1330
- if (typeof name !== 'string') {
1331
- throw createCompilerError("Expected ast node to have a 'name'.", null, [ast]);
1332
- }
1333
-
1334
- return name;
1335
- }
1336
-
1337
- function getTypeName(ast) {
1338
- return ast ? print(ast) : 'Undefined Type Name';
1339
- }
1340
- /**
1341
- * @private
1342
- */
1343
-
1344
-
1345
- function getFragmentType(ast) {
1346
- if (ast.kind === 'FragmentDefinition') {
1347
- return ast.typeCondition;
1348
- }
1349
-
1350
- throw createCompilerError('Expected ast node to be a FragmentDefinition node.', null, [ast]);
1351
- }
1352
-
1353
- function checkFragmentSpreadTypeCompatibility(schema, fragmentType, parentType, fragmentName, fragmentTypeAST, parentTypeAST) {
1354
- if (!schema.doTypesOverlap(fragmentType, schema.assertCompositeType(parentType))) {
1355
- var nodes = [];
1356
-
1357
- if (parentTypeAST) {
1358
- nodes.push(parentTypeAST);
1359
- }
1360
-
1361
- if (fragmentTypeAST) {
1362
- nodes.push(fragmentTypeAST);
1363
- }
1364
-
1365
- var possibleConcreteTypes = schema.isAbstractType(parentType) ? Array.from(schema.getPossibleTypes(schema.assertAbstractType(parentType))) : [];
1366
- var suggestedTypesMessage = '';
1367
-
1368
- if (possibleConcreteTypes.length !== 0) {
1369
- suggestedTypesMessage = " Possible concrete types include ".concat(possibleConcreteTypes.sort().slice(0, 3).map(function (type) {
1370
- return "'".concat(schema.getTypeString(type), "'");
1371
- }).join(', '), ", etc.");
1372
- }
1373
-
1374
- throw createUserError((fragmentName != null ? "Fragment '".concat(fragmentName, "' cannot be spread here as objects of ") : 'Fragment cannot be spread here as objects of ') + "type '".concat(schema.getTypeString(parentType), "' ") + "can never be of type '".concat(schema.getTypeString(fragmentType), "'.") + suggestedTypesMessage, null, nodes);
1375
- }
1376
- }
1377
-
1378
- module.exports = {
1379
- parse: parse,
1380
- transform: transform
1381
- };