relay-compiler 11.0.2 → 13.0.0-rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. package/README.md +108 -0
  2. package/cli.js +23 -0
  3. package/index.js +22 -4
  4. package/linux-x64/relay +0 -0
  5. package/macos-arm64/relay +0 -0
  6. package/macos-x64/relay +0 -0
  7. package/package.json +2 -26
  8. package/win-x64/relay.exe +0 -0
  9. package/bin/RelayCompilerBin.js.flow +0 -169
  10. package/bin/RelayCompilerMain.js.flow +0 -515
  11. package/bin/__fixtures__/plugin-module.js.flow +0 -17
  12. package/bin/relay-compiler +0 -19008
  13. package/codegen/CodegenDirectory.js.flow +0 -375
  14. package/codegen/CodegenRunner.js.flow +0 -432
  15. package/codegen/CodegenTypes.js.flow +0 -28
  16. package/codegen/CodegenWatcher.js.flow +0 -254
  17. package/codegen/NormalizationCodeGenerator.js.flow +0 -571
  18. package/codegen/ReaderCodeGenerator.js.flow +0 -512
  19. package/codegen/RelayCodeGenerator.js.flow +0 -85
  20. package/codegen/RelayFileWriter.js.flow +0 -367
  21. package/codegen/SourceControl.js.flow +0 -58
  22. package/codegen/compileRelayArtifacts.js.flow +0 -182
  23. package/codegen/createPrintRequireModuleDependency.js.flow +0 -21
  24. package/codegen/sortObjectByKey.js.flow +0 -25
  25. package/codegen/writeRelayGeneratedFile.js.flow +0 -239
  26. package/core/ASTCache.js.flow +0 -74
  27. package/core/ASTConvert.js.flow +0 -233
  28. package/core/CompilerContext.js.flow +0 -191
  29. package/core/CompilerError.js.flow +0 -255
  30. package/core/DotGraphQLParser.js.flow +0 -39
  31. package/core/GraphQLCompilerProfiler.js.flow +0 -341
  32. package/core/GraphQLDerivedFromMetadata.js.flow +0 -36
  33. package/core/GraphQLWatchmanClient.js.flow +0 -111
  34. package/core/IR.js.flow +0 -326
  35. package/core/IRPrinter.js.flow +0 -478
  36. package/core/IRTransformer.js.flow +0 -377
  37. package/core/IRValidator.js.flow +0 -260
  38. package/core/IRVisitor.js.flow +0 -150
  39. package/core/JSModuleParser.js.flow +0 -24
  40. package/core/RelayCompilerScope.js.flow +0 -199
  41. package/core/RelayFindGraphQLTags.js.flow +0 -119
  42. package/core/RelayGraphQLEnumsGenerator.js.flow +0 -55
  43. package/core/RelayIRTransforms.js.flow +0 -138
  44. package/core/RelayParser.js.flow +0 -1734
  45. package/core/RelaySourceModuleParser.js.flow +0 -135
  46. package/core/Schema.js.flow +0 -2037
  47. package/core/SchemaUtils.js.flow +0 -120
  48. package/core/filterContextForNode.js.flow +0 -50
  49. package/core/getFieldDefinition.js.flow +0 -156
  50. package/core/getIdentifierForArgumentValue.js.flow +0 -49
  51. package/core/getIdentifierForSelection.js.flow +0 -69
  52. package/core/getLiteralArgumentValues.js.flow +0 -32
  53. package/core/getNormalizationOperationName.js.flow +0 -19
  54. package/core/inferRootArgumentDefinitions.js.flow +0 -323
  55. package/index.js.flow +0 -200
  56. package/language/RelayLanguagePluginInterface.js.flow +0 -283
  57. package/language/javascript/FindGraphQLTags.js.flow +0 -137
  58. package/language/javascript/RelayFlowBabelFactories.js.flow +0 -176
  59. package/language/javascript/RelayFlowGenerator.js.flow +0 -1100
  60. package/language/javascript/RelayFlowTypeTransformers.js.flow +0 -184
  61. package/language/javascript/RelayLanguagePluginJavaScript.js.flow +0 -34
  62. package/language/javascript/formatGeneratedModule.js.flow +0 -65
  63. package/lib/bin/RelayCompilerBin.js +0 -143
  64. package/lib/bin/RelayCompilerMain.js +0 -486
  65. package/lib/bin/__fixtures__/plugin-module.js +0 -16
  66. package/lib/codegen/CodegenDirectory.js +0 -336
  67. package/lib/codegen/CodegenRunner.js +0 -433
  68. package/lib/codegen/CodegenTypes.js +0 -11
  69. package/lib/codegen/CodegenWatcher.js +0 -271
  70. package/lib/codegen/NormalizationCodeGenerator.js +0 -481
  71. package/lib/codegen/ReaderCodeGenerator.js +0 -472
  72. package/lib/codegen/RelayCodeGenerator.js +0 -68
  73. package/lib/codegen/RelayFileWriter.js +0 -270
  74. package/lib/codegen/SourceControl.js +0 -60
  75. package/lib/codegen/compileRelayArtifacts.js +0 -157
  76. package/lib/codegen/createPrintRequireModuleDependency.js +0 -19
  77. package/lib/codegen/sortObjectByKey.js +0 -41
  78. package/lib/codegen/writeRelayGeneratedFile.js +0 -208
  79. package/lib/core/ASTCache.js +0 -70
  80. package/lib/core/ASTConvert.js +0 -198
  81. package/lib/core/CompilerContext.js +0 -165
  82. package/lib/core/CompilerError.js +0 -251
  83. package/lib/core/DotGraphQLParser.js +0 -40
  84. package/lib/core/GraphQLCompilerProfiler.js +0 -299
  85. package/lib/core/GraphQLDerivedFromMetadata.js +0 -31
  86. package/lib/core/GraphQLWatchmanClient.js +0 -150
  87. package/lib/core/IR.js +0 -11
  88. package/lib/core/IRPrinter.js +0 -389
  89. package/lib/core/IRTransformer.js +0 -345
  90. package/lib/core/IRValidator.js +0 -226
  91. package/lib/core/IRVisitor.js +0 -45
  92. package/lib/core/JSModuleParser.js +0 -18
  93. package/lib/core/RelayCompilerScope.js +0 -149
  94. package/lib/core/RelayFindGraphQLTags.js +0 -79
  95. package/lib/core/RelayGraphQLEnumsGenerator.js +0 -50
  96. package/lib/core/RelayIRTransforms.js +0 -109
  97. package/lib/core/RelayParser.js +0 -1382
  98. package/lib/core/RelaySourceModuleParser.js +0 -104
  99. package/lib/core/Schema.js +0 -1877
  100. package/lib/core/SchemaUtils.js +0 -98
  101. package/lib/core/filterContextForNode.js +0 -49
  102. package/lib/core/getFieldDefinition.js +0 -145
  103. package/lib/core/getIdentifierForArgumentValue.js +0 -53
  104. package/lib/core/getIdentifierForSelection.js +0 -48
  105. package/lib/core/getLiteralArgumentValues.js +0 -26
  106. package/lib/core/getNormalizationOperationName.js +0 -17
  107. package/lib/core/inferRootArgumentDefinitions.js +0 -351
  108. package/lib/index.js +0 -178
  109. package/lib/language/RelayLanguagePluginInterface.js +0 -14
  110. package/lib/language/javascript/FindGraphQLTags.js +0 -126
  111. package/lib/language/javascript/RelayFlowBabelFactories.js +0 -160
  112. package/lib/language/javascript/RelayFlowGenerator.js +0 -857
  113. package/lib/language/javascript/RelayFlowTypeTransformers.js +0 -119
  114. package/lib/language/javascript/RelayLanguagePluginJavaScript.js +0 -30
  115. package/lib/language/javascript/formatGeneratedModule.js +0 -36
  116. package/lib/reporters/ConsoleReporter.js +0 -61
  117. package/lib/reporters/MultiReporter.js +0 -45
  118. package/lib/reporters/Reporter.js +0 -11
  119. package/lib/runner/Artifacts.js +0 -323
  120. package/lib/runner/BufferedFilesystem.js +0 -261
  121. package/lib/runner/GraphQLASTNodeGroup.js +0 -256
  122. package/lib/runner/GraphQLASTUtils.js +0 -23
  123. package/lib/runner/GraphQLNodeMap.js +0 -81
  124. package/lib/runner/Sources.js +0 -271
  125. package/lib/runner/StrictMap.js +0 -134
  126. package/lib/runner/compileArtifacts.js +0 -39
  127. package/lib/runner/extractAST.js +0 -77
  128. package/lib/runner/getChangedNodeNames.js +0 -82
  129. package/lib/runner/getSchemaInstance.js +0 -30
  130. package/lib/runner/types.js +0 -12
  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 -41
  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 -44
  154. package/lib/transforms/SkipRedundantNodesTransform.js +0 -254
  155. package/lib/transforms/SkipSplitOperationTransform.js +0 -32
  156. package/lib/transforms/SkipUnreachableNodeTransform.js +0 -158
  157. package/lib/transforms/SkipUnusedVariablesTransform.js +0 -74
  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 -91
  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 -98
  174. package/lib/util/Rollout.js +0 -40
  175. package/lib/util/TimeReporter.js +0 -83
  176. package/lib/util/areEqualArgValues.js +0 -134
  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 -66
  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 -219
  194. package/runner/BufferedFilesystem.js.flow +0 -194
  195. package/runner/GraphQLASTNodeGroup.js.flow +0 -176
  196. package/runner/GraphQLASTUtils.js.flow +0 -26
  197. package/runner/GraphQLNodeMap.js.flow +0 -55
  198. package/runner/Sources.js.flow +0 -228
  199. package/runner/StrictMap.js.flow +0 -96
  200. package/runner/compileArtifacts.js.flow +0 -76
  201. package/runner/extractAST.js.flow +0 -100
  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/transforms/ApplyFragmentArgumentTransform.js.flow +0 -526
  206. package/transforms/ClientExtensionsTransform.js.flow +0 -225
  207. package/transforms/ConnectionTransform.js.flow +0 -855
  208. package/transforms/DeclarativeConnectionMutationTransform.js.flow +0 -247
  209. package/transforms/DeferStreamTransform.js.flow +0 -265
  210. package/transforms/DisallowIdAsAlias.js.flow +0 -47
  211. package/transforms/DisallowTypenameOnRoot.js.flow +0 -45
  212. package/transforms/FieldHandleTransform.js.flow +0 -79
  213. package/transforms/FilterCompilerDirectivesTransform.js.flow +0 -33
  214. package/transforms/FilterDirectivesTransform.js.flow +0 -45
  215. package/transforms/FlattenTransform.js.flow +0 -460
  216. package/transforms/GenerateIDFieldTransform.js.flow +0 -152
  217. package/transforms/GenerateTypeNameTransform.js.flow +0 -161
  218. package/transforms/InlineDataFragmentTransform.js.flow +0 -125
  219. package/transforms/InlineFragmentsTransform.js.flow +0 -71
  220. package/transforms/MaskTransform.js.flow +0 -126
  221. package/transforms/MatchTransform.js.flow +0 -589
  222. package/transforms/ReactFlightComponentTransform.js.flow +0 -195
  223. package/transforms/RefetchableFragmentTransform.js.flow +0 -272
  224. package/transforms/RelayDirectiveTransform.js.flow +0 -97
  225. package/transforms/RequiredFieldTransform.js.flow +0 -415
  226. package/transforms/SkipClientExtensionsTransform.js.flow +0 -54
  227. package/transforms/SkipHandleFieldTransform.js.flow +0 -44
  228. package/transforms/SkipRedundantNodesTransform.js.flow +0 -258
  229. package/transforms/SkipSplitOperationTransform.js.flow +0 -37
  230. package/transforms/SkipUnreachableNodeTransform.js.flow +0 -149
  231. package/transforms/SkipUnusedVariablesTransform.js.flow +0 -59
  232. package/transforms/SplitModuleImportTransform.js.flow +0 -98
  233. package/transforms/TestOperationTransform.js.flow +0 -142
  234. package/transforms/TransformUtils.js.flow +0 -26
  235. package/transforms/ValidateGlobalVariablesTransform.js.flow +0 -81
  236. package/transforms/ValidateRequiredArgumentsTransform.js.flow +0 -127
  237. package/transforms/ValidateServerOnlyDirectivesTransform.js.flow +0 -112
  238. package/transforms/ValidateUnusedVariablesTransform.js.flow +0 -89
  239. package/transforms/query-generators/FetchableQueryGenerator.js.flow +0 -189
  240. package/transforms/query-generators/NodeQueryGenerator.js.flow +0 -219
  241. package/transforms/query-generators/QueryQueryGenerator.js.flow +0 -57
  242. package/transforms/query-generators/ViewerQueryGenerator.js.flow +0 -97
  243. package/transforms/query-generators/index.js.flow +0 -90
  244. package/transforms/query-generators/utils.js.flow +0 -76
  245. package/util/CodeMarker.js.flow +0 -79
  246. package/util/DefaultHandleKey.js.flow +0 -17
  247. package/util/RelayCompilerCache.js.flow +0 -88
  248. package/util/Rollout.js.flow +0 -39
  249. package/util/TimeReporter.js.flow +0 -79
  250. package/util/areEqualArgValues.js.flow +0 -125
  251. package/util/argumentContainsVariables.js.flow +0 -38
  252. package/util/dedupeJSONStringify.js.flow +0 -152
  253. package/util/generateAbstractTypeRefinementKey.js.flow +0 -29
  254. package/util/getDefinitionNodeHash.js.flow +0 -25
  255. package/util/getModuleName.js.flow +0 -39
  256. package/util/joinArgumentDefinitions.js.flow +0 -105
  257. package/util/md5.js.flow +0 -22
  258. package/util/murmurHash.js.flow +0 -94
  259. package/util/nullthrowsOSS.js.flow +0 -25
  260. package/util/orList.js.flow +0 -37
  261. package/util/partitionArray.js.flow +0 -37
@@ -1,1382 +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 Profiler = require('./GraphQLCompilerProfiler');
22
-
23
- var orList = require('../util/orList');
24
-
25
- var partitionArray = require('../util/partitionArray');
26
-
27
- var _require = require('../util/DefaultHandleKey'),
28
- DEFAULT_HANDLE_KEY = _require.DEFAULT_HANDLE_KEY;
29
-
30
- var _require2 = require('./CompilerError'),
31
- createCompilerError = _require2.createCompilerError,
32
- createUserError = _require2.createUserError,
33
- eachWithCombinedError = _require2.eachWithCombinedError;
34
-
35
- var _require3 = require('./SchemaUtils'),
36
- isExecutableDefinitionAST = _require3.isExecutableDefinitionAST;
37
-
38
- var _require4 = require('./getFieldDefinition'),
39
- getFieldDefinitionLegacy = _require4.getFieldDefinitionLegacy;
40
-
41
- var _require5 = require('graphql'),
42
- parseGraphQL = _require5.parse,
43
- parseType = _require5.parseType,
44
- print = _require5.print,
45
- Source = _require5.Source;
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
- // $FlowFixMe[incompatible-return]
595
- type: type
596
- };
597
- };
598
-
599
- _proto2._transformSelections = function _transformSelections(selectionSet, parentType, parentTypeAST) {
600
- var _this4 = this;
601
-
602
- return selectionSet.selections.map(function (selection) {
603
- var node;
604
-
605
- if (selection.kind === 'Field') {
606
- node = _this4._transformField(selection, parentType);
607
- } else if (selection.kind === 'FragmentSpread') {
608
- node = _this4._transformFragmentSpread(selection, parentType, parentTypeAST);
609
- } else if (selection.kind === 'InlineFragment') {
610
- node = _this4._transformInlineFragment(selection, parentType, parentTypeAST);
611
- } else {
612
- selection.kind;
613
- throw createCompilerError("Unknown ast kind '".concat(selection.kind, "'."), [selection]);
614
- }
615
-
616
- var _this4$_splitConditio = _this4._splitConditions(node.directives),
617
- conditions = _this4$_splitConditio[0],
618
- directives = _this4$_splitConditio[1];
619
-
620
- var conditionalNodes = applyConditions(conditions, // $FlowFixMe[incompatible-call]
621
- [(0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, node), {}, {
622
- directives: directives
623
- })]);
624
-
625
- if (conditionalNodes.length !== 1) {
626
- throw createCompilerError('Expected exactly one condition node.', null, selection.directives);
627
- }
628
-
629
- return conditionalNodes[0];
630
- });
631
- };
632
-
633
- _proto2._transformInlineFragment = function _transformInlineFragment(fragment, parentType, parentTypeAST) {
634
- var schema = this._schema;
635
- var typeCondition = fragment.typeCondition != null ? schema.getTypeFromAST(fragment.typeCondition) : parentType;
636
-
637
- if (typeCondition == null) {
638
- var _fragment$typeConditi;
639
-
640
- 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]);
641
- }
642
-
643
- var typeConditionName = schema.getTypeString(typeCondition);
644
- typeCondition = schema.asCompositeType(typeCondition);
645
-
646
- if (typeCondition == null) {
647
- var _fragment$typeConditi2;
648
-
649
- 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]);
650
- }
651
-
652
- var rawParentType = this._schema.assertCompositeType(this._schema.getRawType(parentType));
653
-
654
- checkFragmentSpreadTypeCompatibility(this._schema, typeCondition, rawParentType, null, fragment.typeCondition, parentTypeAST);
655
-
656
- var directives = this._transformDirectives(fragment.directives || [], 'INLINE_FRAGMENT');
657
-
658
- var selections = this._transformSelections(fragment.selectionSet, typeCondition, fragment.typeCondition);
659
-
660
- return {
661
- kind: 'InlineFragment',
662
- directives: directives,
663
- loc: buildLocation(fragment.loc),
664
- metadata: null,
665
- selections: selections,
666
- typeCondition: typeCondition
667
- };
668
- };
669
-
670
- _proto2._transformFragmentSpread = function _transformFragmentSpread(fragmentSpread, parentType, parentTypeAST) {
671
- var _this5 = this;
672
-
673
- var fragmentName = getName(fragmentSpread);
674
-
675
- var _partitionArray = partitionArray(fragmentSpread.directives || [], function (directive) {
676
- var name = getName(directive);
677
- return name === ARGUMENTS || name === DEPRECATED_UNCHECKED_ARGUMENTS;
678
- }),
679
- argumentDirectives = _partitionArray[0],
680
- otherDirectives = _partitionArray[1];
681
-
682
- if (argumentDirectives.length > 1) {
683
- throw createUserError("Directive @".concat(ARGUMENTS, " may be used at most once per a fragment spread."), null, argumentDirectives);
684
- }
685
-
686
- var fragmentDefinition = this._entries.get(fragmentName);
687
-
688
- if (fragmentDefinition == null) {
689
- throw createUserError("Unknown fragment '".concat(fragmentName, "'."), null, [fragmentSpread.name]);
690
- }
691
-
692
- var fragmentTypeNode = getFragmentType(fragmentDefinition.definition);
693
-
694
- var fragmentType = this._schema.assertCompositeType(this._schema.expectTypeFromAST(fragmentTypeNode));
695
-
696
- var rawParentType = this._schema.assertCompositeType(this._schema.getRawType(parentType));
697
-
698
- checkFragmentSpreadTypeCompatibility(this._schema, fragmentType, rawParentType, fragmentSpread.name.value, fragmentSpread, parentTypeAST);
699
- var fragmentArgumentDefinitions = fragmentDefinition.variableDefinitions;
700
- var argumentsDirective = argumentDirectives[0];
701
- var args;
702
-
703
- if (argumentsDirective != null) {
704
- var isDeprecatedUncheckedArguments = getName(argumentsDirective) === DEPRECATED_UNCHECKED_ARGUMENTS;
705
- var hasInvalidArgument = false;
706
- args = (argumentsDirective.arguments || []).map(function (arg) {
707
- var _argumentDefinition$t;
708
-
709
- var argName = getName(arg);
710
- var argValue = arg.value;
711
- var argumentDefinition = fragmentArgumentDefinitions.get(argName);
712
- var argumentType = (_argumentDefinition$t = argumentDefinition === null || argumentDefinition === void 0 ? void 0 : argumentDefinition.type) !== null && _argumentDefinition$t !== void 0 ? _argumentDefinition$t : null;
713
-
714
- if (argValue.kind === 'Variable') {
715
- if (argumentDefinition == null && !isDeprecatedUncheckedArguments) {
716
- 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]);
717
- }
718
-
719
- hasInvalidArgument = hasInvalidArgument || argumentDefinition == null; // TODO: check the type of the variable and use the type
720
-
721
- return {
722
- kind: 'Argument',
723
- loc: buildLocation(arg.loc),
724
- name: argName,
725
- value: _this5._transformVariable(argValue, null),
726
- type: null
727
- };
728
- } else {
729
- if (argumentType == null) {
730
- 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]);
731
- }
732
-
733
- var value = _this5._transformValue(argValue, argumentType);
734
-
735
- return {
736
- kind: 'Argument',
737
- loc: buildLocation(arg.loc),
738
- name: argName,
739
- value: value,
740
- type: argumentType
741
- };
742
- }
743
- });
744
-
745
- if (isDeprecatedUncheckedArguments && !hasInvalidArgument) {
746
- throw createUserError("Invalid use of @".concat(DEPRECATED_UNCHECKED_ARGUMENTS, ": all arguments ") + "are defined, use @".concat(ARGUMENTS, " instead."), null, [argumentsDirective]);
747
- }
748
- }
749
-
750
- var directives = this._transformDirectives(otherDirectives, 'FRAGMENT_SPREAD');
751
-
752
- return {
753
- kind: 'FragmentSpread',
754
- args: args || [],
755
- metadata: null,
756
- loc: buildLocation(fragmentSpread.loc),
757
- name: fragmentName,
758
- directives: directives
759
- };
760
- };
761
-
762
- _proto2._transformField = function _transformField(field, parentType) {
763
- var _field$alias$value, _field$alias;
764
-
765
- var schema = this._schema;
766
- var name = getName(field);
767
-
768
- var fieldDef = this._getFieldDefinition(schema, parentType, name, field);
769
-
770
- if (fieldDef == null) {
771
- throw createUserError("Unknown field '".concat(name, "' on type '").concat(schema.getTypeString(parentType), "'."), null, [field]);
772
- }
773
-
774
- 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;
775
-
776
- var args = this._transformArguments(field.arguments || [], schema.getFieldArgs(fieldDef), fieldDef);
777
-
778
- var _partitionArray2 = partitionArray(field.directives || [], function (directive) {
779
- return getName(directive) !== CLIENT_FIELD;
780
- }),
781
- otherDirectives = _partitionArray2[0],
782
- clientFieldDirectives = _partitionArray2[1];
783
-
784
- var directives = this._transformDirectives(otherDirectives, 'FIELD');
785
-
786
- var type = schema.getFieldType(fieldDef);
787
-
788
- var handles = this._transformHandle(name, args, clientFieldDirectives);
789
-
790
- if (schema.isLeafType(schema.getRawType(type))) {
791
- if (field.selectionSet && field.selectionSet.selections && field.selectionSet.selections.length) {
792
- throw createUserError("Expected no selections for scalar field '".concat(name, "'."), null, [field]);
793
- }
794
-
795
- return {
796
- kind: 'ScalarField',
797
- alias: alias,
798
- args: args,
799
- directives: directives,
800
- handles: handles,
801
- loc: buildLocation(field.loc),
802
- metadata: null,
803
- name: name,
804
- type: schema.assertScalarFieldType(type)
805
- };
806
- } else {
807
- var selections = field.selectionSet ? this._transformSelections(field.selectionSet, type) : null;
808
-
809
- if (selections == null || selections.length === 0) {
810
- throw createUserError("Expected at least one selection for non-scalar field '".concat(name, "' on type '").concat(schema.getTypeString(type), "'."), null, [field]);
811
- }
812
-
813
- return {
814
- kind: 'LinkedField',
815
- alias: alias,
816
- args: args,
817
- connection: false,
818
- directives: directives,
819
- handles: handles,
820
- loc: buildLocation(field.loc),
821
- metadata: null,
822
- name: name,
823
- selections: selections,
824
- type: schema.assertLinkedFieldType(type)
825
- };
826
- }
827
- };
828
-
829
- _proto2._transformHandle = function _transformHandle(fieldName, fieldArgs, clientFieldDirectives) {
830
- var handles = null;
831
- clientFieldDirectives.forEach(function (clientFieldDirective) {
832
- var handleArgument = (clientFieldDirective.arguments || []).find(function (arg) {
833
- return getName(arg) === CLIENT_FIELD_HANDLE;
834
- });
835
-
836
- if (handleArgument) {
837
- var name = null;
838
- var key = DEFAULT_HANDLE_KEY;
839
- var filters = null;
840
- var maybeHandle = transformLiteralValue(handleArgument.value, handleArgument);
841
-
842
- if (typeof maybeHandle !== 'string') {
843
- throw createUserError("Expected a string literal argument for the @".concat(CLIENT_FIELD, " directive."), null, [handleArgument.value]);
844
- }
845
-
846
- name = maybeHandle;
847
- var keyArgument = (clientFieldDirective.arguments || []).find(function (arg) {
848
- return getName(arg) === CLIENT_FIELD_KEY;
849
- });
850
-
851
- if (keyArgument) {
852
- var maybeKey = transformLiteralValue(keyArgument.value, keyArgument);
853
-
854
- if (typeof maybeKey !== 'string') {
855
- throw createUserError("Expected a string literal argument for the @".concat(CLIENT_FIELD, " directive."), null, [keyArgument.value]);
856
- }
857
-
858
- key = maybeKey;
859
- }
860
-
861
- var filtersArgument = (clientFieldDirective.arguments || []).find(function (arg) {
862
- return getName(arg) === CLIENT_FIELD_FILTERS;
863
- });
864
-
865
- if (filtersArgument) {
866
- var maybeFilters = transformLiteralValue(filtersArgument.value, filtersArgument);
867
-
868
- if (!(Array.isArray(maybeFilters) && maybeFilters.every(function (filter) {
869
- return typeof filter === 'string' && fieldArgs.some(function (fieldArg) {
870
- return fieldArg.name === filter;
871
- });
872
- }))) {
873
- throw createUserError("Expected an array of argument names on field '".concat(fieldName, "'."), null, [filtersArgument.value]);
874
- } // $FlowFixMe[incompatible-cast]
875
-
876
-
877
- filters = maybeFilters;
878
- }
879
-
880
- var dynamicKeyArgument = (clientFieldDirective.arguments || []).find(function (arg) {
881
- return getName(arg) === 'dynamicKey_UNSTABLE';
882
- });
883
-
884
- if (dynamicKeyArgument != null) {
885
- throw createUserError('Dynamic keys are only supported with @connection.', null, [dynamicKeyArgument.value]);
886
- }
887
-
888
- handles = handles || [];
889
- handles.push({
890
- name: name,
891
- key: key,
892
- filters: filters,
893
- dynamicKey: null
894
- });
895
- }
896
- });
897
- return handles;
898
- };
899
-
900
- _proto2._transformDirectives = function _transformDirectives(directives, location) {
901
- var _this6 = this;
902
-
903
- this._validateDirectivesLocation(directives, location);
904
-
905
- return directives.map(function (directive) {
906
- var name = getName(directive);
907
-
908
- var directiveDef = _this6._schema.getDirective(name);
909
-
910
- if (directiveDef == null) {
911
- throw createUserError("Unknown directive '".concat(name, "'."), null, [directive]);
912
- }
913
-
914
- var args = _this6._transformArguments(directive.arguments || [], directiveDef.args.map(function (item) {
915
- return {
916
- name: item.name,
917
- type: item.type,
918
- defaultValue: item.defaultValue
919
- };
920
- }), null, name);
921
-
922
- return {
923
- kind: 'Directive',
924
- loc: buildLocation(directive.loc),
925
- name: name,
926
- args: args
927
- };
928
- });
929
- };
930
-
931
- _proto2._transformArguments = function _transformArguments(args, argumentDefinitions, field, directiveName) {
932
- var _this7 = this;
933
-
934
- return args.map(function (arg) {
935
- var argName = getName(arg);
936
- var argDef = argumentDefinitions.find(function (def) {
937
- return def.name === argName;
938
- });
939
-
940
- if (argDef == null) {
941
- 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, "'.") : '.');
942
- throw createUserError(message, null, [arg]);
943
- }
944
-
945
- var value = _this7._transformValue(arg.value, argDef.type);
946
-
947
- return {
948
- kind: 'Argument',
949
- loc: buildLocation(arg.loc),
950
- name: argName,
951
- value: value,
952
- type: argDef.type
953
- };
954
- });
955
- };
956
-
957
- _proto2._splitConditions = function _splitConditions(mixedDirectives) {
958
- var _partitionArray3 = partitionArray(mixedDirectives, function (directive) {
959
- return directive.name === INCLUDE || directive.name === SKIP;
960
- }),
961
- conditionDirectives = _partitionArray3[0],
962
- otherDirectives = _partitionArray3[1];
963
-
964
- var conditions = conditionDirectives.map(function (directive) {
965
- var passingValue = directive.name === INCLUDE;
966
- var arg = directive.args[0];
967
-
968
- if (arg == null || arg.name !== IF) {
969
- throw createUserError("Expected an 'if' argument to @".concat(directive.name, "."), [directive.loc]);
970
- }
971
-
972
- if (!(arg.value.kind === 'Variable' || arg.value.kind === 'Literal')) {
973
- throw createUserError("Expected the 'if' argument to @".concat(directive.name, " to be a variable or literal."), [directive.loc]);
974
- }
975
-
976
- return {
977
- kind: 'Condition',
978
- condition: arg.value,
979
- loc: directive.loc,
980
- passingValue: passingValue,
981
- selections: []
982
- };
983
- });
984
- var sortedConditions = conditions.sort(function (a, b) {
985
- if (a.condition.kind === 'Variable' && b.condition.kind === 'Variable') {
986
- return a.condition.variableName < b.condition.variableName ? -1 : a.condition.variableName > b.condition.variableName ? 1 : 0;
987
- } else {
988
- // sort literals earlier, variables later
989
- return a.condition.kind === 'Variable' ? 1 : b.condition.kind === 'Variable' ? -1 : 0;
990
- }
991
- });
992
- return [sortedConditions, otherDirectives];
993
- };
994
-
995
- _proto2._transformVariable = function _transformVariable(ast, usedAsType) {
996
- var variableName = getName(ast);
997
-
998
- this._recordAndVerifyVariableReference(ast, variableName, usedAsType);
999
-
1000
- return {
1001
- kind: 'Variable',
1002
- loc: buildLocation(ast.loc),
1003
- variableName: variableName,
1004
- type: usedAsType
1005
- };
1006
- };
1007
-
1008
- _proto2._transformValue = function _transformValue(ast, type) {
1009
- var _this8 = this;
1010
-
1011
- return transformValue(this._schema, ast, type, function (variableAst, variableType) {
1012
- return _this8._transformVariable(variableAst, variableType);
1013
- });
1014
- };
1015
-
1016
- return GraphQLDefinitionParser;
1017
- }();
1018
- /**
1019
- * Transforms and validates argument values according to the expected
1020
- * type.
1021
- */
1022
-
1023
-
1024
- function transformValue(schema, ast, type, transformVariable) {
1025
- if (ast.kind === 'Variable') {
1026
- // Special case variables since there is no value to parse
1027
- return transformVariable(ast, type);
1028
- } else if (ast.kind === 'NullValue') {
1029
- // Special case null literals since there is no value to parse
1030
- if (schema.isNonNull(type)) {
1031
- throw createUserError("Expected a value matching type '".concat(String(type), "'."), null, [ast]);
1032
- }
1033
-
1034
- return {
1035
- kind: 'Literal',
1036
- loc: buildLocation(ast.loc),
1037
- value: null
1038
- };
1039
- } else {
1040
- return transformNonNullLiteral(schema, ast, type, transformVariable);
1041
- }
1042
- }
1043
- /**
1044
- * Transforms and validates non-null literal (non-variable) values
1045
- * according to the expected type.
1046
- */
1047
-
1048
-
1049
- function transformNonNullLiteral(schema, ast, type, transformVariable) {
1050
- // Transform the value based on the type without a non-null wrapper.
1051
- // Note that error messages should still use the original `type`
1052
- // since that accurately describes to the user what the expected
1053
- // type is (using nullableType would suggest that `null` is legal
1054
- // even when it may not be, for example).
1055
- var nullableType = schema.getNullableType(type);
1056
-
1057
- if (schema.isList(nullableType)) {
1058
- if (ast.kind !== 'ListValue') {
1059
- // Parse singular (non-list) values flowing into a list type
1060
- // as scalars, ie without wrapping them in an array.
1061
- if (!schema.isInputType(schema.getListItemType(nullableType))) {
1062
- throw createUserError("Expected type ".concat(schema.getTypeString(nullableType), " to be an input type."), null, [ast]);
1063
- }
1064
-
1065
- return transformValue(schema, ast, schema.assertInputType(schema.getListItemType(nullableType)), transformVariable);
1066
- }
1067
-
1068
- var itemType = schema.assertInputType(schema.getListItemType(nullableType));
1069
- var literalList = [];
1070
- var items = [];
1071
- var areAllItemsScalar = true;
1072
- ast.values.forEach(function (item) {
1073
- var itemValue = transformValue(schema, item, itemType, transformVariable);
1074
-
1075
- if (itemValue.kind === 'Literal') {
1076
- literalList.push(itemValue.value);
1077
- }
1078
-
1079
- items.push(itemValue);
1080
- areAllItemsScalar = areAllItemsScalar && itemValue.kind === 'Literal';
1081
- });
1082
-
1083
- if (areAllItemsScalar) {
1084
- return {
1085
- kind: 'Literal',
1086
- loc: buildLocation(ast.loc),
1087
- value: literalList
1088
- };
1089
- } else {
1090
- return {
1091
- kind: 'ListValue',
1092
- loc: buildLocation(ast.loc),
1093
- items: items
1094
- };
1095
- }
1096
- } else if (schema.isInputObject(nullableType)) {
1097
- if (ast.kind !== 'ObjectValue') {
1098
- throw createUserError("Expected a value matching type '".concat(schema.getTypeString(type), "'."), null, [ast]);
1099
- }
1100
-
1101
- var literalObject = {};
1102
- var fields = [];
1103
- var areAllFieldsScalar = true;
1104
- var inputType = schema.assertInputObjectType(nullableType);
1105
- var requiredFieldNames = new Set(schema.getFields(inputType).filter(function (field) {
1106
- return schema.isNonNull(schema.getFieldType(field));
1107
- }).map(function (field) {
1108
- return schema.getFieldName(field);
1109
- }));
1110
- var seenFields = new Map();
1111
- ast.fields.forEach(function (field) {
1112
- var fieldName = getName(field);
1113
- var seenField = seenFields.get(fieldName);
1114
-
1115
- if (seenField) {
1116
- throw createUserError("Duplicated field name '".concat(fieldName, "' in the input object."), null, [field, seenField]);
1117
- }
1118
-
1119
- var fieldID = schema.getFieldByName(inputType, fieldName);
1120
-
1121
- if (!fieldID) {
1122
- throw createUserError("Unknown field '".concat(fieldName, "' on type '").concat(schema.getTypeString(inputType), "'."), null, [field]);
1123
- }
1124
-
1125
- var fieldConfig = schema.getFieldConfig(fieldID);
1126
- var fieldType = schema.assertInputType(fieldConfig.type);
1127
- var fieldValue = transformValue(schema, field.value, fieldType, transformVariable);
1128
-
1129
- if (fieldValue.kind === 'Literal') {
1130
- literalObject[field.name.value] = fieldValue.value;
1131
- }
1132
-
1133
- fields.push({
1134
- kind: 'ObjectFieldValue',
1135
- loc: buildLocation(field.loc),
1136
- name: fieldName,
1137
- value: fieldValue
1138
- });
1139
- seenFields.set(fieldName, field);
1140
- requiredFieldNames["delete"](fieldName);
1141
- areAllFieldsScalar = areAllFieldsScalar && fieldValue.kind === 'Literal';
1142
- });
1143
-
1144
- if (requiredFieldNames.size > 0) {
1145
- var requiredFieldStr = Array.from(requiredFieldNames).map(function (item) {
1146
- return "'".concat(item, "'");
1147
- }).join(', ');
1148
- throw createUserError("Missing non-optional field".concat(requiredFieldNames.size > 1 ? 's:' : '', " ").concat(requiredFieldStr, " for input type '").concat(schema.getTypeString(inputType), "'."), null, [ast]);
1149
- }
1150
-
1151
- if (areAllFieldsScalar) {
1152
- return {
1153
- kind: 'Literal',
1154
- loc: buildLocation(ast.loc),
1155
- value: literalObject
1156
- };
1157
- } else {
1158
- return {
1159
- kind: 'ObjectValue',
1160
- loc: buildLocation(ast.loc),
1161
- fields: fields
1162
- };
1163
- }
1164
- } else if (schema.isId(nullableType)) {
1165
- // GraphQLID's parseLiteral() always returns the string value. However
1166
- // the int/string distinction may be important at runtime, so this
1167
- // transform parses int/string literals into the corresponding JS types.
1168
- if (ast.kind === 'IntValue') {
1169
- return {
1170
- kind: 'Literal',
1171
- loc: buildLocation(ast.loc),
1172
- value: parseInt(ast.value, 10)
1173
- };
1174
- } else if (ast.kind === 'StringValue') {
1175
- return {
1176
- kind: 'Literal',
1177
- loc: buildLocation(ast.loc),
1178
- value: ast.value
1179
- };
1180
- } else {
1181
- throw createUserError("Invalid value, expected a value matching type '".concat(schema.getTypeString(type), "'."), null, [ast]);
1182
- }
1183
- } else if (schema.isEnum(nullableType)) {
1184
- var enumType = schema.assertEnumType(nullableType);
1185
- var value = schema.parseLiteral(enumType, ast);
1186
-
1187
- if (value == null) {
1188
- var suggestions = schema.getEnumValues(enumType); // parseLiteral() should return a non-null JavaScript value
1189
- // if the ast value is valid for the type.
1190
-
1191
- throw createUserError("Expected a value matching type '".concat(schema.getTypeString(type), "'. Possible values: ").concat(orList(suggestions), "?'"), null, [ast]);
1192
- }
1193
-
1194
- return {
1195
- kind: 'Literal',
1196
- loc: buildLocation(ast.loc),
1197
- value: value
1198
- };
1199
- } else if (schema.isScalar(nullableType)) {
1200
- var _value = schema.parseLiteral(schema.assertScalarType(nullableType), ast);
1201
-
1202
- if (_value == null) {
1203
- // parseLiteral() should return a non-null JavaScript value
1204
- // if the ast value is valid for the type.
1205
- throw createUserError("Expected a value matching type '".concat(schema.getTypeString(type), "'."), null, [ast]);
1206
- }
1207
-
1208
- return {
1209
- kind: 'Literal',
1210
- loc: buildLocation(ast.loc),
1211
- value: _value
1212
- };
1213
- } else {
1214
- throw createCompilerError("Unsupported type '".concat(schema.getTypeString(type), "' for input value, expected a GraphQLList, ") + 'GraphQLInputObjectType, GraphQLEnumType, or GraphQLScalarType.', null, [ast]);
1215
- }
1216
- }
1217
- /**
1218
- * @private
1219
- */
1220
-
1221
-
1222
- function transformLiteralValue(ast, context) {
1223
- switch (ast.kind) {
1224
- case 'IntValue':
1225
- return parseInt(ast.value, 10);
1226
-
1227
- case 'FloatValue':
1228
- return parseFloat(ast.value);
1229
-
1230
- case 'StringValue':
1231
- return ast.value;
1232
-
1233
- case 'BooleanValue':
1234
- // Note: duplicated because Flow does not understand fall-through cases
1235
- return ast.value;
1236
-
1237
- case 'EnumValue':
1238
- // Note: duplicated because Flow does not understand fall-through cases
1239
- return ast.value;
1240
-
1241
- case 'ListValue':
1242
- return ast.values.map(function (item) {
1243
- return transformLiteralValue(item, context);
1244
- });
1245
-
1246
- case 'NullValue':
1247
- return null;
1248
-
1249
- case 'ObjectValue':
1250
- {
1251
- var objectValue = {};
1252
- ast.fields.forEach(function (field) {
1253
- var fieldName = getName(field);
1254
- var value = transformLiteralValue(field.value, context);
1255
- objectValue[fieldName] = value;
1256
- });
1257
- return objectValue;
1258
- }
1259
-
1260
- case 'Variable':
1261
- throw createUserError('Unexpected variable where a literal (static) value is required.', null, [ast, context]);
1262
-
1263
- default:
1264
- ast.kind;
1265
- throw createCompilerError("Unknown ast kind '".concat(ast.kind, "'."), [ast]);
1266
- }
1267
- }
1268
- /**
1269
- * @private
1270
- */
1271
-
1272
-
1273
- function buildArgumentDefinitions(variables) {
1274
- return Array.from(variables.values(), function (_ref3) {
1275
- var ast = _ref3.ast,
1276
- name = _ref3.name,
1277
- defaultValue = _ref3.defaultValue,
1278
- type = _ref3.type;
1279
- return {
1280
- kind: 'LocalArgumentDefinition',
1281
- loc: buildLocation(ast.loc),
1282
- name: name,
1283
- type: type,
1284
- defaultValue: defaultValue
1285
- };
1286
- });
1287
- }
1288
- /**
1289
- * @private
1290
- */
1291
-
1292
-
1293
- function buildLocation(loc) {
1294
- if (loc == null) {
1295
- return {
1296
- kind: 'Unknown'
1297
- };
1298
- }
1299
-
1300
- return {
1301
- kind: 'Source',
1302
- start: loc.start,
1303
- end: loc.end,
1304
- source: loc.source
1305
- };
1306
- }
1307
- /**
1308
- * @private
1309
- */
1310
-
1311
-
1312
- function applyConditions(conditions, selections) {
1313
- var nextSelections = selections;
1314
- conditions.forEach(function (condition) {
1315
- nextSelections = [(0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, condition), {}, {
1316
- selections: nextSelections
1317
- })];
1318
- });
1319
- return nextSelections;
1320
- }
1321
- /**
1322
- * @private
1323
- */
1324
-
1325
-
1326
- function getName(ast) {
1327
- var _ast$name;
1328
-
1329
- var name = (_ast$name = ast.name) === null || _ast$name === void 0 ? void 0 : _ast$name.value;
1330
-
1331
- if (typeof name !== 'string') {
1332
- throw createCompilerError("Expected ast node to have a 'name'.", null, [ast]);
1333
- }
1334
-
1335
- return name;
1336
- }
1337
-
1338
- function getTypeName(ast) {
1339
- return ast ? print(ast) : 'Undefined Type Name';
1340
- }
1341
- /**
1342
- * @private
1343
- */
1344
-
1345
-
1346
- function getFragmentType(ast) {
1347
- if (ast.kind === 'FragmentDefinition') {
1348
- return ast.typeCondition;
1349
- }
1350
-
1351
- throw createCompilerError('Expected ast node to be a FragmentDefinition node.', null, [ast]);
1352
- }
1353
-
1354
- function checkFragmentSpreadTypeCompatibility(schema, fragmentType, parentType, fragmentName, fragmentTypeAST, parentTypeAST) {
1355
- if (!schema.doTypesOverlap(fragmentType, schema.assertCompositeType(parentType))) {
1356
- var nodes = [];
1357
-
1358
- if (parentTypeAST) {
1359
- nodes.push(parentTypeAST);
1360
- }
1361
-
1362
- if (fragmentTypeAST) {
1363
- nodes.push(fragmentTypeAST);
1364
- }
1365
-
1366
- var possibleConcreteTypes = schema.isAbstractType(parentType) ? Array.from(schema.getPossibleTypes(schema.assertAbstractType(parentType))) : [];
1367
- var suggestedTypesMessage = '';
1368
-
1369
- if (possibleConcreteTypes.length !== 0) {
1370
- suggestedTypesMessage = " Possible concrete types include ".concat(possibleConcreteTypes.sort().slice(0, 3).map(function (type) {
1371
- return "'".concat(schema.getTypeString(type), "'");
1372
- }).join(', '), ", etc.");
1373
- }
1374
-
1375
- 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);
1376
- }
1377
- }
1378
-
1379
- module.exports = {
1380
- parse: parse,
1381
- transform: transform
1382
- };