1 | #!/usr/bin/env node
|
2 | /**
|
3 | * Relay v7.0.0
|
4 | *
|
5 | * Copyright (c) Facebook, Inc. and its affiliates.
|
6 | *
|
7 | * This source code is licensed under the MIT license found in the
|
8 | * LICENSE file in the root directory of this source tree.
|
9 | */
|
10 | module.exports =
|
11 | /******/ (function(modules) { // webpackBootstrap
|
12 | /******/ // The module cache
|
13 | /******/ var installedModules = {};
|
14 | /******/
|
15 | /******/ // The require function
|
16 | /******/ function __webpack_require__(moduleId) {
|
17 | /******/
|
18 | /******/ // Check if module is in cache
|
19 | /******/ if(installedModules[moduleId]) {
|
20 | /******/ return installedModules[moduleId].exports;
|
21 | /******/ }
|
22 | /******/ // Create a new module (and put it into the cache)
|
23 | /******/ var module = installedModules[moduleId] = {
|
24 | /******/ i: moduleId,
|
25 | /******/ l: false,
|
26 | /******/ exports: {}
|
27 | /******/ };
|
28 | /******/
|
29 | /******/ // Execute the module function
|
30 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
31 | /******/
|
32 | /******/ // Flag the module as loaded
|
33 | /******/ module.l = true;
|
34 | /******/
|
35 | /******/ // Return the exports of the module
|
36 | /******/ return module.exports;
|
37 | /******/ }
|
38 | /******/
|
39 | /******/
|
40 | /******/ // expose the modules object (__webpack_modules__)
|
41 | /******/ __webpack_require__.m = modules;
|
42 | /******/
|
43 | /******/ // expose the module cache
|
44 | /******/ __webpack_require__.c = installedModules;
|
45 | /******/
|
46 | /******/ // define getter function for harmony exports
|
47 | /******/ __webpack_require__.d = function(exports, name, getter) {
|
48 | /******/ if(!__webpack_require__.o(exports, name)) {
|
49 | /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
50 | /******/ }
|
51 | /******/ };
|
52 | /******/
|
53 | /******/ // define __esModule on exports
|
54 | /******/ __webpack_require__.r = function(exports) {
|
55 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
56 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
57 | /******/ }
|
58 | /******/ Object.defineProperty(exports, '__esModule', { value: true });
|
59 | /******/ };
|
60 | /******/
|
61 | /******/ // create a fake namespace object
|
62 | /******/ // mode & 1: value is a module id, require it
|
63 | /******/ // mode & 2: merge all properties of value into the ns
|
64 | /******/ // mode & 4: return value when already ns object
|
65 | /******/ // mode & 8|1: behave like require
|
66 | /******/ __webpack_require__.t = function(value, mode) {
|
67 | /******/ if(mode & 1) value = __webpack_require__(value);
|
68 | /******/ if(mode & 8) return value;
|
69 | /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
70 | /******/ var ns = Object.create(null);
|
71 | /******/ __webpack_require__.r(ns);
|
72 | /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
73 | /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
74 | /******/ return ns;
|
75 | /******/ };
|
76 | /******/
|
77 | /******/ // getDefaultExport function for compatibility with non-harmony modules
|
78 | /******/ __webpack_require__.n = function(module) {
|
79 | /******/ var getter = module && module.__esModule ?
|
80 | /******/ function getDefault() { return module['default']; } :
|
81 | /******/ function getModuleExports() { return module; };
|
82 | /******/ __webpack_require__.d(getter, 'a', getter);
|
83 | /******/ return getter;
|
84 | /******/ };
|
85 | /******/
|
86 | /******/ // Object.prototype.hasOwnProperty.call
|
87 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
88 | /******/
|
89 | /******/ // __webpack_public_path__
|
90 | /******/ __webpack_require__.p = "";
|
91 | /******/
|
92 | /******/
|
93 | /******/ // Load entry module and return exports
|
94 | /******/ return __webpack_require__(__webpack_require__.s = 48);
|
95 | /******/ })
|
96 | /************************************************************************/
|
97 | /******/ ([
|
98 | /* 0 */
|
99 | /***/ (function(module, exports) {
|
100 |
|
101 | module.exports = require("@babel/runtime/helpers/interopRequireDefault");
|
102 |
|
103 | /***/ }),
|
104 | /* 1 */
|
105 | /***/ (function(module, exports, __webpack_require__) {
|
106 |
|
107 | "use strict";
|
108 | /**
|
109 | * Copyright (c) Facebook, Inc. and its affiliates.
|
110 | *
|
111 | * This source code is licensed under the MIT license found in the
|
112 | * LICENSE file in the root directory of this source tree.
|
113 | *
|
114 | *
|
115 | * @format
|
116 | */
|
117 |
|
118 |
|
119 | var _require = __webpack_require__(7),
|
120 | GraphQLError = _require.GraphQLError;
|
121 |
|
122 | /**
|
123 | * Creates an error describing invalid application code (GraphQL/Schema)
|
124 | * that must be fixed by the end developer. This should only be used
|
125 | * for local errors that don't affect processing of other user code.
|
126 | */
|
127 | function createUserError(message, locations, nodes) {
|
128 | var _nodes;
|
129 |
|
130 | var messageWithLocations = message;
|
131 |
|
132 | if (locations != null) {
|
133 | var printedLocations = printLocations(locations);
|
134 | messageWithLocations = printedLocations.length === 0 ? message : [message].concat(printedLocations).join('\n\n') + '\n';
|
135 | }
|
136 |
|
137 | return new GraphQLError(messageWithLocations, (_nodes = nodes) !== null && _nodes !== void 0 ? _nodes : []);
|
138 | }
|
139 | /**
|
140 | * Similar to createUserError but for errors that are *not* recoverable:
|
141 | * the compiler should not continue to process other inputs because their
|
142 | * validity can't be determined.
|
143 | */
|
144 |
|
145 |
|
146 | function createNonRecoverableUserError(message, locations, nodes) {
|
147 | var _nodes2;
|
148 |
|
149 | var messageWithLocations = message;
|
150 |
|
151 | if (locations != null) {
|
152 | var printedLocations = printLocations(locations);
|
153 | messageWithLocations = printedLocations.length === 0 ? message : [message].concat(printedLocations).join('\n\n') + '\n';
|
154 | }
|
155 |
|
156 | var error = new GraphQLError(messageWithLocations, (_nodes2 = nodes) !== null && _nodes2 !== void 0 ? _nodes2 : []);
|
157 | return new Error(error.message);
|
158 | }
|
159 | /**
|
160 | * Creates an error describing a problem with the compiler itself - such
|
161 | * as a broken invariant - that must be fixed within the compiler.
|
162 | */
|
163 |
|
164 |
|
165 | function createCompilerError(message, locations, nodes) {
|
166 | var _nodes3;
|
167 |
|
168 | var messageWithLocations = message;
|
169 |
|
170 | if (locations != null) {
|
171 | var printedLocations = printLocations(locations);
|
172 | messageWithLocations = printedLocations.length === 0 ? message : [message].concat(printedLocations).join('\n\n') + '\n';
|
173 | }
|
174 |
|
175 | var error = new GraphQLError("Internal Error: ".concat(messageWithLocations), (_nodes3 = nodes) !== null && _nodes3 !== void 0 ? _nodes3 : []);
|
176 | return new Error(error.message);
|
177 | }
|
178 | /**
|
179 | * Iterates over the elements of some iterable value, calling the
|
180 | * supplied callback for each item with a guard for user errors.
|
181 | *
|
182 | * Non-user errors abort the iteration and are instantly rethrown.
|
183 | * User errors are collected and rethrown at the end, if multiple user errors
|
184 | * occur, a combined error is thrown.
|
185 | */
|
186 |
|
187 |
|
188 | function eachWithCombinedError(iterable, fn) {
|
189 | var errors = [];
|
190 | var _iteratorNormalCompletion = true;
|
191 | var _didIteratorError = false;
|
192 | var _iteratorError = undefined;
|
193 |
|
194 | try {
|
195 | for (var _iterator = iterable[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
196 | var item = _step.value;
|
197 |
|
198 | try {
|
199 | fn(item);
|
200 | } catch (error) {
|
201 | if (error instanceof GraphQLError) {
|
202 | errors.push(error);
|
203 | } else {
|
204 | throw error;
|
205 | }
|
206 | }
|
207 | }
|
208 | } catch (err) {
|
209 | _didIteratorError = true;
|
210 | _iteratorError = err;
|
211 | } finally {
|
212 | try {
|
213 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
214 | _iterator["return"]();
|
215 | }
|
216 | } finally {
|
217 | if (_didIteratorError) {
|
218 | throw _iteratorError;
|
219 | }
|
220 | }
|
221 | }
|
222 |
|
223 | if (errors.length > 0) {
|
224 | if (errors.length === 1) {
|
225 | throw errors[0];
|
226 | }
|
227 |
|
228 | throw createUserError("Encountered ".concat(errors.length, " errors:\n") + errors.map(function (error) {
|
229 | return String(error).split('\n').map(function (line, index) {
|
230 | return index === 0 ? "- ".concat(line) : " ".concat(line);
|
231 | }).join('\n');
|
232 | }).join('\n'));
|
233 | }
|
234 | }
|
235 |
|
236 | function printLocations(locations) {
|
237 | var printedLocations = [];
|
238 | var _iteratorNormalCompletion2 = true;
|
239 | var _didIteratorError2 = false;
|
240 | var _iteratorError2 = undefined;
|
241 |
|
242 | try {
|
243 | for (var _iterator2 = locations[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
244 | var location = _step2.value;
|
245 | var sourceLocation = location;
|
246 |
|
247 | while (sourceLocation.kind === 'Derived') {
|
248 | sourceLocation = sourceLocation.source;
|
249 | }
|
250 |
|
251 | switch (sourceLocation.kind) {
|
252 | case 'Source':
|
253 | {
|
254 | // source location
|
255 | var prefix = sourceLocation === location ? 'Source: ' : 'Source (derived): ';
|
256 | printedLocations.push(prefix + highlightSourceAtLocation(sourceLocation.source, getLocation(sourceLocation.source, sourceLocation.start)));
|
257 | break;
|
258 | }
|
259 |
|
260 | case 'Generated':
|
261 | {
|
262 | printedLocations.push('Source: (generated)');
|
263 | break;
|
264 | }
|
265 |
|
266 | case 'Unknown':
|
267 | {
|
268 | printedLocations.push('Source: (unknown)');
|
269 | break;
|
270 | }
|
271 |
|
272 | default:
|
273 | {
|
274 | sourceLocation;
|
275 | throw createCompilerError("RelayCompilerError: cannot print location '".concat(String(sourceLocation), "'."));
|
276 | }
|
277 | }
|
278 | }
|
279 | } catch (err) {
|
280 | _didIteratorError2 = true;
|
281 | _iteratorError2 = err;
|
282 | } finally {
|
283 | try {
|
284 | if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
285 | _iterator2["return"]();
|
286 | }
|
287 | } finally {
|
288 | if (_didIteratorError2) {
|
289 | throw _iteratorError2;
|
290 | }
|
291 | }
|
292 | }
|
293 |
|
294 | return printedLocations;
|
295 | }
|
296 | /**
|
297 | * Render a helpful description of the location of the error in the GraphQL
|
298 | * Source document.
|
299 | */
|
300 |
|
301 |
|
302 | function highlightSourceAtLocation(source, location) {
|
303 | var firstLineColumnOffset = source.locationOffset.column - 1;
|
304 | var body = whitespace(firstLineColumnOffset) + source.body;
|
305 | var lineIndex = location.line - 1;
|
306 | var lineOffset = source.locationOffset.line - 1;
|
307 | var lineNum = location.line + lineOffset;
|
308 | var columnOffset = location.line === 1 ? firstLineColumnOffset : 0;
|
309 | var columnNum = location.column + columnOffset;
|
310 | var lines = body.split(/\r\n|[\n\r]/g);
|
311 | return "".concat(source.name, " (").concat(lineNum, ":").concat(columnNum, ")\n") + printPrefixedLines([// Lines specified like this: ["prefix", "string"],
|
312 | ["".concat(lineNum - 1, ": "), lines[lineIndex - 1]], ["".concat(lineNum, ": "), lines[lineIndex]], ['', whitespace(columnNum - 1) + '^'], ["".concat(lineNum + 1, ": "), lines[lineIndex + 1]]]);
|
313 | }
|
314 |
|
315 | function printPrefixedLines(lines) {
|
316 | var existingLines = lines.filter(function (_ref) {
|
317 | var _ = _ref[0],
|
318 | line = _ref[1];
|
319 | return line !== undefined;
|
320 | });
|
321 | var padLen = 0;
|
322 | var _iteratorNormalCompletion3 = true;
|
323 | var _didIteratorError3 = false;
|
324 | var _iteratorError3 = undefined;
|
325 |
|
326 | try {
|
327 | for (var _iterator3 = existingLines[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
328 | var _step3$value = _step3.value,
|
329 | prefix = _step3$value[0];
|
330 | padLen = Math.max(padLen, prefix.length);
|
331 | }
|
332 | } catch (err) {
|
333 | _didIteratorError3 = true;
|
334 | _iteratorError3 = err;
|
335 | } finally {
|
336 | try {
|
337 | if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
|
338 | _iterator3["return"]();
|
339 | }
|
340 | } finally {
|
341 | if (_didIteratorError3) {
|
342 | throw _iteratorError3;
|
343 | }
|
344 | }
|
345 | }
|
346 |
|
347 | return existingLines.map(function (_ref2) {
|
348 | var prefix = _ref2[0],
|
349 | line = _ref2[1];
|
350 | return lpad(padLen, prefix) + line;
|
351 | }).join('\n');
|
352 | }
|
353 |
|
354 | function whitespace(len) {
|
355 | return Array(len + 1).join(' ');
|
356 | }
|
357 |
|
358 | function lpad(len, str) {
|
359 | return whitespace(len - str.length) + str;
|
360 | }
|
361 |
|
362 | function getLocation(source, position) {
|
363 | var lineRegexp = /\r\n|[\n\r]/g;
|
364 | var line = 1;
|
365 | var column = position + 1;
|
366 | var match;
|
367 |
|
368 | while ((match = lineRegexp.exec(source.body)) && match.index < position) {
|
369 | line += 1;
|
370 | column = position + 1 - (match.index + match[0].length);
|
371 | }
|
372 |
|
373 | return {
|
374 | line: line,
|
375 | column: column
|
376 | };
|
377 | }
|
378 |
|
379 | module.exports = {
|
380 | createCompilerError: createCompilerError,
|
381 | createNonRecoverableUserError: createNonRecoverableUserError,
|
382 | createUserError: createUserError,
|
383 | eachWithCombinedError: eachWithCombinedError
|
384 | };
|
385 |
|
386 | /***/ }),
|
387 | /* 2 */
|
388 | /***/ (function(module, exports) {
|
389 |
|
390 | module.exports = require("@babel/runtime/helpers/objectSpread");
|
391 |
|
392 | /***/ }),
|
393 | /* 3 */
|
394 | /***/ (function(module, exports, __webpack_require__) {
|
395 |
|
396 | "use strict";
|
397 | /**
|
398 | * Copyright (c) Facebook, Inc. and its affiliates.
|
399 | *
|
400 | * This source code is licensed under the MIT license found in the
|
401 | * LICENSE file in the root directory of this source tree.
|
402 | *
|
403 | *
|
404 | * @format
|
405 | */
|
406 |
|
407 |
|
408 | var _interopRequireDefault = __webpack_require__(0);
|
409 |
|
410 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
411 |
|
412 | var invariant = __webpack_require__(4);
|
413 |
|
414 | var _require = __webpack_require__(1),
|
415 | eachWithCombinedError = _require.eachWithCombinedError;
|
416 |
|
417 | /**
|
418 | * @public
|
419 | *
|
420 | * Helper for writing compiler transforms that apply "map" and/or "filter"-style
|
421 | * operations to compiler contexts. The `visitor` argument accepts a map of IR
|
422 | * kinds to user-defined functions that can map nodes of that kind to new values
|
423 | * (of the same kind).
|
424 | *
|
425 | * If a visitor function is defined for a kind, the visitor function is
|
426 | * responsible for traversing its children (by calling `this.traverse(node)`)
|
427 | * and returning either the input (to indicate no changes), a new node (to
|
428 | * indicate changes), or null/undefined (to indicate the removal of that node
|
429 | * from the output).
|
430 | *
|
431 | * If a visitor function is *not* defined for a kind, a default traversal is
|
432 | * used to evaluate its children.
|
433 | *
|
434 | * The `stateInitializer` argument accepts an optional function to construct the
|
435 | * state for each document (fragment or root) in the context. Any documents for
|
436 | * which the initializer returns null/undefined is deleted from the context
|
437 | * without being traversed.
|
438 | *
|
439 | * Example: Alias all scalar fields with the reverse of their name:
|
440 | *
|
441 | * ```
|
442 | * transform(context, {
|
443 | * ScalarField: visitScalarField,
|
444 | * });
|
445 | *
|
446 | * function visitScalarField(field: ScalarField, state: State): ?ScalarField {
|
447 | * // Traverse child nodes - for a scalar field these are the arguments &
|
448 | * // directives.
|
449 | * const nextField = this.traverse(field, state);
|
450 | * // Return a new node with a different alias.
|
451 | * return {
|
452 | * ...nextField,
|
453 | * alias: nextField.name.split('').reverse().join(''),
|
454 | * };
|
455 | * }
|
456 | * ```
|
457 | */
|
458 | function transform(context, visitor, stateInitializer) {
|
459 | var transformer = new Transformer(context, visitor);
|
460 | return context.withMutations(function (ctx) {
|
461 | var nextContext = ctx;
|
462 | eachWithCombinedError(context.documents(), function (prevNode) {
|
463 | var nextNode;
|
464 |
|
465 | if (stateInitializer === undefined) {
|
466 | nextNode = transformer.visit(prevNode, undefined);
|
467 | } else {
|
468 | var _state = stateInitializer(prevNode);
|
469 |
|
470 | if (_state != null) {
|
471 | nextNode = transformer.visit(prevNode, _state);
|
472 | }
|
473 | }
|
474 |
|
475 | if (!nextNode) {
|
476 | nextContext = nextContext.remove(prevNode.name);
|
477 | } else if (nextNode !== prevNode) {
|
478 | nextContext = nextContext.replace(nextNode);
|
479 | }
|
480 | });
|
481 | return nextContext;
|
482 | });
|
483 | }
|
484 | /**
|
485 | * @internal
|
486 | */
|
487 |
|
488 |
|
489 | var Transformer =
|
490 | /*#__PURE__*/
|
491 | function () {
|
492 | function Transformer(context, visitor) {
|
493 | this._context = context;
|
494 | this._states = [];
|
495 | this._visitor = visitor;
|
496 | }
|
497 | /**
|
498 | * @public
|
499 | *
|
500 | * Returns the original compiler context that is being transformed. This can
|
501 | * be used to look up fragments by name, for example.
|
502 | */
|
503 |
|
504 |
|
505 | var _proto = Transformer.prototype;
|
506 |
|
507 | _proto.getContext = function getContext() {
|
508 | return this._context;
|
509 | }
|
510 | /**
|
511 | * @public
|
512 | *
|
513 | * Transforms the node, calling a user-defined visitor function if defined for
|
514 | * the node's kind. Uses the given state for this portion of the traversal.
|
515 | *
|
516 | * Note: This differs from `traverse` in that it calls a visitor function for
|
517 | * the node itself.
|
518 | */
|
519 | ;
|
520 |
|
521 | _proto.visit = function visit(node, state) {
|
522 | this._states.push(state);
|
523 |
|
524 | var nextNode = this._visit(node);
|
525 |
|
526 | this._states.pop();
|
527 |
|
528 | return nextNode;
|
529 | }
|
530 | /**
|
531 | * @public
|
532 | *
|
533 | * Transforms the children of the given node, skipping the user-defined
|
534 | * visitor function for the node itself. Uses the given state for this portion
|
535 | * of the traversal.
|
536 | *
|
537 | * Note: This differs from `visit` in that it does not call a visitor function
|
538 | * for the node itself.
|
539 | */
|
540 | ;
|
541 |
|
542 | _proto.traverse = function traverse(node, state) {
|
543 | this._states.push(state);
|
544 |
|
545 | var nextNode = this._traverse(node);
|
546 |
|
547 | this._states.pop();
|
548 |
|
549 | return nextNode;
|
550 | };
|
551 |
|
552 | _proto._visit = function _visit(node) {
|
553 | var nodeVisitor = this._visitor[node.kind];
|
554 |
|
555 | if (nodeVisitor) {
|
556 | // If a handler for the kind is defined, it is responsible for calling
|
557 | // `traverse` to transform children as necessary.
|
558 | var _state2 = this._getState();
|
559 |
|
560 | var nextNode = nodeVisitor.call(this, node, _state2);
|
561 | return nextNode;
|
562 | } // Otherwise traverse is called automatically.
|
563 |
|
564 |
|
565 | return this._traverse(node);
|
566 | };
|
567 |
|
568 | _proto._traverse = function _traverse(prevNode) {
|
569 | var nextNode;
|
570 |
|
571 | switch (prevNode.kind) {
|
572 | case 'Argument':
|
573 | nextNode = this._traverseChildren(prevNode, null, ['value']);
|
574 | break;
|
575 |
|
576 | case 'Literal':
|
577 | case 'LocalArgumentDefinition':
|
578 | case 'RootArgumentDefinition':
|
579 | case 'Variable':
|
580 | nextNode = prevNode;
|
581 | break;
|
582 |
|
583 | case 'Defer':
|
584 | nextNode = this._traverseChildren(prevNode, ['selections'], ['if']);
|
585 | break;
|
586 |
|
587 | case 'Stream':
|
588 | nextNode = this._traverseChildren(prevNode, ['selections'], ['if', 'initialCount']);
|
589 | break;
|
590 |
|
591 | case 'ClientExtension':
|
592 | nextNode = this._traverseChildren(prevNode, ['selections']);
|
593 | break;
|
594 |
|
595 | case 'Directive':
|
596 | nextNode = this._traverseChildren(prevNode, ['args']);
|
597 | break;
|
598 |
|
599 | case 'ModuleImport':
|
600 | nextNode = this._traverseChildren(prevNode, ['selections']);
|
601 |
|
602 | if (!nextNode.selections.length) {
|
603 | nextNode = null;
|
604 | }
|
605 |
|
606 | break;
|
607 |
|
608 | case 'FragmentSpread':
|
609 | case 'ScalarField':
|
610 | nextNode = this._traverseChildren(prevNode, ['args', 'directives']);
|
611 | break;
|
612 |
|
613 | case 'InlineDataFragmentSpread':
|
614 | nextNode = this._traverseChildren(prevNode, ['selections']);
|
615 | break;
|
616 |
|
617 | case 'ConnectionField':
|
618 | case 'LinkedField':
|
619 | nextNode = this._traverseChildren(prevNode, ['args', 'directives', 'selections']);
|
620 |
|
621 | if (!nextNode.selections.length) {
|
622 | nextNode = null;
|
623 | }
|
624 |
|
625 | break;
|
626 |
|
627 | case 'Connection':
|
628 | nextNode = this._traverseChildren(prevNode, ['args', 'selections']);
|
629 |
|
630 | if (!nextNode.selections.length) {
|
631 | nextNode = null;
|
632 | }
|
633 |
|
634 | break;
|
635 |
|
636 | case 'Condition':
|
637 | nextNode = this._traverseChildren(prevNode, ['directives', 'selections'], ['condition']);
|
638 |
|
639 | if (!nextNode.selections.length) {
|
640 | nextNode = null;
|
641 | }
|
642 |
|
643 | break;
|
644 |
|
645 | case 'InlineFragment':
|
646 | nextNode = this._traverseChildren(prevNode, ['directives', 'selections']);
|
647 |
|
648 | if (!nextNode.selections.length) {
|
649 | nextNode = null;
|
650 | }
|
651 |
|
652 | break;
|
653 |
|
654 | case 'Fragment':
|
655 | case 'Root':
|
656 | nextNode = this._traverseChildren(prevNode, ['argumentDefinitions', 'directives', 'selections']);
|
657 | break;
|
658 |
|
659 | case 'Request':
|
660 | nextNode = this._traverseChildren(prevNode, null, ['fragment', 'root']);
|
661 | break;
|
662 |
|
663 | case 'SplitOperation':
|
664 | nextNode = this._traverseChildren(prevNode, ['selections']);
|
665 | break;
|
666 |
|
667 | default:
|
668 | prevNode;
|
669 | true ? true ? invariant(false, 'GraphQLIRTransformer: Unknown kind `%s`.', prevNode.kind) : undefined : undefined;
|
670 | }
|
671 |
|
672 | return nextNode;
|
673 | };
|
674 |
|
675 | _proto._traverseChildren = function _traverseChildren(prevNode, pluralKeys, singularKeys) {
|
676 | var _this = this;
|
677 |
|
678 | var nextNode;
|
679 | pluralKeys && pluralKeys.forEach(function (key) {
|
680 | var prevItems = prevNode[key];
|
681 |
|
682 | if (!prevItems) {
|
683 | return;
|
684 | }
|
685 |
|
686 | !Array.isArray(prevItems) ? true ? invariant(false, 'GraphQLIRTransformer: Expected data for `%s` to be an array, got `%s`.', key, prevItems) : undefined : void 0;
|
687 |
|
688 | var nextItems = _this._map(prevItems);
|
689 |
|
690 | if (nextNode || nextItems !== prevItems) {
|
691 | nextNode = nextNode || (0, _objectSpread2["default"])({}, prevNode);
|
692 | nextNode[key] = nextItems;
|
693 | }
|
694 | });
|
695 | singularKeys && singularKeys.forEach(function (key) {
|
696 | var prevItem = prevNode[key];
|
697 |
|
698 | if (!prevItem) {
|
699 | return;
|
700 | }
|
701 |
|
702 | var nextItem = _this._visit(prevItem);
|
703 |
|
704 | if (nextNode || nextItem !== prevItem) {
|
705 | nextNode = nextNode || (0, _objectSpread2["default"])({}, prevNode);
|
706 | nextNode[key] = nextItem;
|
707 | }
|
708 | });
|
709 | return nextNode || prevNode;
|
710 | };
|
711 |
|
712 | _proto._map = function _map(prevItems) {
|
713 | var _this2 = this;
|
714 |
|
715 | var nextItems;
|
716 | prevItems.forEach(function (prevItem, index) {
|
717 | var nextItem = _this2._visit(prevItem);
|
718 |
|
719 | if (nextItems || nextItem !== prevItem) {
|
720 | nextItems = nextItems || prevItems.slice(0, index);
|
721 |
|
722 | if (nextItem) {
|
723 | nextItems.push(nextItem);
|
724 | }
|
725 | }
|
726 | });
|
727 | return nextItems || prevItems;
|
728 | };
|
729 |
|
730 | _proto._getState = function _getState() {
|
731 | !this._states.length ? true ? invariant(false, 'GraphQLIRTransformer: Expected a current state to be set but found none. ' + 'This is usually the result of mismatched number of pushState()/popState() ' + 'calls.') : undefined : void 0;
|
732 | return this._states[this._states.length - 1];
|
733 | };
|
734 |
|
735 | return Transformer;
|
736 | }();
|
737 |
|
738 | module.exports = {
|
739 | transform: transform
|
740 | };
|
741 |
|
742 | /***/ }),
|
743 | /* 4 */
|
744 | /***/ (function(module, exports) {
|
745 |
|
746 | module.exports = require("fbjs/lib/invariant");
|
747 |
|
748 | /***/ }),
|
749 | /* 5 */
|
750 | /***/ (function(module, exports) {
|
751 |
|
752 | module.exports = require("@babel/runtime/helpers/toConsumableArray");
|
753 |
|
754 | /***/ }),
|
755 | /* 6 */
|
756 | /***/ (function(module, exports, __webpack_require__) {
|
757 |
|
758 | "use strict";
|
759 | /**
|
760 | * Copyright (c) Facebook, Inc. and its affiliates.
|
761 | *
|
762 | * This source code is licensed under the MIT license found in the
|
763 | * LICENSE file in the root directory of this source tree.
|
764 | *
|
765 | *
|
766 | * @format
|
767 | */
|
768 |
|
769 |
|
770 | var _asyncToGenerator = __webpack_require__(10);
|
771 |
|
772 | var invariant = __webpack_require__(4);
|
773 | /**
|
774 | * The compiler profiler builds a "call graph" of high level operations as a
|
775 | * means of tracking time spent over the course of running the compiler.
|
776 | */
|
777 |
|
778 |
|
779 | var enabled = false;
|
780 | var traces = [{
|
781 | ph: 'M',
|
782 | pid: 0,
|
783 | tid: 0,
|
784 | name: 'process_name',
|
785 | args: {
|
786 | name: 'relay-compiler'
|
787 | }
|
788 | }, {
|
789 | ph: 'M',
|
790 | pid: 0,
|
791 | tid: 0,
|
792 | name: 'thread_name',
|
793 | args: {
|
794 | name: 'relay-compiler'
|
795 | }
|
796 | }];
|
797 | var stack = [];
|
798 |
|
799 | function enable() {
|
800 | enabled = true;
|
801 | }
|
802 |
|
803 | function getTraces() {
|
804 | return traces;
|
805 | }
|
806 | /**
|
807 | * Run the provided function as part of a stack profile.
|
808 | */
|
809 |
|
810 |
|
811 | function run(name, fn) {
|
812 | return instrument(fn, name)();
|
813 | }
|
814 | /**
|
815 | * Run the provided async function as part context in a stack profile.
|
816 | * See instrumentAsyncContext() for limitations and usage notes.
|
817 | */
|
818 |
|
819 |
|
820 | function asyncContext(name, fn) {
|
821 | return instrumentAsyncContext(fn, name)();
|
822 | }
|
823 | /**
|
824 | * Wait for the provided async operation as an async profile.
|
825 | */
|
826 |
|
827 |
|
828 | function waitFor(name, fn) {
|
829 | return instrumentWait(fn, name)();
|
830 | }
|
831 | /**
|
832 | * Return a new instrumented sync function to be part of a stack profile.
|
833 | *
|
834 | * This instruments synchronous functions to be displayed in a stack
|
835 | * visualization. To instrument async functions, see instrumentAsyncContext()
|
836 | * and instrumentWait().
|
837 | */
|
838 |
|
839 |
|
840 | function instrument(fn, name) {
|
841 | var _ref, _name;
|
842 |
|
843 | if (!enabled) {
|
844 | return fn;
|
845 | }
|
846 |
|
847 | var profileName = (_ref = (_name = name) !== null && _name !== void 0 ? _name : // $FlowFixMe - Flow no longer considers statics of functions as any
|
848 | fn.displayName) !== null && _ref !== void 0 ? _ref : fn.name;
|
849 |
|
850 | var instrumented = function instrumented() {
|
851 | var traceId = start(profileName);
|
852 |
|
853 | try {
|
854 | return fn.apply(this, arguments);
|
855 | } finally {
|
856 | end(traceId);
|
857 | }
|
858 | };
|
859 |
|
860 | instrumented.displayName = profileName;
|
861 | return instrumented;
|
862 | }
|
863 | /**
|
864 | * Return a new instrumented async function which provides context for a stack.
|
865 | *
|
866 | * Because the resulting profiling information will be incorporated into a
|
867 | * stack visualization, the instrumented function must represent a distinct
|
868 | * region of time which does not overlap with any other async context.
|
869 | *
|
870 | * In other words, functions instrumented with instrumentAsyncContext must not
|
871 | * run in parallel via Promise.all().
|
872 | *
|
873 | * To instrument functions which will run in parallel, use instrumentWait().
|
874 | */
|
875 |
|
876 |
|
877 | function instrumentAsyncContext(fn, name) {
|
878 | var _ref2, _name2;
|
879 |
|
880 | if (!enabled) {
|
881 | return fn;
|
882 | }
|
883 |
|
884 | var profileName = (_ref2 = (_name2 = name) !== null && _name2 !== void 0 ? _name2 : // $FlowFixMe - Flow no longer considers statics of functions as any
|
885 | fn.displayName) !== null && _ref2 !== void 0 ? _ref2 : fn.name;
|
886 |
|
887 | var instrumented =
|
888 | /*#__PURE__*/
|
889 | function () {
|
890 | var _instrumented = _asyncToGenerator(function* () {
|
891 | var traceId = start(profileName);
|
892 |
|
893 | try {
|
894 | return yield fn.apply(this, arguments);
|
895 | } finally {
|
896 | end(traceId);
|
897 | }
|
898 | });
|
899 |
|
900 | function instrumented() {
|
901 | return _instrumented.apply(this, arguments);
|
902 | }
|
903 |
|
904 | return instrumented;
|
905 | }();
|
906 |
|
907 | instrumented.displayName = profileName;
|
908 | return instrumented;
|
909 | }
|
910 | /**
|
911 | * Return a new instrumented function which performs an awaited async operation.
|
912 | *
|
913 | * The instrumented function is not included in the overall run time of the
|
914 | * compiler, instead it captures the time waiting on some asynchronous external
|
915 | * resource such as network or filesystem which are often run in parallel.
|
916 | */
|
917 |
|
918 |
|
919 | function instrumentWait(fn, name) {
|
920 | var _ref3, _name3;
|
921 |
|
922 | if (!enabled) {
|
923 | return fn;
|
924 | }
|
925 |
|
926 | var profileName = (_ref3 = (_name3 = name) !== null && _name3 !== void 0 ? _name3 : // $FlowFixMe - Flow no longer considers statics of functions as any
|
927 | fn.displayName) !== null && _ref3 !== void 0 ? _ref3 : fn.name;
|
928 |
|
929 | var instrumented =
|
930 | /*#__PURE__*/
|
931 | function () {
|
932 | var _instrumented2 = _asyncToGenerator(function* () {
|
933 | var traceId = startWait(profileName);
|
934 |
|
935 | try {
|
936 | return yield fn.apply(this, arguments);
|
937 | } finally {
|
938 | end(traceId);
|
939 | }
|
940 | });
|
941 |
|
942 | function instrumented() {
|
943 | return _instrumented2.apply(this, arguments);
|
944 | }
|
945 |
|
946 | return instrumented;
|
947 | }();
|
948 |
|
949 | instrumented.displayName = profileName;
|
950 | return instrumented;
|
951 | }
|
952 |
|
953 | var T_ZERO = process.hrtime(); // Return a Uint32 of microtime duration since program start.
|
954 |
|
955 | function microtime() {
|
956 | var hrtime = process.hrtime(T_ZERO); // eslint-disable-next-line no-bitwise
|
957 |
|
958 | return 0 | hrtime[0] * 1e6 + Math.round(hrtime[1] / 1e3);
|
959 | }
|
960 | /**
|
961 | * Start a stack profile with a particular name, returns an ID to pass to end().
|
962 | *
|
963 | * Other profiles may start before this one ends, which will be represented as
|
964 | * nested operations, however all nested operations must end before this ends.
|
965 | *
|
966 | * In particular, be careful to end after errors.
|
967 | */
|
968 |
|
969 |
|
970 | function start(name) {
|
971 | var beginTrace = {
|
972 | ph: 'B',
|
973 | name: name,
|
974 | pid: 0,
|
975 | tid: 0,
|
976 | ts: microtime()
|
977 | };
|
978 | traces.push(beginTrace);
|
979 | stack.push(beginTrace);
|
980 | return traces.length - 1;
|
981 | }
|
982 |
|
983 | var asyncID = 0;
|
984 | /**
|
985 | * Start an async wait profile with a particular name, returns an ID to pass
|
986 | * to end().
|
987 | *
|
988 | * Other profiles may start before this one ends, which will be represented as
|
989 | * nested operations, however all nested operations must end before this ends.
|
990 | *
|
991 | * In particular, be careful to end after errors.
|
992 | */
|
993 |
|
994 | function startWait(name) {
|
995 | traces.push({
|
996 | ph: 'b',
|
997 | name: name,
|
998 | cat: 'wait',
|
999 | id: asyncID++,
|
1000 | pid: 0,
|
1001 | tid: 0,
|
1002 | ts: microtime()
|
1003 | });
|
1004 | return traces.length - 1;
|
1005 | }
|
1006 |
|
1007 | function end(traceIdx) {
|
1008 | var trace = traces[traceIdx];
|
1009 |
|
1010 | if (trace.ph === 'b') {
|
1011 | traces.push({
|
1012 | ph: 'e',
|
1013 | cat: trace.cat,
|
1014 | name: trace.name,
|
1015 | id: trace.id,
|
1016 | pid: trace.pid,
|
1017 | tid: trace.tid,
|
1018 | ts: microtime()
|
1019 | });
|
1020 | return;
|
1021 | }
|
1022 |
|
1023 | !(trace.ph === 'B') ? true ? invariant(false, 'Begin trace phase') : undefined : void 0;
|
1024 | !(stack.pop() === trace) ? true ? invariant(false, 'GraphQLCompilerProfiler: The profile trace %s ended before nested traces. ' + 'If it is async, try using Profile.waitFor or Profile.profileWait.', trace.name) : undefined : void 0;
|
1025 | var prevTrace = traces[traces.length - 1];
|
1026 |
|
1027 | if (trace === prevTrace) {
|
1028 | traces[traceIdx] = {
|
1029 | ph: 'X',
|
1030 | name: trace.name,
|
1031 | pid: trace.pid,
|
1032 | tid: trace.tid,
|
1033 | ts: trace.ts,
|
1034 | dur: microtime() - trace.ts
|
1035 | };
|
1036 | return;
|
1037 | }
|
1038 |
|
1039 | traces.push({
|
1040 | ph: 'E',
|
1041 | name: trace.name,
|
1042 | pid: trace.pid,
|
1043 | tid: trace.tid,
|
1044 | ts: microtime()
|
1045 | });
|
1046 | }
|
1047 |
|
1048 | module.exports = {
|
1049 | enable: enable,
|
1050 | getTraces: getTraces,
|
1051 | run: run,
|
1052 | asyncContext: asyncContext,
|
1053 | waitFor: waitFor,
|
1054 | instrument: instrument,
|
1055 | instrumentAsyncContext: instrumentAsyncContext,
|
1056 | instrumentWait: instrumentWait,
|
1057 | start: start,
|
1058 | startWait: startWait,
|
1059 | end: end
|
1060 | };
|
1061 |
|
1062 | /***/ }),
|
1063 | /* 7 */
|
1064 | /***/ (function(module, exports) {
|
1065 |
|
1066 | module.exports = require("graphql");
|
1067 |
|
1068 | /***/ }),
|
1069 | /* 8 */
|
1070 | /***/ (function(module, exports) {
|
1071 |
|
1072 | module.exports = require("path");
|
1073 |
|
1074 | /***/ }),
|
1075 | /* 9 */
|
1076 | /***/ (function(module, exports) {
|
1077 |
|
1078 | module.exports = require("relay-runtime");
|
1079 |
|
1080 | /***/ }),
|
1081 | /* 10 */
|
1082 | /***/ (function(module, exports) {
|
1083 |
|
1084 | module.exports = require("@babel/runtime/helpers/asyncToGenerator");
|
1085 |
|
1086 | /***/ }),
|
1087 | /* 11 */
|
1088 | /***/ (function(module, exports, __webpack_require__) {
|
1089 |
|
1090 | "use strict";
|
1091 | /**
|
1092 | * Copyright (c) Facebook, Inc. and its affiliates.
|
1093 | *
|
1094 | * This source code is licensed under the MIT license found in the
|
1095 | * LICENSE file in the root directory of this source tree.
|
1096 | *
|
1097 | *
|
1098 | * @format
|
1099 | */
|
1100 |
|
1101 |
|
1102 | var ID = 'id';
|
1103 | /**
|
1104 | * @public
|
1105 | *
|
1106 | * Determine if an AST node contains a fragment/operation definition.
|
1107 | */
|
1108 |
|
1109 | function isExecutableDefinitionAST(ast) {
|
1110 | return ast.kind === 'FragmentDefinition' || ast.kind === 'OperationDefinition';
|
1111 | }
|
1112 | /**
|
1113 | * @public
|
1114 | *
|
1115 | * Determine if an AST node contains a schema definition.
|
1116 | */
|
1117 |
|
1118 |
|
1119 | function isSchemaDefinitionAST(ast) {
|
1120 | return ast.kind === 'SchemaDefinition' || ast.kind === 'ScalarTypeDefinition' || ast.kind === 'ObjectTypeDefinition' || ast.kind === 'InterfaceTypeDefinition' || ast.kind === 'UnionTypeDefinition' || ast.kind === 'EnumTypeDefinition' || ast.kind === 'InputObjectTypeDefinition' || ast.kind === 'DirectiveDefinition' || ast.kind === 'ScalarTypeExtension' || ast.kind === 'ObjectTypeExtension' || ast.kind === 'InterfaceTypeExtension' || ast.kind === 'UnionTypeExtension' || ast.kind === 'EnumTypeExtension' || ast.kind === 'InputObjectTypeExtension';
|
1121 | }
|
1122 |
|
1123 | function generateIDField(idType) {
|
1124 | return {
|
1125 | kind: 'ScalarField',
|
1126 | alias: ID,
|
1127 | args: [],
|
1128 | directives: [],
|
1129 | handles: null,
|
1130 | loc: {
|
1131 | kind: 'Generated'
|
1132 | },
|
1133 | metadata: null,
|
1134 | name: ID,
|
1135 | type: idType
|
1136 | };
|
1137 | }
|
1138 |
|
1139 | function getNullableBooleanInput(schema) {
|
1140 | return schema.assertInputType(schema.expectBooleanType());
|
1141 | }
|
1142 |
|
1143 | function getNonNullBooleanInput(schema) {
|
1144 | return schema.assertInputType(schema.getNonNullType(schema.expectBooleanType()));
|
1145 | }
|
1146 |
|
1147 | function getNullableStringInput(schema) {
|
1148 | return schema.assertInputType(schema.expectStringType());
|
1149 | }
|
1150 |
|
1151 | function getNonNullStringInput(schema) {
|
1152 | return schema.assertInputType(schema.getNonNullType(schema.expectStringType()));
|
1153 | }
|
1154 |
|
1155 | function getNullableIdInput(schema) {
|
1156 | return schema.assertInputType(schema.expectIdType());
|
1157 | }
|
1158 |
|
1159 | function getNonNullIdInput(schema) {
|
1160 | return schema.assertInputType(schema.getNonNullType(schema.expectIdType()));
|
1161 | }
|
1162 |
|
1163 | module.exports = {
|
1164 | generateIDField: generateIDField,
|
1165 | isExecutableDefinitionAST: isExecutableDefinitionAST,
|
1166 | isSchemaDefinitionAST: isSchemaDefinitionAST,
|
1167 | getNullableBooleanInput: getNullableBooleanInput,
|
1168 | getNonNullBooleanInput: getNonNullBooleanInput,
|
1169 | getNullableStringInput: getNullableStringInput,
|
1170 | getNonNullStringInput: getNonNullStringInput,
|
1171 | getNullableIdInput: getNullableIdInput,
|
1172 | getNonNullIdInput: getNonNullIdInput
|
1173 | };
|
1174 |
|
1175 | /***/ }),
|
1176 | /* 12 */
|
1177 | /***/ (function(module, exports) {
|
1178 |
|
1179 | module.exports = require("crypto");
|
1180 |
|
1181 | /***/ }),
|
1182 | /* 13 */
|
1183 | /***/ (function(module, exports) {
|
1184 |
|
1185 | module.exports = require("fs");
|
1186 |
|
1187 | /***/ }),
|
1188 | /* 14 */
|
1189 | /***/ (function(module, exports) {
|
1190 |
|
1191 | module.exports = require("immutable");
|
1192 |
|
1193 | /***/ }),
|
1194 | /* 15 */
|
1195 | /***/ (function(module, exports, __webpack_require__) {
|
1196 |
|
1197 | "use strict";
|
1198 | /**
|
1199 | * Copyright (c) Facebook, Inc. and its affiliates.
|
1200 | *
|
1201 | * This source code is licensed under the MIT license found in the
|
1202 | * LICENSE file in the root directory of this source tree.
|
1203 | *
|
1204 | *
|
1205 | * @format
|
1206 | */
|
1207 |
|
1208 |
|
1209 | var _require = __webpack_require__(7),
|
1210 | visit = _require.visit;
|
1211 |
|
1212 | var NodeKeys = {
|
1213 | Argument: ['value'],
|
1214 | ClientExtension: ['selections'],
|
1215 | Condition: ['condition', 'selections'],
|
1216 | Defer: ['selections', 'if'],
|
1217 | Connection: ['args', 'selections'],
|
1218 | ConnectionField: ['args', 'directives', 'selections'],
|
1219 | Directive: ['args'],
|
1220 | Fragment: ['argumentDefinitions', 'directives', 'selections'],
|
1221 | FragmentSpread: ['args', 'directives'],
|
1222 | InlineDataFragmentSpread: ['selections'],
|
1223 | InlineFragment: ['directives', 'selections'],
|
1224 | LinkedField: ['args', 'directives', 'selections'],
|
1225 | Literal: [],
|
1226 | LocalArgumentDefinition: [],
|
1227 | ModuleImport: ['selections'],
|
1228 | Request: ['fragment', 'root'],
|
1229 | Root: ['argumentDefinitions', 'directives', 'selections'],
|
1230 | RootArgumentDefinition: [],
|
1231 | ScalarField: ['args', 'directives'],
|
1232 | SplitOperation: ['selections'],
|
1233 | Stream: ['selections', 'if', 'initialCount'],
|
1234 | Variable: []
|
1235 | };
|
1236 |
|
1237 | function visitIR(root, visitor) {
|
1238 | return visit(root, visitor, NodeKeys);
|
1239 | }
|
1240 |
|
1241 | module.exports = {
|
1242 | visit: visitIR
|
1243 | };
|
1244 |
|
1245 | /***/ }),
|
1246 | /* 16 */
|
1247 | /***/ (function(module, exports, __webpack_require__) {
|
1248 |
|
1249 | "use strict";
|
1250 | /**
|
1251 | * Copyright (c) Facebook, Inc. and its affiliates.
|
1252 | *
|
1253 | * This source code is licensed under the MIT license found in the
|
1254 | * LICENSE file in the root directory of this source tree.
|
1255 | *
|
1256 | *
|
1257 | * @format
|
1258 | */
|
1259 |
|
1260 |
|
1261 | // Copy of Variables type from '../../../react-relay/classic/tools/RelayTypes'
|
1262 | // Duplicating here rather than importing it since we can't take on a dependency
|
1263 | // outside of relay-compiler.
|
1264 | function getLiteralArgumentValues(args) {
|
1265 | var values = {};
|
1266 | args.forEach(function (arg) {
|
1267 | if (arg.value.kind === 'Literal') {
|
1268 | values[arg.name] = arg.value.value;
|
1269 | }
|
1270 | });
|
1271 | return values;
|
1272 | }
|
1273 |
|
1274 | module.exports = getLiteralArgumentValues;
|
1275 |
|
1276 | /***/ }),
|
1277 | /* 17 */
|
1278 | /***/ (function(module, exports, __webpack_require__) {
|
1279 |
|
1280 | "use strict";
|
1281 | /**
|
1282 | * Copyright (c) Facebook, Inc. and its affiliates.
|
1283 | *
|
1284 | * This source code is licensed under the MIT license found in the
|
1285 | * LICENSE file in the root directory of this source tree.
|
1286 | *
|
1287 | *
|
1288 | * @format
|
1289 | */
|
1290 |
|
1291 |
|
1292 | var _interopRequireDefault = __webpack_require__(0);
|
1293 |
|
1294 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
1295 |
|
1296 | var GraphQLCompilerContext = __webpack_require__(19);
|
1297 |
|
1298 | var GraphQLIRVisitor = __webpack_require__(15);
|
1299 |
|
1300 | var SchemaUtils = __webpack_require__(11);
|
1301 |
|
1302 | var _require = __webpack_require__(1),
|
1303 | createCompilerError = _require.createCompilerError;
|
1304 |
|
1305 | /**
|
1306 | * Returns a transformed version of the input context where each document's
|
1307 | * argument definitions are updated to accurately describe the root variables
|
1308 | * used (or reachable) from that document:
|
1309 | * - Fragment argument definitions are updated to include local argument
|
1310 | * definitions and any root variables that are referenced
|
1311 | * by the fragment (or any fragments it transitively spreads).
|
1312 | * - Root argument definitions are updated to reflect the variables
|
1313 | * referenced locally and all root variables referenced by any
|
1314 | * fragments it (transitively) spreads.
|
1315 | */
|
1316 | function inferRootArgumentDefinitions(context) {
|
1317 | // This transform does two main tasks:
|
1318 | // - Determine the set of root variables referenced locally in each
|
1319 | // fragment. Note that RootArgumentDefinitions in the fragment's
|
1320 | // argumentDefinitions can contain spurious entries for legacy
|
1321 | // reasons. Instead of using those the fragment is traversed
|
1322 | // to reanalyze variable usage.
|
1323 | // - Determine the set of root variables that are transitively referenced
|
1324 | // by each fragment, ie the union of all root variables used in the
|
1325 | // fragment and any fragments it transitively spreads.
|
1326 | // Cache fragments as they are transformed to avoid duplicate processing.
|
1327 | // Because @argument values don't matter (only variable names/types),
|
1328 | // each reachable fragment only has to be checked once.
|
1329 | var transformed = new Map();
|
1330 | var nextContext = new GraphQLCompilerContext(context.getSchema());
|
1331 | return nextContext.addAll(Array.from(context.documents(), function (node) {
|
1332 | switch (node.kind) {
|
1333 | case 'Fragment':
|
1334 | {
|
1335 | var argumentDefinitions = transformFragmentArguments(context, transformed, node);
|
1336 | return (0, _objectSpread2["default"])({}, node, {
|
1337 | argumentDefinitions: Array.from(argumentDefinitions.values())
|
1338 | });
|
1339 | }
|
1340 |
|
1341 | case 'Root':
|
1342 | {
|
1343 | return transformRoot(context, transformed, node);
|
1344 | }
|
1345 |
|
1346 | case 'SplitOperation':
|
1347 | {
|
1348 | return node;
|
1349 | }
|
1350 |
|
1351 | default:
|
1352 | {
|
1353 | node;
|
1354 | throw createCompilerError("inferRootArgumentDefinitions: Unsupported kind '".concat(node.kind, "'."));
|
1355 | }
|
1356 | }
|
1357 | }));
|
1358 | }
|
1359 |
|
1360 | function transformRoot(context, transformed, root) {
|
1361 | // Ignore argument definitions, determine what root variables are
|
1362 | // transitively referenced
|
1363 | var argumentDefinitions = new Map();
|
1364 | var localArgumentDefinitions = new Map();
|
1365 | var _iteratorNormalCompletion = true;
|
1366 | var _didIteratorError = false;
|
1367 | var _iteratorError = undefined;
|
1368 |
|
1369 | try {
|
1370 | for (var _iterator = root.argumentDefinitions.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
1371 | var _step$value = _step.value,
|
1372 | name = _step$value[0],
|
1373 | argDef = _step$value[1];
|
1374 |
|
1375 | if (argDef.kind === 'LocalArgumentDefinition') {
|
1376 | localArgumentDefinitions.set(name, argDef);
|
1377 | }
|
1378 | }
|
1379 | } catch (err) {
|
1380 | _didIteratorError = true;
|
1381 | _iteratorError = err;
|
1382 | } finally {
|
1383 | try {
|
1384 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
1385 | _iterator["return"]();
|
1386 | }
|
1387 | } finally {
|
1388 | if (_didIteratorError) {
|
1389 | throw _iteratorError;
|
1390 | }
|
1391 | }
|
1392 | }
|
1393 |
|
1394 | visit(context, transformed, argumentDefinitions, root);
|
1395 | return (0, _objectSpread2["default"])({}, root, {
|
1396 | argumentDefinitions: Array.from(argumentDefinitions.values(), function (argDef) {
|
1397 | var _ref, _ref2;
|
1398 |
|
1399 | if (argDef.kind !== 'RootArgumentDefinition') {
|
1400 | throw createCompilerError("inferRootArgumentDefinitions: Expected inferred variable '$".concat(argDef.name, "' to be a root variables."), [argDef.loc]);
|
1401 | }
|
1402 |
|
1403 | var localDefinition = localArgumentDefinitions.get(argDef.name);
|
1404 | var type = (_ref = localDefinition === null || localDefinition === void 0 ? void 0 : localDefinition.type) !== null && _ref !== void 0 ? _ref : argDef.type;
|
1405 | return {
|
1406 | defaultValue: (_ref2 = localDefinition === null || localDefinition === void 0 ? void 0 : localDefinition.defaultValue) !== null && _ref2 !== void 0 ? _ref2 : null,
|
1407 | kind: 'LocalArgumentDefinition',
|
1408 | loc: argDef.loc,
|
1409 | name: argDef.name,
|
1410 | type: type
|
1411 | };
|
1412 | })
|
1413 | });
|
1414 | }
|
1415 |
|
1416 | function transformFragmentArguments(context, transformed, fragment) {
|
1417 | var name = fragment.name;
|
1418 | var transformedArguments = transformed.get(name);
|
1419 |
|
1420 | if (transformedArguments != null) {
|
1421 | return transformedArguments;
|
1422 | } // Start with only the explicitly defined local arguments, recover the
|
1423 | // correct set of root variables excluding invalid @arguments values.
|
1424 |
|
1425 |
|
1426 | var argumentDefinitions = new Map();
|
1427 | fragment.argumentDefinitions.forEach(function (argDef) {
|
1428 | if (argDef.kind === 'LocalArgumentDefinition') {
|
1429 | argumentDefinitions.set(argDef.name, argDef);
|
1430 | }
|
1431 | }); // Break cycles by initially caching a version that only has local
|
1432 | // arguments. If the current fragment is reached again, it won't have
|
1433 | // any root variables to add to its parents. The traversal below will
|
1434 | // find any root variables and update the cached version of the
|
1435 | // fragment.
|
1436 |
|
1437 | transformed.set(name, argumentDefinitions);
|
1438 | visit(context, transformed, argumentDefinitions, fragment);
|
1439 | transformed.set(name, argumentDefinitions);
|
1440 | return argumentDefinitions;
|
1441 | }
|
1442 |
|
1443 | function visit(context, transformed, argumentDefinitions, node) {
|
1444 | GraphQLIRVisitor.visit(node, {
|
1445 | FragmentSpread: function FragmentSpread(fragmentSpread) {
|
1446 | var fragment = context.getFragment(fragmentSpread.name, fragmentSpread.loc);
|
1447 | var referencedFragmentArguments = transformFragmentArguments(context, transformed, fragment); // Detect root variables being passed as the value of @arguments;
|
1448 | // recover the expected type from the corresponding argument definitions.
|
1449 |
|
1450 | fragmentSpread.args.forEach(function (arg) {
|
1451 | var argDef = referencedFragmentArguments.get(arg.name);
|
1452 |
|
1453 | if (argDef != null && arg.value.kind === 'Variable' && !argumentDefinitions.has(arg.value.variableName)) {
|
1454 | argumentDefinitions.set(arg.value.variableName, {
|
1455 | kind: 'RootArgumentDefinition',
|
1456 | loc: {
|
1457 | kind: 'Derived',
|
1458 | source: arg.loc
|
1459 | },
|
1460 | name: arg.value.variableName,
|
1461 | type: argDef.type
|
1462 | });
|
1463 | }
|
1464 | }); // Merge any root variables referenced by the spread fragment
|
1465 | // into this (parent) fragment's arguments.
|
1466 |
|
1467 | var _iteratorNormalCompletion2 = true;
|
1468 | var _didIteratorError2 = false;
|
1469 | var _iteratorError2 = undefined;
|
1470 |
|
1471 | try {
|
1472 | for (var _iterator2 = referencedFragmentArguments.values()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
1473 | var argDef = _step2.value;
|
1474 |
|
1475 | if (argDef.kind === 'RootArgumentDefinition') {
|
1476 | argumentDefinitions.set(argDef.name, argDef);
|
1477 | }
|
1478 | }
|
1479 | } catch (err) {
|
1480 | _didIteratorError2 = true;
|
1481 | _iteratorError2 = err;
|
1482 | } finally {
|
1483 | try {
|
1484 | if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
1485 | _iterator2["return"]();
|
1486 | }
|
1487 | } finally {
|
1488 | if (_didIteratorError2) {
|
1489 | throw _iteratorError2;
|
1490 | }
|
1491 | }
|
1492 | }
|
1493 | },
|
1494 | Argument: function Argument(argument) {
|
1495 | var _variable$type;
|
1496 |
|
1497 | if (argument.value.kind !== 'Variable') {
|
1498 | return false;
|
1499 | }
|
1500 |
|
1501 | var variable = argument.value;
|
1502 | var type = (_variable$type = variable.type) !== null && _variable$type !== void 0 ? _variable$type : argument.type;
|
1503 |
|
1504 | if (type == null) {
|
1505 | return;
|
1506 | }
|
1507 |
|
1508 | if (!argumentDefinitions.has(variable.variableName)) {
|
1509 | // root variable
|
1510 | argumentDefinitions.set(variable.variableName, {
|
1511 | kind: 'RootArgumentDefinition',
|
1512 | loc: {
|
1513 | kind: 'Derived',
|
1514 | source: argument.loc
|
1515 | },
|
1516 | name: variable.variableName,
|
1517 | type: type
|
1518 | });
|
1519 | }
|
1520 |
|
1521 | return false;
|
1522 | },
|
1523 | Condition: function Condition(condition) {
|
1524 | var _variable$type2;
|
1525 |
|
1526 | var variable = condition.condition;
|
1527 |
|
1528 | if (variable.kind !== 'Variable') {
|
1529 | return;
|
1530 | }
|
1531 |
|
1532 | var type = (_variable$type2 = variable.type) !== null && _variable$type2 !== void 0 ? _variable$type2 : SchemaUtils.getNonNullBooleanInput(context.getSchema());
|
1533 |
|
1534 | if (!argumentDefinitions.has(variable.variableName)) {
|
1535 | // root variable
|
1536 | argumentDefinitions.set(variable.variableName, {
|
1537 | kind: 'RootArgumentDefinition',
|
1538 | loc: {
|
1539 | kind: 'Derived',
|
1540 | source: variable.loc
|
1541 | },
|
1542 | name: variable.variableName,
|
1543 | type: type
|
1544 | });
|
1545 | }
|
1546 | },
|
1547 | Connection: function Connection(connection) {
|
1548 | var stream = connection.stream;
|
1549 |
|
1550 | if (stream == null) {
|
1551 | return;
|
1552 | }
|
1553 |
|
1554 | var defaultType = SchemaUtils.getNonNullBooleanInput(context.getSchema());
|
1555 | [stream["if"], stream.initialCount].forEach(function (variable) {
|
1556 | var _variable$type3;
|
1557 |
|
1558 | if (variable == null || variable.kind !== 'Variable') {
|
1559 | return;
|
1560 | }
|
1561 |
|
1562 | var type = (_variable$type3 = variable.type) !== null && _variable$type3 !== void 0 ? _variable$type3 : defaultType;
|
1563 |
|
1564 | if (!argumentDefinitions.has(variable.variableName)) {
|
1565 | // root variable
|
1566 | argumentDefinitions.set(variable.variableName, {
|
1567 | kind: 'RootArgumentDefinition',
|
1568 | loc: {
|
1569 | kind: 'Derived',
|
1570 | source: variable.loc
|
1571 | },
|
1572 | name: variable.variableName,
|
1573 | type: type
|
1574 | });
|
1575 | }
|
1576 | });
|
1577 | },
|
1578 | Defer: function Defer(defer) {
|
1579 | var _variable$type4;
|
1580 |
|
1581 | var variable = defer["if"];
|
1582 |
|
1583 | if (variable == null || variable.kind !== 'Variable') {
|
1584 | return;
|
1585 | }
|
1586 |
|
1587 | var type = (_variable$type4 = variable.type) !== null && _variable$type4 !== void 0 ? _variable$type4 : SchemaUtils.getNonNullBooleanInput(context.getSchema());
|
1588 |
|
1589 | if (!argumentDefinitions.has(variable.variableName)) {
|
1590 | // root variable
|
1591 | argumentDefinitions.set(variable.variableName, {
|
1592 | kind: 'RootArgumentDefinition',
|
1593 | loc: {
|
1594 | kind: 'Derived',
|
1595 | source: variable.loc
|
1596 | },
|
1597 | name: variable.variableName,
|
1598 | type: type
|
1599 | });
|
1600 | }
|
1601 | },
|
1602 | Stream: function Stream(stream) {
|
1603 | [stream["if"], stream.initialCount].forEach(function (variable) {
|
1604 | var _variable$type5;
|
1605 |
|
1606 | if (variable == null || variable.kind !== 'Variable') {
|
1607 | return;
|
1608 | }
|
1609 |
|
1610 | var type = (_variable$type5 = variable.type) !== null && _variable$type5 !== void 0 ? _variable$type5 : SchemaUtils.getNonNullBooleanInput(context.getSchema());
|
1611 |
|
1612 | if (!argumentDefinitions.has(variable.variableName)) {
|
1613 | // root variable
|
1614 | argumentDefinitions.set(variable.variableName, {
|
1615 | kind: 'RootArgumentDefinition',
|
1616 | loc: {
|
1617 | kind: 'Derived',
|
1618 | source: variable.loc
|
1619 | },
|
1620 | name: variable.variableName,
|
1621 | type: type
|
1622 | });
|
1623 | }
|
1624 | });
|
1625 | },
|
1626 | LinkedField: function LinkedField(field) {
|
1627 | if (!field.handles) {
|
1628 | return;
|
1629 | }
|
1630 |
|
1631 | field.handles.forEach(function (handle) {
|
1632 | var _variable$type6;
|
1633 |
|
1634 | var variable = handle.dynamicKey;
|
1635 |
|
1636 | if (variable == null) {
|
1637 | return;
|
1638 | }
|
1639 |
|
1640 | var type = (_variable$type6 = variable.type) !== null && _variable$type6 !== void 0 ? _variable$type6 : SchemaUtils.getNullableStringInput(context.getSchema());
|
1641 |
|
1642 | if (!argumentDefinitions.has(variable.variableName)) {
|
1643 | // root variable
|
1644 | argumentDefinitions.set(variable.variableName, {
|
1645 | kind: 'RootArgumentDefinition',
|
1646 | loc: {
|
1647 | kind: 'Derived',
|
1648 | source: variable.loc
|
1649 | },
|
1650 | name: variable.variableName,
|
1651 | type: type
|
1652 | });
|
1653 | }
|
1654 | });
|
1655 | }
|
1656 | });
|
1657 | }
|
1658 |
|
1659 | module.exports = inferRootArgumentDefinitions;
|
1660 |
|
1661 | /***/ }),
|
1662 | /* 18 */
|
1663 | /***/ (function(module, exports, __webpack_require__) {
|
1664 |
|
1665 | "use strict";
|
1666 | /**
|
1667 | * Copyright (c) Facebook, Inc. and its affiliates.
|
1668 | *
|
1669 | * This source code is licensed under the MIT license found in the
|
1670 | * LICENSE file in the root directory of this source tree.
|
1671 | *
|
1672 | *
|
1673 | * @format
|
1674 | * @emails oncall+relay
|
1675 | */
|
1676 |
|
1677 |
|
1678 | var _asyncToGenerator = __webpack_require__(10);
|
1679 |
|
1680 | var childProcess = __webpack_require__(53);
|
1681 |
|
1682 | var watchman = __webpack_require__(54);
|
1683 |
|
1684 | var MAX_ATTEMPT_LIMIT = 5;
|
1685 |
|
1686 | function delay(delayMs) {
|
1687 | return new Promise(function (resolve) {
|
1688 | return setTimeout(resolve, delayMs);
|
1689 | });
|
1690 | }
|
1691 |
|
1692 | var GraphQLWatchmanClient =
|
1693 | /*#__PURE__*/
|
1694 | function () {
|
1695 | GraphQLWatchmanClient.isAvailable = function isAvailable() {
|
1696 | return new Promise(function (resolve) {
|
1697 | // This command not only will verify that watchman CLI is available
|
1698 | // More than that `watchman version` is a command that runs on the server.
|
1699 | // And it can tell us that watchman is up and running
|
1700 | // Also `watchman version` check ``relative_root`` capability
|
1701 | // under the covers
|
1702 | var proc = childProcess.spawn('watchman', ['version']);
|
1703 | proc.on('error', function () {
|
1704 | resolve(false);
|
1705 | });
|
1706 | proc.on('close', function (code) {
|
1707 | resolve(code === 0);
|
1708 | });
|
1709 | });
|
1710 | };
|
1711 |
|
1712 | function GraphQLWatchmanClient() {
|
1713 | var attemptLimit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
1714 | this._client = new watchman.Client();
|
1715 | this._attemptLimit = Math.max(Math.min(MAX_ATTEMPT_LIMIT, attemptLimit), 0);
|
1716 | }
|
1717 |
|
1718 | var _proto = GraphQLWatchmanClient.prototype;
|
1719 |
|
1720 | _proto._command = function _command() {
|
1721 | var _this = this;
|
1722 |
|
1723 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
1724 | args[_key] = arguments[_key];
|
1725 | }
|
1726 |
|
1727 | return new Promise(function (resolve, reject) {
|
1728 | _this._client.command(args, function (error, response) {
|
1729 | if (error) {
|
1730 | reject(error);
|
1731 | } else {
|
1732 | resolve(response);
|
1733 | }
|
1734 | });
|
1735 | });
|
1736 | };
|
1737 |
|
1738 | _proto.command =
|
1739 | /*#__PURE__*/
|
1740 | function () {
|
1741 | var _command2 = _asyncToGenerator(function* () {
|
1742 | var attempt = 0;
|
1743 |
|
1744 | for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
1745 | args[_key2] = arguments[_key2];
|
1746 | }
|
1747 |
|
1748 | while (true) {
|
1749 | try {
|
1750 | attempt++;
|
1751 | return yield this._command.apply(this, args);
|
1752 | } catch (error) {
|
1753 | if (attempt > this._attemptLimit) {
|
1754 | throw error;
|
1755 | }
|
1756 |
|
1757 | yield delay(Math.pow(2, attempt) * 500);
|
1758 |
|
1759 | this._client.end();
|
1760 |
|
1761 | this._client = new watchman.Client();
|
1762 | }
|
1763 | }
|
1764 | });
|
1765 |
|
1766 | function command() {
|
1767 | return _command2.apply(this, arguments);
|
1768 | }
|
1769 |
|
1770 | return command;
|
1771 | }();
|
1772 |
|
1773 | _proto.hasCapability =
|
1774 | /*#__PURE__*/
|
1775 | function () {
|
1776 | var _hasCapability = _asyncToGenerator(function* (capability) {
|
1777 | var resp = yield this.command('list-capabilities');
|
1778 | return resp.capabilities.includes(capability);
|
1779 | });
|
1780 |
|
1781 | function hasCapability(_x) {
|
1782 | return _hasCapability.apply(this, arguments);
|
1783 | }
|
1784 |
|
1785 | return hasCapability;
|
1786 | }();
|
1787 |
|
1788 | _proto.watchProject =
|
1789 | /*#__PURE__*/
|
1790 | function () {
|
1791 | var _watchProject = _asyncToGenerator(function* (baseDir) {
|
1792 | var resp = yield this.command('watch-project', baseDir);
|
1793 |
|
1794 | if ('warning' in resp) {
|
1795 | console.error('Warning:', resp.warning);
|
1796 | }
|
1797 |
|
1798 | return {
|
1799 | root: resp.watch,
|
1800 | relativePath: resp.relative_path
|
1801 | };
|
1802 | });
|
1803 |
|
1804 | function watchProject(_x2) {
|
1805 | return _watchProject.apply(this, arguments);
|
1806 | }
|
1807 |
|
1808 | return watchProject;
|
1809 | }();
|
1810 |
|
1811 | _proto.on = function on(event, callback) {
|
1812 | this._client.on(event, callback);
|
1813 | };
|
1814 |
|
1815 | _proto.end = function end() {
|
1816 | this._client.end();
|
1817 | };
|
1818 |
|
1819 | return GraphQLWatchmanClient;
|
1820 | }();
|
1821 |
|
1822 | module.exports = GraphQLWatchmanClient;
|
1823 |
|
1824 | /***/ }),
|
1825 | /* 19 */
|
1826 | /***/ (function(module, exports, __webpack_require__) {
|
1827 |
|
1828 | "use strict";
|
1829 | /**
|
1830 | * Copyright (c) Facebook, Inc. and its affiliates.
|
1831 | *
|
1832 | * This source code is licensed under the MIT license found in the
|
1833 | * LICENSE file in the root directory of this source tree.
|
1834 | *
|
1835 | *
|
1836 | * @format
|
1837 | */
|
1838 |
|
1839 |
|
1840 | var Profiler = __webpack_require__(6);
|
1841 |
|
1842 | var invariant = __webpack_require__(4);
|
1843 |
|
1844 | var _require = __webpack_require__(1),
|
1845 | createUserError = _require.createUserError; // $FlowFixMe - immutable.js is not flow-typed
|
1846 |
|
1847 |
|
1848 | var _require2 = __webpack_require__(14),
|
1849 | ImmutableOrderedMap = _require2.OrderedMap;
|
1850 |
|
1851 | /**
|
1852 | * An immutable representation of a corpus of documents being compiled together.
|
1853 | * For each document, the context stores the IR and any validation errors.
|
1854 | */
|
1855 | var GraphQLCompilerContext =
|
1856 | /*#__PURE__*/
|
1857 | function () {
|
1858 | function GraphQLCompilerContext(schema) {
|
1859 | this._isMutable = false;
|
1860 | this._documents = new ImmutableOrderedMap();
|
1861 | this._withTransform = new WeakMap();
|
1862 | this._schema = schema;
|
1863 | }
|
1864 | /**
|
1865 | * Returns the documents for the context in the order they were added.
|
1866 | */
|
1867 |
|
1868 |
|
1869 | var _proto = GraphQLCompilerContext.prototype;
|
1870 |
|
1871 | _proto.documents = function documents() {
|
1872 | return this._documents.toArray();
|
1873 | };
|
1874 |
|
1875 | _proto.forEachDocument = function forEachDocument(fn) {
|
1876 | this._documents.forEach(fn);
|
1877 | };
|
1878 |
|
1879 | _proto.replace = function replace(node) {
|
1880 | return this._update(this._documents.update(node.name, function (existing) {
|
1881 | !existing ? true ? invariant(false, 'GraphQLCompilerContext: Expected to replace existing node %s, but' + 'one was not found in the context.', node.name) : undefined : void 0;
|
1882 | return node;
|
1883 | }));
|
1884 | };
|
1885 |
|
1886 | _proto.add = function add(node) {
|
1887 | return this._update(this._documents.update(node.name, function (existing) {
|
1888 | !!existing ? true ? invariant(false, 'GraphQLCompilerContext: Duplicate document named `%s`. GraphQL ' + 'fragments and roots must have unique names.', node.name) : undefined : void 0;
|
1889 | return node;
|
1890 | }));
|
1891 | };
|
1892 |
|
1893 | _proto.addAll = function addAll(nodes) {
|
1894 | return this.withMutations(function (mutable) {
|
1895 | return nodes.reduce(function (ctx, definition) {
|
1896 | return ctx.add(definition);
|
1897 | }, mutable);
|
1898 | });
|
1899 | }
|
1900 | /**
|
1901 | * Apply a list of compiler transforms and return a new compiler context.
|
1902 | */
|
1903 | ;
|
1904 |
|
1905 | _proto.applyTransforms = function applyTransforms(transforms, reporter) {
|
1906 | var _this = this;
|
1907 |
|
1908 | return Profiler.run('applyTransforms', function () {
|
1909 | return transforms.reduce(function (ctx, transform) {
|
1910 | return ctx.applyTransform(transform, reporter);
|
1911 | }, _this);
|
1912 | });
|
1913 | }
|
1914 | /**
|
1915 | * Applies a transform to this context, returning a new context.
|
1916 | *
|
1917 | * This is memoized such that applying the same sequence of transforms will
|
1918 | * not result in duplicated work.
|
1919 | */
|
1920 | ;
|
1921 |
|
1922 | _proto.applyTransform = function applyTransform(transform, reporter) {
|
1923 | var transformed = this._withTransform.get(transform);
|
1924 |
|
1925 | if (!transformed) {
|
1926 | var start = process.hrtime();
|
1927 | transformed = Profiler.instrument(transform)(this);
|
1928 | var delta = process.hrtime(start);
|
1929 | var deltaMs = Math.round((delta[0] * 1e9 + delta[1]) / 1e6);
|
1930 | reporter && reporter.reportTime(transform.name, deltaMs);
|
1931 |
|
1932 | this._withTransform.set(transform, transformed);
|
1933 | }
|
1934 |
|
1935 | return transformed;
|
1936 | };
|
1937 |
|
1938 | _proto.get = function get(name) {
|
1939 | return this._documents.get(name);
|
1940 | };
|
1941 |
|
1942 | _proto.getFragment = function getFragment(name, referencedFrom) {
|
1943 | var node = this._documents.get(name);
|
1944 |
|
1945 | if (node == null) {
|
1946 | throw createUserError("Cannot find fragment '".concat(name, "'."), referencedFrom != null ? [referencedFrom] : null);
|
1947 | } else if (node.kind !== 'Fragment') {
|
1948 | throw createUserError("Cannot find fragment '".concat(name, "', a document with this name exists ") + 'but is not a fragment.', [node.loc, referencedFrom].filter(Boolean));
|
1949 | }
|
1950 |
|
1951 | return node;
|
1952 | };
|
1953 |
|
1954 | _proto.getRoot = function getRoot(name) {
|
1955 | var node = this._documents.get(name);
|
1956 |
|
1957 | if (node == null) {
|
1958 | throw createUserError("Cannot find root '".concat(name, "'."));
|
1959 | } else if (node.kind !== 'Root') {
|
1960 | throw createUserError("Cannot find root '".concat(name, "', a document with this name exists but ") + 'is not a root.', [node.loc]);
|
1961 | }
|
1962 |
|
1963 | return node;
|
1964 | };
|
1965 |
|
1966 | _proto.remove = function remove(name) {
|
1967 | return this._update(this._documents["delete"](name));
|
1968 | };
|
1969 |
|
1970 | _proto.withMutations = function withMutations(fn) {
|
1971 | var mutableCopy = this._update(this._documents.asMutable());
|
1972 |
|
1973 | mutableCopy._isMutable = true;
|
1974 | var result = fn(mutableCopy);
|
1975 | result._isMutable = false;
|
1976 | result._documents = result._documents.asImmutable();
|
1977 | return this._documents === result._documents ? this : result;
|
1978 | };
|
1979 |
|
1980 | _proto._update = function _update(documents) {
|
1981 | var context = this._isMutable ? this : new GraphQLCompilerContext(this.getSchema());
|
1982 | context._documents = documents;
|
1983 | return context;
|
1984 | };
|
1985 |
|
1986 | _proto.getSchema = function getSchema() {
|
1987 | return this._schema;
|
1988 | };
|
1989 |
|
1990 | return GraphQLCompilerContext;
|
1991 | }();
|
1992 |
|
1993 | module.exports = GraphQLCompilerContext;
|
1994 |
|
1995 | /***/ }),
|
1996 | /* 20 */
|
1997 | /***/ (function(module, exports) {
|
1998 |
|
1999 | module.exports = require("nullthrows");
|
2000 |
|
2001 | /***/ }),
|
2002 | /* 21 */
|
2003 | /***/ (function(module, exports, __webpack_require__) {
|
2004 |
|
2005 | "use strict";
|
2006 | /**
|
2007 | * Copyright (c) Facebook, Inc. and its affiliates.
|
2008 | *
|
2009 | * This source code is licensed under the MIT license found in the
|
2010 | * LICENSE file in the root directory of this source tree.
|
2011 | *
|
2012 | *
|
2013 | * @format
|
2014 | */
|
2015 |
|
2016 |
|
2017 | function buildFragmentSpread(fragment) {
|
2018 | var args = [];
|
2019 | var _iteratorNormalCompletion = true;
|
2020 | var _didIteratorError = false;
|
2021 | var _iteratorError = undefined;
|
2022 |
|
2023 | try {
|
2024 | for (var _iterator = fragment.argumentDefinitions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
2025 | var argDef = _step.value;
|
2026 |
|
2027 | if (argDef.kind !== 'LocalArgumentDefinition') {
|
2028 | continue;
|
2029 | }
|
2030 |
|
2031 | args.push({
|
2032 | kind: 'Argument',
|
2033 | loc: {
|
2034 | kind: 'Derived',
|
2035 | source: argDef.loc
|
2036 | },
|
2037 | name: argDef.name,
|
2038 | type: argDef.type,
|
2039 | value: {
|
2040 | kind: 'Variable',
|
2041 | loc: {
|
2042 | kind: 'Derived',
|
2043 | source: argDef.loc
|
2044 | },
|
2045 | variableName: argDef.name,
|
2046 | type: argDef.type
|
2047 | }
|
2048 | });
|
2049 | }
|
2050 | } catch (err) {
|
2051 | _didIteratorError = true;
|
2052 | _iteratorError = err;
|
2053 | } finally {
|
2054 | try {
|
2055 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
2056 | _iterator["return"]();
|
2057 | }
|
2058 | } finally {
|
2059 | if (_didIteratorError) {
|
2060 | throw _iteratorError;
|
2061 | }
|
2062 | }
|
2063 | }
|
2064 |
|
2065 | return {
|
2066 | args: args,
|
2067 | directives: [],
|
2068 | kind: 'FragmentSpread',
|
2069 | loc: {
|
2070 | kind: 'Derived',
|
2071 | source: fragment.loc
|
2072 | },
|
2073 | metadata: null,
|
2074 | name: fragment.name
|
2075 | };
|
2076 | }
|
2077 |
|
2078 | function buildOperationArgumentDefinitions(argumentDefinitions) {
|
2079 | return argumentDefinitions.map(function (argDef) {
|
2080 | if (argDef.kind === 'LocalArgumentDefinition') {
|
2081 | return argDef;
|
2082 | } else {
|
2083 | return {
|
2084 | kind: 'LocalArgumentDefinition',
|
2085 | name: argDef.name,
|
2086 | type: argDef.type,
|
2087 | defaultValue: null,
|
2088 | loc: argDef.loc
|
2089 | };
|
2090 | }
|
2091 | });
|
2092 | }
|
2093 |
|
2094 | module.exports = {
|
2095 | buildFragmentSpread: buildFragmentSpread,
|
2096 | buildOperationArgumentDefinitions: buildOperationArgumentDefinitions
|
2097 | };
|
2098 |
|
2099 | /***/ }),
|
2100 | /* 22 */
|
2101 | /***/ (function(module, exports) {
|
2102 |
|
2103 | module.exports = require("@babel/types");
|
2104 |
|
2105 | /***/ }),
|
2106 | /* 23 */
|
2107 | /***/ (function(module, exports) {
|
2108 |
|
2109 | module.exports = require("@babel/runtime/helpers/defineProperty");
|
2110 |
|
2111 | /***/ }),
|
2112 | /* 24 */
|
2113 | /***/ (function(module, exports, __webpack_require__) {
|
2114 |
|
2115 | "use strict";
|
2116 | /**
|
2117 | * Copyright (c) Facebook, Inc. and its affiliates.
|
2118 | *
|
2119 | * This source code is licensed under the MIT license found in the
|
2120 | * LICENSE file in the root directory of this source tree.
|
2121 | *
|
2122 | *
|
2123 | * @format
|
2124 | */
|
2125 |
|
2126 |
|
2127 | var _interopRequireDefault = __webpack_require__(0);
|
2128 |
|
2129 | var _asyncToGenerator = __webpack_require__(10);
|
2130 |
|
2131 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
2132 |
|
2133 | var Profiler = __webpack_require__(6);
|
2134 |
|
2135 | var crypto = __webpack_require__(12);
|
2136 |
|
2137 | var invariant = __webpack_require__(4);
|
2138 |
|
2139 | var path = __webpack_require__(8);
|
2140 |
|
2141 | var CodegenDirectory =
|
2142 | /*#__PURE__*/
|
2143 | function () {
|
2144 | function CodegenDirectory(dir, options) {
|
2145 | var _this = this;
|
2146 |
|
2147 | var _options$filesystem, _options$shards;
|
2148 |
|
2149 | this._filesystem = (_options$filesystem = options.filesystem) !== null && _options$filesystem !== void 0 ? _options$filesystem : __webpack_require__(13);
|
2150 | this.onlyValidate = options.onlyValidate;
|
2151 | this._shards = (_options$shards = options.shards) !== null && _options$shards !== void 0 ? _options$shards : 1;
|
2152 |
|
2153 | if (this._filesystem.existsSync(dir)) {
|
2154 | !this._filesystem.statSync(dir).isDirectory() ? true ? invariant(false, 'Expected `%s` to be a directory.', dir) : undefined : void 0;
|
2155 | }
|
2156 |
|
2157 | if (!this.onlyValidate) {
|
2158 | var dirs = [];
|
2159 | var parent = dir;
|
2160 |
|
2161 | while (!this._filesystem.existsSync(parent)) {
|
2162 | dirs.unshift(parent);
|
2163 | parent = path.dirname(parent);
|
2164 | }
|
2165 |
|
2166 | dirs.forEach(function (d) {
|
2167 | return _this._filesystem.mkdirSync(d);
|
2168 | });
|
2169 |
|
2170 | if (this._shards > 1) {
|
2171 | for (var shard = 0; shard < this._shards; shard++) {
|
2172 | var shardDir = path.join(dir, this._getShardName(shard));
|
2173 |
|
2174 | if (this._filesystem.existsSync(shardDir)) {
|
2175 | !this._filesystem.statSync(dir).isDirectory() ? true ? invariant(false, 'Expected `%s` to be a directory.', dir) : undefined : void 0;
|
2176 | } else {
|
2177 | this._filesystem.mkdirSync(shardDir);
|
2178 | }
|
2179 | }
|
2180 | }
|
2181 | }
|
2182 |
|
2183 | this._files = new Set();
|
2184 | this.changes = {
|
2185 | deleted: [],
|
2186 | updated: [],
|
2187 | created: [],
|
2188 | unchanged: []
|
2189 | };
|
2190 | this._dir = dir;
|
2191 | }
|
2192 |
|
2193 | CodegenDirectory.combineChanges = function combineChanges(dirs) {
|
2194 | var changes = {
|
2195 | deleted: [],
|
2196 | updated: [],
|
2197 | created: [],
|
2198 | unchanged: []
|
2199 | };
|
2200 | dirs.forEach(function (dir) {
|
2201 | var _changes$deleted, _changes$updated, _changes$created, _changes$unchanged;
|
2202 |
|
2203 | (_changes$deleted = changes.deleted).push.apply(_changes$deleted, (0, _toConsumableArray2["default"])(dir.changes.deleted));
|
2204 |
|
2205 | (_changes$updated = changes.updated).push.apply(_changes$updated, (0, _toConsumableArray2["default"])(dir.changes.updated));
|
2206 |
|
2207 | (_changes$created = changes.created).push.apply(_changes$created, (0, _toConsumableArray2["default"])(dir.changes.created));
|
2208 |
|
2209 | (_changes$unchanged = changes.unchanged).push.apply(_changes$unchanged, (0, _toConsumableArray2["default"])(dir.changes.unchanged));
|
2210 | });
|
2211 | return changes;
|
2212 | };
|
2213 |
|
2214 | CodegenDirectory.hasChanges = function hasChanges(changes) {
|
2215 | return changes.created.length > 0 || changes.updated.length > 0 || changes.deleted.length > 0;
|
2216 | };
|
2217 |
|
2218 | CodegenDirectory.formatChanges = function formatChanges(changes, options) {
|
2219 | var output = [];
|
2220 |
|
2221 | function formatFiles(label, files) {
|
2222 | if (files.length > 0) {
|
2223 | output.push(label + ':');
|
2224 | files.forEach(function (file) {
|
2225 | output.push(' - ' + file);
|
2226 | });
|
2227 | }
|
2228 | }
|
2229 |
|
2230 | if (options.onlyValidate) {
|
2231 | formatFiles('Missing', changes.created);
|
2232 | formatFiles('Out of date', changes.updated);
|
2233 | formatFiles('Extra', changes.deleted);
|
2234 | } else {
|
2235 | formatFiles('Created', changes.created);
|
2236 | formatFiles('Updated', changes.updated);
|
2237 | formatFiles('Deleted', changes.deleted);
|
2238 | output.push("Unchanged: ".concat(changes.unchanged.length, " files"));
|
2239 | }
|
2240 |
|
2241 | return output.join('\n');
|
2242 | };
|
2243 |
|
2244 | CodegenDirectory.printChanges = function printChanges(changes, options) {
|
2245 | Profiler.run('CodegenDirectory.printChanges', function () {
|
2246 | var output = CodegenDirectory.formatChanges(changes, options); // eslint-disable-next-line no-console
|
2247 |
|
2248 | console.log(output);
|
2249 | });
|
2250 | };
|
2251 |
|
2252 | CodegenDirectory.getAddedRemovedFiles = function getAddedRemovedFiles(dirs) {
|
2253 | var added = [];
|
2254 | var removed = [];
|
2255 | dirs.forEach(function (dir) {
|
2256 | dir.changes.created.forEach(function (name) {
|
2257 | added.push(dir.getPath(name));
|
2258 | });
|
2259 | dir.changes.deleted.forEach(function (name) {
|
2260 | removed.push(dir.getPath(name));
|
2261 | });
|
2262 | });
|
2263 | return {
|
2264 | added: added,
|
2265 | removed: removed
|
2266 | };
|
2267 | };
|
2268 |
|
2269 | CodegenDirectory.sourceControlAddRemove =
|
2270 | /*#__PURE__*/
|
2271 | function () {
|
2272 | var _sourceControlAddRemove = _asyncToGenerator(function* (sourceControl, dirs) {
|
2273 | var _CodegenDirectory$get = CodegenDirectory.getAddedRemovedFiles(dirs),
|
2274 | added = _CodegenDirectory$get.added,
|
2275 | removed = _CodegenDirectory$get.removed;
|
2276 |
|
2277 | sourceControl.addRemove(added, removed);
|
2278 | });
|
2279 |
|
2280 | function sourceControlAddRemove(_x, _x2) {
|
2281 | return _sourceControlAddRemove.apply(this, arguments);
|
2282 | }
|
2283 |
|
2284 | return sourceControlAddRemove;
|
2285 | }();
|
2286 |
|
2287 | var _proto = CodegenDirectory.prototype;
|
2288 |
|
2289 | _proto.printChanges = function printChanges() {
|
2290 | CodegenDirectory.printChanges(this.changes, {
|
2291 | onlyValidate: this.onlyValidate
|
2292 | });
|
2293 | };
|
2294 |
|
2295 | _proto.read = function read(filename) {
|
2296 | var filePath = path.join(this._dir, filename);
|
2297 |
|
2298 | if (this._filesystem.existsSync(filePath)) {
|
2299 | return this._filesystem.readFileSync(filePath, 'utf8');
|
2300 | }
|
2301 |
|
2302 | return null;
|
2303 | };
|
2304 |
|
2305 | _proto.markUnchanged = function markUnchanged(filename) {
|
2306 | this._addGenerated(filename);
|
2307 |
|
2308 | this.changes.unchanged.push(filename);
|
2309 | }
|
2310 | /**
|
2311 | * Marks a files as updated or out of date without actually writing the file.
|
2312 | * This is probably only be useful when doing validation without intention to
|
2313 | * actually write to disk.
|
2314 | */
|
2315 | ;
|
2316 |
|
2317 | _proto.markUpdated = function markUpdated(filename) {
|
2318 | this._addGenerated(filename);
|
2319 |
|
2320 | this.changes.updated.push(filename);
|
2321 | };
|
2322 |
|
2323 | _proto.writeFile = function writeFile(filename, content) {
|
2324 | var _this2 = this;
|
2325 |
|
2326 | var shouldRepersist = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
2327 | Profiler.run('CodegenDirectory.writeFile', function () {
|
2328 | _this2._addGenerated(filename);
|
2329 |
|
2330 | var filePath = _this2.getPath(filename);
|
2331 |
|
2332 | if (_this2._filesystem.existsSync(filePath)) {
|
2333 | var existingContent = _this2._filesystem.readFileSync(filePath, 'utf8');
|
2334 |
|
2335 | if (existingContent === content && !shouldRepersist) {
|
2336 | _this2.changes.unchanged.push(filename);
|
2337 | } else {
|
2338 | _this2._writeFile(filePath, content);
|
2339 |
|
2340 | _this2.changes.updated.push(filename);
|
2341 | }
|
2342 | } else {
|
2343 | _this2._writeFile(filePath, content);
|
2344 |
|
2345 | _this2.changes.created.push(filename);
|
2346 | }
|
2347 | });
|
2348 | };
|
2349 |
|
2350 | _proto._writeFile = function _writeFile(filePath, content) {
|
2351 | if (!this.onlyValidate) {
|
2352 | this._filesystem.writeFileSync(filePath, content, 'utf8');
|
2353 | }
|
2354 | }
|
2355 | /**
|
2356 | * Deletes all non-generated files, except for invisible "dot" files (ie.
|
2357 | * files with names starting with ".").
|
2358 | */
|
2359 | ;
|
2360 |
|
2361 | _proto.deleteExtraFiles = function deleteExtraFiles() {
|
2362 | var _this3 = this;
|
2363 |
|
2364 | Profiler.run('CodegenDirectory.deleteExtraFiles', function () {
|
2365 | if (_this3._shards > 1) {
|
2366 | _this3._filesystem.readdirSync(_this3._dir).forEach(function (firstLevel) {
|
2367 | if (firstLevel.startsWith('.')) {
|
2368 | // allow hidden files on the first level of the codegen directory
|
2369 | return;
|
2370 | }
|
2371 |
|
2372 | var firstLevelPath = path.join(_this3._dir, firstLevel);
|
2373 |
|
2374 | if (!_this3._filesystem.statSync(firstLevelPath).isDirectory()) {
|
2375 | // Delete all files on the top level, all files need to be in a
|
2376 | // shard directory.
|
2377 | _this3._filesystem.unlinkSync(firstLevelPath);
|
2378 |
|
2379 | return;
|
2380 | }
|
2381 |
|
2382 | _this3._filesystem.readdirSync(firstLevelPath).forEach(function (actualFile) {
|
2383 | if (_this3._files.has(actualFile)) {
|
2384 | return;
|
2385 | }
|
2386 |
|
2387 | if (!_this3.onlyValidate) {
|
2388 | try {
|
2389 | _this3._filesystem.unlinkSync(path.join(firstLevelPath, actualFile));
|
2390 | } catch (_unused) {
|
2391 | throw new Error('CodegenDirectory: Failed to delete `' + actualFile + '` in `' + _this3._dir + '`.');
|
2392 | }
|
2393 | }
|
2394 |
|
2395 | _this3.changes.deleted.push(actualFile);
|
2396 | });
|
2397 | });
|
2398 | } else {
|
2399 | _this3._filesystem.readdirSync(_this3._dir).forEach(function (actualFile) {
|
2400 | if (actualFile.startsWith('.') || _this3._files.has(actualFile)) {
|
2401 | return;
|
2402 | }
|
2403 |
|
2404 | if (!_this3.onlyValidate) {
|
2405 | try {
|
2406 | _this3._filesystem.unlinkSync(path.join(_this3._dir, actualFile));
|
2407 | } catch (_unused2) {
|
2408 | throw new Error('CodegenDirectory: Failed to delete `' + actualFile + '` in `' + _this3._dir + '`.');
|
2409 | }
|
2410 | }
|
2411 |
|
2412 | _this3.changes.deleted.push(actualFile);
|
2413 | });
|
2414 | }
|
2415 | });
|
2416 | };
|
2417 |
|
2418 | _proto.getPath = function getPath(filename) {
|
2419 | if (this._shards > 1) {
|
2420 | var hasher = crypto.createHash('md5');
|
2421 | hasher.update(filename, 'utf8');
|
2422 |
|
2423 | var shard = hasher.digest().readUInt32BE(0) % this._shards;
|
2424 |
|
2425 | return path.join(this._dir, this._getShardName(shard), filename);
|
2426 | }
|
2427 |
|
2428 | return path.join(this._dir, filename);
|
2429 | };
|
2430 |
|
2431 | _proto._getShardName = function _getShardName(shardNumber) {
|
2432 | var base16length = Math.ceil(Math.log2(256) / 4);
|
2433 | return shardNumber.toString(16).padStart(base16length, '0');
|
2434 | };
|
2435 |
|
2436 | _proto._addGenerated = function _addGenerated(filename) {
|
2437 | !!this._files.has(filename) ? true ? invariant(false, 'CodegenDirectory: Tried to generate `%s` twice in `%s`.', filename, this._dir) : undefined : void 0;
|
2438 |
|
2439 | this._files.add(filename);
|
2440 | };
|
2441 |
|
2442 | return CodegenDirectory;
|
2443 | }();
|
2444 |
|
2445 | module.exports = CodegenDirectory;
|
2446 |
|
2447 | /***/ }),
|
2448 | /* 25 */
|
2449 | /***/ (function(module, exports, __webpack_require__) {
|
2450 |
|
2451 | "use strict";
|
2452 | /**
|
2453 | * Copyright (c) Facebook, Inc. and its affiliates.
|
2454 | *
|
2455 | * This source code is licensed under the MIT license found in the
|
2456 | * LICENSE file in the root directory of this source tree.
|
2457 | *
|
2458 | *
|
2459 | * @format
|
2460 | */
|
2461 |
|
2462 |
|
2463 | var Profiler = __webpack_require__(6);
|
2464 |
|
2465 | var _require = __webpack_require__(11),
|
2466 | isExecutableDefinitionAST = _require.isExecutableDefinitionAST,
|
2467 | isSchemaDefinitionAST = _require.isSchemaDefinitionAST;
|
2468 |
|
2469 | var _require2 = __webpack_require__(7),
|
2470 | extendSchema = _require2.extendSchema,
|
2471 | parse = _require2.parse,
|
2472 | print = _require2.print,
|
2473 | visit = _require2.visit;
|
2474 |
|
2475 | function convertASTDocuments(schema, documents, transform) {
|
2476 | return Profiler.run('ASTConvert.convertASTDocuments', function () {
|
2477 | var definitions = definitionsFromDocuments(documents);
|
2478 | var astDefinitions = [];
|
2479 | documents.forEach(function (doc) {
|
2480 | doc.definitions.forEach(function (definition) {
|
2481 | if (isExecutableDefinitionAST(definition)) {
|
2482 | astDefinitions.push(definition);
|
2483 | }
|
2484 | });
|
2485 | });
|
2486 | return convertASTDefinitions(schema, definitions, transform);
|
2487 | });
|
2488 | }
|
2489 |
|
2490 | function convertASTDocumentsWithBase(schema, baseDocuments, documents, transform) {
|
2491 | return Profiler.run('ASTConvert.convertASTDocumentsWithBase', function () {
|
2492 | var baseDefinitions = definitionsFromDocuments(baseDocuments);
|
2493 | var definitions = definitionsFromDocuments(documents);
|
2494 | var requiredDefinitions = new Map();
|
2495 | var baseMap = new Map();
|
2496 | baseDefinitions.forEach(function (definition) {
|
2497 | if (isExecutableDefinitionAST(definition)) {
|
2498 | var definitionName = definition.name && definition.name.value; // If there's no name, no reason to put in the map
|
2499 |
|
2500 | if (definitionName != null) {
|
2501 | if (baseMap.has(definitionName)) {
|
2502 | throw new Error("Duplicate definition of '".concat(definitionName, "'."));
|
2503 | }
|
2504 |
|
2505 | baseMap.set(definitionName, definition);
|
2506 | }
|
2507 | }
|
2508 | });
|
2509 | var definitionsToVisit = [];
|
2510 | definitions.forEach(function (definition) {
|
2511 | if (isExecutableDefinitionAST(definition)) {
|
2512 | definitionsToVisit.push(definition);
|
2513 | }
|
2514 | });
|
2515 |
|
2516 | while (definitionsToVisit.length > 0) {
|
2517 | var definition = definitionsToVisit.pop();
|
2518 | var name = definition.name && definition.name.value;
|
2519 |
|
2520 | if (name == null) {
|
2521 | continue;
|
2522 | }
|
2523 |
|
2524 | if (requiredDefinitions.has(name)) {
|
2525 | if (requiredDefinitions.get(name) !== definition) {
|
2526 | throw new Error("Duplicate definition of '".concat(name, "'."));
|
2527 | }
|
2528 |
|
2529 | continue;
|
2530 | }
|
2531 |
|
2532 | requiredDefinitions.set(name, definition);
|
2533 | visit(definition, {
|
2534 | FragmentSpread: function FragmentSpread(spread) {
|
2535 | var baseDefinition = baseMap.get(spread.name.value);
|
2536 |
|
2537 | if (baseDefinition) {
|
2538 | // We only need to add those definitions not already included
|
2539 | // in definitions
|
2540 | definitionsToVisit.push(baseDefinition);
|
2541 | }
|
2542 | }
|
2543 | });
|
2544 | }
|
2545 |
|
2546 | var definitionsToConvert = [];
|
2547 | requiredDefinitions.forEach(function (definition) {
|
2548 | return definitionsToConvert.push(definition);
|
2549 | });
|
2550 | return convertASTDefinitions(schema, definitionsToConvert, transform);
|
2551 | });
|
2552 | }
|
2553 |
|
2554 | function convertASTDefinitions(schema, definitions, transform) {
|
2555 | var operationDefinitions = [];
|
2556 | definitions.forEach(function (definition) {
|
2557 | if (isExecutableDefinitionAST(definition)) {
|
2558 | operationDefinitions.push(definition);
|
2559 | }
|
2560 | });
|
2561 | return transform(schema, operationDefinitions);
|
2562 | }
|
2563 |
|
2564 | function definitionsFromDocuments(documents) {
|
2565 | var definitions = [];
|
2566 | documents.forEach(function (doc) {
|
2567 | doc.definitions.forEach(function (definition) {
|
2568 | return definitions.push(definition);
|
2569 | });
|
2570 | });
|
2571 | return definitions;
|
2572 | }
|
2573 | /**
|
2574 | * Extends a GraphQLSchema with a list of schema extensions in string form.
|
2575 | */
|
2576 |
|
2577 |
|
2578 | function transformASTSchema(schema, schemaExtensions) {
|
2579 | return Profiler.run('ASTConvert.transformASTSchema', function () {
|
2580 | if (schemaExtensions.length === 0) {
|
2581 | return schema;
|
2582 | }
|
2583 |
|
2584 | var extension = schemaExtensions.join('\n');
|
2585 | return cachedExtend(schema, extension, function () {
|
2586 | return extendSchema(schema, parse(extension));
|
2587 | });
|
2588 | });
|
2589 | }
|
2590 | /**
|
2591 | * Extends a GraphQLSchema with a list of schema extensions in AST form.
|
2592 | */
|
2593 |
|
2594 |
|
2595 | function extendASTSchema(baseSchema, documents) {
|
2596 | return Profiler.run('ASTConvert.extendASTSchema', function () {
|
2597 | var schemaExtensions = [];
|
2598 | documents.forEach(function (doc) {
|
2599 | doc.definitions.forEach(function (definition) {
|
2600 | if (isSchemaDefinitionAST(definition)) {
|
2601 | schemaExtensions.push(definition);
|
2602 | }
|
2603 | });
|
2604 | });
|
2605 |
|
2606 | if (schemaExtensions.length === 0) {
|
2607 | return baseSchema;
|
2608 | }
|
2609 |
|
2610 | var key = schemaExtensions.map(print).join('\n');
|
2611 | return cachedExtend(baseSchema, key, function () {
|
2612 | return extendSchema(baseSchema, {
|
2613 | kind: 'Document',
|
2614 | definitions: schemaExtensions
|
2615 | }, // TODO T24511737 figure out if this is dangerous
|
2616 | {
|
2617 | assumeValid: true
|
2618 | });
|
2619 | });
|
2620 | });
|
2621 | }
|
2622 |
|
2623 | var extendedSchemas = new Map();
|
2624 |
|
2625 | function cachedExtend(schema, key, compute) {
|
2626 | var cache = extendedSchemas.get(schema);
|
2627 |
|
2628 | if (!cache) {
|
2629 | cache = {};
|
2630 | extendedSchemas.set(schema, cache);
|
2631 | }
|
2632 |
|
2633 | var extendedSchema = cache[key];
|
2634 |
|
2635 | if (!extendedSchema) {
|
2636 | extendedSchema = compute();
|
2637 | cache[key] = extendedSchema;
|
2638 | }
|
2639 |
|
2640 | return extendedSchema;
|
2641 | }
|
2642 |
|
2643 | module.exports = {
|
2644 | convertASTDocuments: convertASTDocuments,
|
2645 | convertASTDocumentsWithBase: convertASTDocumentsWithBase,
|
2646 | extendASTSchema: extendASTSchema,
|
2647 | transformASTSchema: transformASTSchema
|
2648 | };
|
2649 |
|
2650 | /***/ }),
|
2651 | /* 26 */
|
2652 | /***/ (function(module, exports, __webpack_require__) {
|
2653 |
|
2654 | "use strict";
|
2655 | /**
|
2656 | * Copyright (c) Facebook, Inc. and its affiliates.
|
2657 | *
|
2658 | * This source code is licensed under the MIT license found in the
|
2659 | * LICENSE file in the root directory of this source tree.
|
2660 | *
|
2661 | *
|
2662 | * @format
|
2663 | */
|
2664 |
|
2665 |
|
2666 | var Profiler = __webpack_require__(6);
|
2667 |
|
2668 | var _require = __webpack_require__(14),
|
2669 | ImmutableMap = _require.Map;
|
2670 |
|
2671 | var ASTCache =
|
2672 | /*#__PURE__*/
|
2673 | function () {
|
2674 | function ASTCache(config) {
|
2675 | this._documents = new Map();
|
2676 | this._baseDir = config.baseDir;
|
2677 | this._parse = Profiler.instrument(config.parse, 'ASTCache.parseFn');
|
2678 | } // Short-term: we don't do subscriptions/delta updates, instead always use all definitions
|
2679 |
|
2680 |
|
2681 | var _proto = ASTCache.prototype;
|
2682 |
|
2683 | _proto.documents = function documents() {
|
2684 | return ImmutableMap(this._documents);
|
2685 | } // parse should return the set of changes
|
2686 | ;
|
2687 |
|
2688 | _proto.parseFiles = function parseFiles(files) {
|
2689 | var _this = this;
|
2690 |
|
2691 | var documents = ImmutableMap();
|
2692 | files.forEach(function (file) {
|
2693 | if (!file.exists) {
|
2694 | _this._documents["delete"](file.relPath);
|
2695 |
|
2696 | return;
|
2697 | }
|
2698 |
|
2699 | var doc = function () {
|
2700 | try {
|
2701 | return _this._parse(_this._baseDir, file);
|
2702 | } catch (error) {
|
2703 | throw new Error("Parse error: ".concat(error, " in \"").concat(file.relPath, "\""));
|
2704 | }
|
2705 | }();
|
2706 |
|
2707 | if (!doc) {
|
2708 | _this._documents["delete"](file.relPath);
|
2709 |
|
2710 | return;
|
2711 | }
|
2712 |
|
2713 | documents = documents.set(file.relPath, doc);
|
2714 |
|
2715 | _this._documents.set(file.relPath, doc);
|
2716 | });
|
2717 | return documents;
|
2718 | };
|
2719 |
|
2720 | return ASTCache;
|
2721 | }();
|
2722 |
|
2723 | module.exports = ASTCache;
|
2724 |
|
2725 | /***/ }),
|
2726 | /* 27 */
|
2727 | /***/ (function(module, exports, __webpack_require__) {
|
2728 |
|
2729 | "use strict";
|
2730 | /**
|
2731 | * Copyright (c) Facebook, Inc. and its affiliates.
|
2732 | *
|
2733 | * This source code is licensed under the MIT license found in the
|
2734 | * LICENSE file in the root directory of this source tree.
|
2735 | *
|
2736 | *
|
2737 | * @format
|
2738 | */
|
2739 |
|
2740 |
|
2741 | var _interopRequireDefault = __webpack_require__(0);
|
2742 |
|
2743 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
2744 |
|
2745 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
2746 |
|
2747 | var Profiler = __webpack_require__(6);
|
2748 |
|
2749 | var orList = __webpack_require__(62);
|
2750 |
|
2751 | var partitionArray = __webpack_require__(28);
|
2752 |
|
2753 | var _require = __webpack_require__(29),
|
2754 | DEFAULT_HANDLE_KEY = _require.DEFAULT_HANDLE_KEY;
|
2755 |
|
2756 | var _require2 = __webpack_require__(1),
|
2757 | createCompilerError = _require2.createCompilerError,
|
2758 | createUserError = _require2.createUserError,
|
2759 | eachWithCombinedError = _require2.eachWithCombinedError;
|
2760 |
|
2761 | var _require3 = __webpack_require__(11),
|
2762 | isExecutableDefinitionAST = _require3.isExecutableDefinitionAST;
|
2763 |
|
2764 | var _require4 = __webpack_require__(30),
|
2765 | getFieldDefinitionLegacy = _require4.getFieldDefinitionLegacy;
|
2766 |
|
2767 | var _require5 = __webpack_require__(7),
|
2768 | parseGraphQL = _require5.parse,
|
2769 | parseType = _require5.parseType,
|
2770 | print = _require5.print,
|
2771 | Source = _require5.Source;
|
2772 |
|
2773 | var ARGUMENT_DEFINITIONS = 'argumentDefinitions';
|
2774 | var ARGUMENTS = 'arguments';
|
2775 | var DEPRECATED_UNCHECKED_ARGUMENTS = 'uncheckedArguments_DEPRECATED';
|
2776 | var DIRECTIVE_WHITELIST = new Set([ARGUMENT_DEFINITIONS, DEPRECATED_UNCHECKED_ARGUMENTS, ARGUMENTS]);
|
2777 | /**
|
2778 | * @internal
|
2779 | *
|
2780 | * This directive is not intended for use by developers directly. To set a field
|
2781 | * handle in product code use a compiler plugin.
|
2782 | */
|
2783 |
|
2784 | var CLIENT_FIELD = '__clientField';
|
2785 | var CLIENT_FIELD_HANDLE = 'handle';
|
2786 | var CLIENT_FIELD_KEY = 'key';
|
2787 | var CLIENT_FIELD_FILTERS = 'filters';
|
2788 | var INCLUDE = 'include';
|
2789 | var SKIP = 'skip';
|
2790 | var IF = 'if';
|
2791 | /**
|
2792 | * Transforms GraphQL text into Relay Compiler's internal, strongly-typed
|
2793 | * intermediate representation (IR).
|
2794 | */
|
2795 |
|
2796 | function parse(schema, text, filename) {
|
2797 | var ast = parseGraphQL(new Source(text, filename)); // TODO T24511737 figure out if this is dangerous
|
2798 |
|
2799 | var parser = new RelayParser(schema.DEPRECATED__extend(ast), ast.definitions);
|
2800 | return parser.transform();
|
2801 | }
|
2802 | /**
|
2803 | * Transforms untyped GraphQL parse trees (ASTs) into Relay Compiler's
|
2804 | * internal, strongly-typed intermediate representation (IR).
|
2805 | */
|
2806 |
|
2807 |
|
2808 | function transform(schema, definitions) {
|
2809 | return Profiler.run('RelayParser.transform', function () {
|
2810 | var parser = new RelayParser(schema, definitions);
|
2811 | return parser.transform();
|
2812 | });
|
2813 | }
|
2814 | /**
|
2815 | * @private
|
2816 | */
|
2817 |
|
2818 |
|
2819 | var RelayParser =
|
2820 | /*#__PURE__*/
|
2821 | function () {
|
2822 | function RelayParser(schema, definitions) {
|
2823 | var _this = this;
|
2824 |
|
2825 | this._definitions = new Map(); // leaving this configurable to make it easy to experiment w changing later
|
2826 |
|
2827 | this._getFieldDefinition = getFieldDefinitionLegacy;
|
2828 | this._schema = schema;
|
2829 | var duplicated = new Set();
|
2830 | definitions.forEach(function (def) {
|
2831 | if (isExecutableDefinitionAST(def)) {
|
2832 | var name = getName(def);
|
2833 |
|
2834 | if (_this._definitions.has(name)) {
|
2835 | duplicated.add(name);
|
2836 | return;
|
2837 | }
|
2838 |
|
2839 | _this._definitions.set(name, def);
|
2840 | }
|
2841 | });
|
2842 |
|
2843 | if (duplicated.size) {
|
2844 | 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) {
|
2845 | return "- ".concat(name);
|
2846 | }).join('\n'));
|
2847 | }
|
2848 | }
|
2849 |
|
2850 | var _proto = RelayParser.prototype;
|
2851 |
|
2852 | _proto.transform = function transform() {
|
2853 | var _this2 = this;
|
2854 |
|
2855 | var nodes = [];
|
2856 | var entries = new Map(); // Construct a mapping of name to definition ast + variable definitions.
|
2857 | // This allows the subsequent AST -> IR tranformation to reference the
|
2858 | // defined arguments of referenced fragments.
|
2859 |
|
2860 | eachWithCombinedError(this._definitions, function (_ref4) {
|
2861 | var name = _ref4[0],
|
2862 | definition = _ref4[1];
|
2863 |
|
2864 | var variableDefinitions = _this2._buildArgumentDefinitions(definition);
|
2865 |
|
2866 | entries.set(name, {
|
2867 | definition: definition,
|
2868 | variableDefinitions: variableDefinitions
|
2869 | });
|
2870 | }); // Convert the ASTs to IR.
|
2871 |
|
2872 | eachWithCombinedError(entries.values(), function (_ref5) {
|
2873 | var definition = _ref5.definition,
|
2874 | variableDefinitions = _ref5.variableDefinitions;
|
2875 | var node = parseDefinition(_this2._schema, _this2._getFieldDefinition, entries, definition, variableDefinitions);
|
2876 | nodes.push(node);
|
2877 | });
|
2878 | return nodes;
|
2879 | }
|
2880 | /**
|
2881 | * Constructs a mapping of variable names to definitions for the given
|
2882 | * operation/fragment definition.
|
2883 | */
|
2884 | ;
|
2885 |
|
2886 | _proto._buildArgumentDefinitions = function _buildArgumentDefinitions(definition) {
|
2887 | switch (definition.kind) {
|
2888 | case 'OperationDefinition':
|
2889 | return this._buildOperationArgumentDefinitions(definition);
|
2890 |
|
2891 | case 'FragmentDefinition':
|
2892 | return this._buildFragmentArgumentDefinitions(definition);
|
2893 |
|
2894 | default:
|
2895 | definition;
|
2896 | throw createCompilerError("Unexpected ast kind '".concat(definition.kind, "'."), [definition]);
|
2897 | }
|
2898 | }
|
2899 | /**
|
2900 | * Constructs a mapping of variable names to definitions using the
|
2901 | * variables defined in `@argumentDefinitions`.
|
2902 | */
|
2903 | ;
|
2904 |
|
2905 | _proto._buildFragmentArgumentDefinitions = function _buildFragmentArgumentDefinitions(fragment) {
|
2906 | var _this3 = this;
|
2907 |
|
2908 | var variableDirectives = (fragment.directives || []).filter(function (directive) {
|
2909 | return getName(directive) === ARGUMENT_DEFINITIONS;
|
2910 | });
|
2911 |
|
2912 | if (!variableDirectives.length) {
|
2913 | return new Map();
|
2914 | }
|
2915 |
|
2916 | if (variableDirectives.length !== 1) {
|
2917 | throw createUserError("Directive @".concat(ARGUMENT_DEFINITIONS, " may be defined at most once per ") + 'fragment.', null, variableDirectives);
|
2918 | }
|
2919 |
|
2920 | var variableDirective = variableDirectives[0]; // $FlowIssue: refining directly on `variableDirective.arguments` doesn't
|
2921 | // work, below accesses all report arguments could still be null/undefined.
|
2922 |
|
2923 | var args = variableDirective.arguments;
|
2924 |
|
2925 | if (variableDirective == null || !Array.isArray(args)) {
|
2926 | return new Map();
|
2927 | }
|
2928 |
|
2929 | if (!args.length) {
|
2930 | throw createUserError("Directive @".concat(ARGUMENT_DEFINITIONS, " requires arguments: remove the ") + 'directive to skip defining local variables for this fragment.', null, [variableDirective]);
|
2931 | }
|
2932 |
|
2933 | var variables = new Map();
|
2934 | args.forEach(function (arg) {
|
2935 | var _ref;
|
2936 |
|
2937 | var argName = getName(arg);
|
2938 | var previousVariable = variables.get(argName);
|
2939 |
|
2940 | if (previousVariable != null) {
|
2941 | throw createUserError("Duplicate definition for variable '$".concat(argName, "'."), null, [previousVariable.ast, arg]);
|
2942 | }
|
2943 |
|
2944 | if (arg.value.kind !== 'ObjectValue') {
|
2945 | throw createUserError("Expected definition for variable '$".concat(argName, "' to be an object ") + "with the shape: '{type: string, defaultValue?: mixed}.", null, [arg.value]);
|
2946 | }
|
2947 |
|
2948 | var defaultValueNode;
|
2949 | var typeString;
|
2950 | arg.value.fields.forEach(function (field) {
|
2951 | var name = getName(field);
|
2952 |
|
2953 | if (name === 'type') {
|
2954 | typeString = transformLiteralValue(field.value, field);
|
2955 | } else if (name === 'defaultValue') {
|
2956 | defaultValueNode = field.value;
|
2957 | } else {
|
2958 | throw createUserError("Expected definition for variable '$".concat(argName, "' to be an object ") + "with the shape: '{type: string, defaultValue?: mixed}.", null, [arg.value]);
|
2959 | }
|
2960 | });
|
2961 |
|
2962 | if (typeof typeString !== 'string') {
|
2963 | throw createUserError("Expected definition for variable '$".concat(argName, "' to be an object ") + "with the shape: '{type: string, defaultValue?: mixed}.", null, [arg.value]);
|
2964 | }
|
2965 |
|
2966 | var typeFromAST = _this3._schema.getTypeFromAST(parseType(typeString));
|
2967 |
|
2968 | if (typeFromAST == null) {
|
2969 | throw createUserError("Unknown type \"".concat(typeString, "\" referenced in the argument definitions."), null, [arg]);
|
2970 | }
|
2971 |
|
2972 | var type = _this3._schema.asInputType(typeFromAST);
|
2973 |
|
2974 | if (type == null) {
|
2975 | throw createUserError("Expected type \"".concat(typeString, "\" to be an input type in the \"").concat(arg.name.value, "\" argument definitions."), null, [arg.value]);
|
2976 | }
|
2977 |
|
2978 | var defaultValue = defaultValueNode != null ? transformValue(_this3._schema, defaultValueNode, type, function (variableAst) {
|
2979 | throw createUserError("Expected 'defaultValue' to be a literal, got a variable.", null, [variableAst]);
|
2980 | }, {
|
2981 | nonStrictEnums: true
|
2982 | }) : null;
|
2983 |
|
2984 | if (defaultValue != null && defaultValue.kind !== 'Literal') {
|
2985 | throw createUserError("Expected 'defaultValue' to be a literal, got a variable.", [defaultValue.loc]);
|
2986 | }
|
2987 |
|
2988 | variables.set(argName, {
|
2989 | ast: arg,
|
2990 | defaultValue: (_ref = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.value) !== null && _ref !== void 0 ? _ref : null,
|
2991 | defined: true,
|
2992 | name: argName,
|
2993 | type: type
|
2994 | });
|
2995 | });
|
2996 | return variables;
|
2997 | }
|
2998 | /**
|
2999 | * Constructs a mapping of variable names to definitions using the
|
3000 | * standard GraphQL syntax for variable definitions.
|
3001 | */
|
3002 | ;
|
3003 |
|
3004 | _proto._buildOperationArgumentDefinitions = function _buildOperationArgumentDefinitions(operation) {
|
3005 | var schema = this._schema;
|
3006 | var variableDefinitions = new Map();
|
3007 | (operation.variableDefinitions || []).forEach(function (def) {
|
3008 | var name = getName(def.variable);
|
3009 | var typeFromAST = schema.getTypeFromAST(def.type);
|
3010 |
|
3011 | if (typeFromAST == null) {
|
3012 | throw createUserError("Unknown type: '".concat(getTypeName(def.type), "'."), null, [def.type]);
|
3013 | }
|
3014 |
|
3015 | var type = schema.asInputType(typeFromAST);
|
3016 |
|
3017 | if (type == null) {
|
3018 | throw createUserError("Expected type \"".concat(getTypeName(def.type), "\" to be an input type."), null, [def.type]);
|
3019 | }
|
3020 |
|
3021 | var defaultValue = def.defaultValue ? transformLiteralValue(def.defaultValue, def) : null;
|
3022 | var previousDefinition = variableDefinitions.get(name);
|
3023 |
|
3024 | if (previousDefinition != null) {
|
3025 | throw createUserError("Duplicate definition for variable '$".concat(name, "'."), null, [previousDefinition.ast, def]);
|
3026 | }
|
3027 |
|
3028 | variableDefinitions.set(name, {
|
3029 | ast: def,
|
3030 | defaultValue: defaultValue,
|
3031 | defined: true,
|
3032 | name: name,
|
3033 | type: type
|
3034 | });
|
3035 | });
|
3036 | return variableDefinitions;
|
3037 | };
|
3038 |
|
3039 | return RelayParser;
|
3040 | }();
|
3041 | /**
|
3042 | * @private
|
3043 | */
|
3044 |
|
3045 |
|
3046 | function parseDefinition(schema, getFieldDefinition, entries, definition, variableDefinitions) {
|
3047 | var parser = new GraphQLDefinitionParser(schema, getFieldDefinition, entries, definition, variableDefinitions);
|
3048 | return parser.transform();
|
3049 | }
|
3050 | /**
|
3051 | * @private
|
3052 | */
|
3053 |
|
3054 |
|
3055 | var GraphQLDefinitionParser =
|
3056 | /*#__PURE__*/
|
3057 | function () {
|
3058 | function GraphQLDefinitionParser(schema, getFieldDefinition, entries, definition, variableDefinitions) {
|
3059 | this._definition = definition;
|
3060 | this._entries = entries;
|
3061 | this._getFieldDefinition = getFieldDefinition;
|
3062 | this._schema = schema;
|
3063 | this._variableDefinitions = variableDefinitions;
|
3064 | this._unknownVariables = new Map();
|
3065 | }
|
3066 |
|
3067 | var _proto2 = GraphQLDefinitionParser.prototype;
|
3068 |
|
3069 | _proto2.transform = function transform() {
|
3070 | var definition = this._definition;
|
3071 |
|
3072 | switch (definition.kind) {
|
3073 | case 'OperationDefinition':
|
3074 | return this._transformOperation(definition);
|
3075 |
|
3076 | case 'FragmentDefinition':
|
3077 | return this._transformFragment(definition);
|
3078 |
|
3079 | default:
|
3080 | definition;
|
3081 | throw createCompilerError("Unsupported definition type ".concat(definition.kind), [definition]);
|
3082 | }
|
3083 | };
|
3084 |
|
3085 | _proto2._recordAndVerifyVariableReference = function _recordAndVerifyVariableReference(variable, name, usedAsType) {
|
3086 | // Special case for variables used in @arguments where we currently
|
3087 | // aren't guaranteed to be able to resolve the type.
|
3088 | if (usedAsType == null) {
|
3089 | if (!this._variableDefinitions.has(name) && !this._unknownVariables.has(name)) {
|
3090 | this._unknownVariables.set(name, {
|
3091 | ast: variable,
|
3092 | type: null
|
3093 | });
|
3094 | }
|
3095 |
|
3096 | return;
|
3097 | }
|
3098 |
|
3099 | var variableDefinition = this._variableDefinitions.get(name);
|
3100 |
|
3101 | if (variableDefinition != null) {
|
3102 | // If the variable is defined, all usages must be compatible
|
3103 | var effectiveType = variableDefinition.type;
|
3104 |
|
3105 | if (variableDefinition.defaultValue != null) {
|
3106 | // If a default value is defined then it is guaranteed to be used
|
3107 | // at runtime such that the effective type of the variable is non-null
|
3108 | effectiveType = this._schema.getNonNullType(this._schema.getNullableType(effectiveType));
|
3109 | }
|
3110 |
|
3111 | if (!this._schema.isTypeSubTypeOf(effectiveType, usedAsType)) {
|
3112 | 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]);
|
3113 | }
|
3114 | } else {
|
3115 | var previous = this._unknownVariables.get(name);
|
3116 |
|
3117 | if (!previous || !previous.type) {
|
3118 | // No previous usage, current type is strongest
|
3119 | this._unknownVariables.set(name, {
|
3120 | ast: variable,
|
3121 | type: usedAsType
|
3122 | });
|
3123 | } else {
|
3124 | var previousVariable = previous.ast,
|
3125 | previousType = previous.type;
|
3126 |
|
3127 | if (!(this._schema.isTypeSubTypeOf(usedAsType, previousType) || this._schema.isTypeSubTypeOf(previousType, usedAsType))) {
|
3128 | throw createUserError("Variable '$".concat(name, "' was used in locations expecting the conflicting types '").concat(String(previousType), "' and '").concat(String(usedAsType), "'."), null, [previousVariable, variable]);
|
3129 | } // If the new used type has stronger requirements, use that type as reference,
|
3130 | // otherwise keep referencing the previous type
|
3131 |
|
3132 |
|
3133 | if (this._schema.isTypeSubTypeOf(usedAsType, previousType)) {
|
3134 | this._unknownVariables.set(name, {
|
3135 | ast: variable,
|
3136 | type: usedAsType
|
3137 | });
|
3138 | }
|
3139 | }
|
3140 | }
|
3141 | };
|
3142 |
|
3143 | _proto2._getDirectiveLocations = function _getDirectiveLocations() {
|
3144 | if (!this._directiveLocations) {
|
3145 | var directiveDefs = this._schema.getDirectives();
|
3146 |
|
3147 | this._directiveLocations = new Map();
|
3148 | var _iteratorNormalCompletion = true;
|
3149 | var _didIteratorError = false;
|
3150 | var _iteratorError = undefined;
|
3151 |
|
3152 | try {
|
3153 | for (var _iterator = directiveDefs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
3154 | var def = _step.value;
|
3155 |
|
3156 | this._directiveLocations.set(def.name, def.locations);
|
3157 | }
|
3158 | } catch (err) {
|
3159 | _didIteratorError = true;
|
3160 | _iteratorError = err;
|
3161 | } finally {
|
3162 | try {
|
3163 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
3164 | _iterator["return"]();
|
3165 | }
|
3166 | } finally {
|
3167 | if (_didIteratorError) {
|
3168 | throw _iteratorError;
|
3169 | }
|
3170 | }
|
3171 | }
|
3172 | }
|
3173 |
|
3174 | return this._directiveLocations;
|
3175 | };
|
3176 |
|
3177 | _proto2._validateDirectivesLocation = function _validateDirectivesLocation(directives, allowedLocaction) {
|
3178 | if (!directives || !directives.length) {
|
3179 | return;
|
3180 | }
|
3181 |
|
3182 | var directiveLocs = this._getDirectiveLocations();
|
3183 |
|
3184 | var mismatches = directives.filter(function (directive) {
|
3185 | var name = getName(directive);
|
3186 |
|
3187 | if (DIRECTIVE_WHITELIST.has(name)) {
|
3188 | return false;
|
3189 | }
|
3190 |
|
3191 | var locs = directiveLocs.get(name);
|
3192 |
|
3193 | if (locs == null) {
|
3194 | throw createUserError("Unknown directive '".concat(name, "'."), null, [directive]);
|
3195 | }
|
3196 |
|
3197 | return !locs.some(function (loc) {
|
3198 | return loc === allowedLocaction;
|
3199 | });
|
3200 | });
|
3201 |
|
3202 | if (mismatches.length) {
|
3203 | var invalidDirectives = mismatches.map(function (directive) {
|
3204 | return '@' + getName(directive);
|
3205 | }).join(', ');
|
3206 | throw createUserError("Invalid directives ".concat(invalidDirectives, " found on ").concat(allowedLocaction, "."), null, mismatches);
|
3207 | }
|
3208 | };
|
3209 |
|
3210 | _proto2._transformFragment = function _transformFragment(fragment) {
|
3211 | var directives = this._transformDirectives((fragment.directives || []).filter(function (directive) {
|
3212 | return getName(directive) !== ARGUMENT_DEFINITIONS;
|
3213 | }), 'FRAGMENT_DEFINITION');
|
3214 |
|
3215 | var typeFromAST = this._schema.getTypeFromAST(fragment.typeCondition);
|
3216 |
|
3217 | if (typeFromAST == null) {
|
3218 | throw createUserError("Fragment \"".concat(fragment.name.value, "\" cannot condition on unknown ") + "type \"".concat(String(fragment.typeCondition.name.value), "\"."), null, [fragment.typeCondition]);
|
3219 | }
|
3220 |
|
3221 | var type = this._schema.asCompositeType(typeFromAST);
|
3222 |
|
3223 | if (type == null) {
|
3224 | throw createUserError("Fragment \"".concat(fragment.name.value, "\" cannot condition on non composite ") + "type \"".concat(String(type), "\"."), null, [fragment.typeCondition]);
|
3225 | }
|
3226 |
|
3227 | var selections = this._transformSelections(fragment.selectionSet, type, fragment.typeCondition);
|
3228 |
|
3229 | var argumentDefinitions = (0, _toConsumableArray2["default"])(buildArgumentDefinitions(this._variableDefinitions));
|
3230 | var _iteratorNormalCompletion2 = true;
|
3231 | var _didIteratorError2 = false;
|
3232 | var _iteratorError2 = undefined;
|
3233 |
|
3234 | try {
|
3235 | for (var _iterator2 = this._unknownVariables[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
3236 | var _step2$value = _step2.value,
|
3237 | name = _step2$value[0],
|
3238 | variableReference = _step2$value[1];
|
3239 | argumentDefinitions.push({
|
3240 | kind: 'RootArgumentDefinition',
|
3241 | loc: buildLocation(variableReference.ast.loc),
|
3242 | name: name,
|
3243 | type: variableReference.type
|
3244 | });
|
3245 | }
|
3246 | } catch (err) {
|
3247 | _didIteratorError2 = true;
|
3248 | _iteratorError2 = err;
|
3249 | } finally {
|
3250 | try {
|
3251 | if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
3252 | _iterator2["return"]();
|
3253 | }
|
3254 | } finally {
|
3255 | if (_didIteratorError2) {
|
3256 | throw _iteratorError2;
|
3257 | }
|
3258 | }
|
3259 | }
|
3260 |
|
3261 | return {
|
3262 | kind: 'Fragment',
|
3263 | directives: directives,
|
3264 | loc: buildLocation(fragment.loc),
|
3265 | metadata: null,
|
3266 | name: getName(fragment),
|
3267 | selections: selections,
|
3268 | type: type,
|
3269 | // $FlowFixMe - could be null
|
3270 | argumentDefinitions: argumentDefinitions
|
3271 | };
|
3272 | };
|
3273 |
|
3274 | _proto2._getLocationFromOperation = function _getLocationFromOperation(definition) {
|
3275 | switch (definition.operation) {
|
3276 | case 'query':
|
3277 | return 'QUERY';
|
3278 |
|
3279 | case 'mutation':
|
3280 | return 'MUTATION';
|
3281 |
|
3282 | case 'subscription':
|
3283 | return 'SUBSCRIPTION';
|
3284 |
|
3285 | default:
|
3286 | definition.operation;
|
3287 | throw createCompilerError("Unknown operation type '".concat(definition.operation, "'."), null, [definition]);
|
3288 | }
|
3289 | };
|
3290 |
|
3291 | _proto2._transformOperation = function _transformOperation(definition) {
|
3292 | var name = getName(definition);
|
3293 |
|
3294 | var directives = this._transformDirectives(definition.directives || [], this._getLocationFromOperation(definition));
|
3295 |
|
3296 | var type;
|
3297 | var operation;
|
3298 | var schema = this._schema;
|
3299 |
|
3300 | switch (definition.operation) {
|
3301 | case 'query':
|
3302 | operation = 'query';
|
3303 | type = schema.expectQueryType();
|
3304 | break;
|
3305 |
|
3306 | case 'mutation':
|
3307 | operation = 'mutation';
|
3308 | type = schema.expectMutationType();
|
3309 | break;
|
3310 |
|
3311 | case 'subscription':
|
3312 | operation = 'subscription';
|
3313 | type = schema.expectSubscriptionType();
|
3314 | break;
|
3315 |
|
3316 | default:
|
3317 | definition.operation;
|
3318 | throw createCompilerError("Unknown operation type '".concat(definition.operation, "'."), null, [definition]);
|
3319 | }
|
3320 |
|
3321 | if (!definition.selectionSet) {
|
3322 | throw createUserError('Expected operation to have selections.', null, [definition]);
|
3323 | }
|
3324 |
|
3325 | var selections = this._transformSelections(definition.selectionSet, type);
|
3326 |
|
3327 | var argumentDefinitions = buildArgumentDefinitions(this._variableDefinitions);
|
3328 |
|
3329 | if (this._unknownVariables.size !== 0) {
|
3330 | throw createUserError("Query '".concat(name, "' references undefined variables."), null, Array.from(this._unknownVariables.values(), function (variableReference) {
|
3331 | return variableReference.ast;
|
3332 | }));
|
3333 | }
|
3334 |
|
3335 | return {
|
3336 | kind: 'Root',
|
3337 | operation: operation,
|
3338 | loc: buildLocation(definition.loc),
|
3339 | metadata: null,
|
3340 | name: name,
|
3341 | argumentDefinitions: argumentDefinitions,
|
3342 | directives: directives,
|
3343 | selections: selections,
|
3344 | type: type
|
3345 | };
|
3346 | };
|
3347 |
|
3348 | _proto2._transformSelections = function _transformSelections(selectionSet, parentType, parentTypeAST) {
|
3349 | var _this4 = this;
|
3350 |
|
3351 | return selectionSet.selections.map(function (selection) {
|
3352 | var node;
|
3353 |
|
3354 | if (selection.kind === 'Field') {
|
3355 | node = _this4._transformField(selection, parentType);
|
3356 | } else if (selection.kind === 'FragmentSpread') {
|
3357 | node = _this4._transformFragmentSpread(selection, parentType, parentTypeAST);
|
3358 | } else if (selection.kind === 'InlineFragment') {
|
3359 | node = _this4._transformInlineFragment(selection, parentType, parentTypeAST);
|
3360 | } else {
|
3361 | selection.kind;
|
3362 | throw createCompilerError("Unknown ast kind '".concat(selection.kind, "'."), [selection]);
|
3363 | }
|
3364 |
|
3365 | var _this4$_splitConditio = _this4._splitConditions(node.directives),
|
3366 | conditions = _this4$_splitConditio[0],
|
3367 | directives = _this4$_splitConditio[1];
|
3368 |
|
3369 | var conditionalNodes = applyConditions(conditions, // $FlowFixMe(>=0.28.0)
|
3370 | [(0, _objectSpread2["default"])({}, node, {
|
3371 | directives: directives
|
3372 | })]);
|
3373 |
|
3374 | if (conditionalNodes.length !== 1) {
|
3375 | throw createCompilerError('Expected exactly one condition node.', null, selection.directives);
|
3376 | }
|
3377 |
|
3378 | return conditionalNodes[0];
|
3379 | });
|
3380 | };
|
3381 |
|
3382 | _proto2._transformInlineFragment = function _transformInlineFragment(fragment, parentType, parentTypeAST) {
|
3383 | var schema = this._schema;
|
3384 | var typeCondition = fragment.typeCondition != null ? schema.getTypeFromAST(fragment.typeCondition) : parentType;
|
3385 |
|
3386 | if (typeCondition == null) {
|
3387 | var _fragment$typeConditi;
|
3388 |
|
3389 | 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]);
|
3390 | }
|
3391 |
|
3392 | var typeConditionName = schema.getTypeString(typeCondition);
|
3393 | typeCondition = schema.asCompositeType(typeCondition);
|
3394 |
|
3395 | if (typeCondition == null) {
|
3396 | var _fragment$typeConditi2;
|
3397 |
|
3398 | 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]);
|
3399 | }
|
3400 |
|
3401 | var rawParentType = this._schema.assertCompositeType(this._schema.getRawType(parentType));
|
3402 |
|
3403 | checkFragmentSpreadTypeCompatibility(this._schema, typeCondition, rawParentType, null, fragment.typeCondition, parentTypeAST);
|
3404 |
|
3405 | var directives = this._transformDirectives(fragment.directives || [], 'INLINE_FRAGMENT');
|
3406 |
|
3407 | var selections = this._transformSelections(fragment.selectionSet, typeCondition, fragment.typeCondition);
|
3408 |
|
3409 | return {
|
3410 | kind: 'InlineFragment',
|
3411 | directives: directives,
|
3412 | loc: buildLocation(fragment.loc),
|
3413 | metadata: null,
|
3414 | selections: selections,
|
3415 | typeCondition: typeCondition
|
3416 | };
|
3417 | };
|
3418 |
|
3419 | _proto2._transformFragmentSpread = function _transformFragmentSpread(fragmentSpread, parentType, parentTypeAST) {
|
3420 | var _this5 = this;
|
3421 |
|
3422 | var fragmentName = getName(fragmentSpread);
|
3423 |
|
3424 | var _partitionArray = partitionArray(fragmentSpread.directives || [], function (directive) {
|
3425 | var name = getName(directive);
|
3426 | return name === ARGUMENTS || name === DEPRECATED_UNCHECKED_ARGUMENTS;
|
3427 | }),
|
3428 | argumentDirectives = _partitionArray[0],
|
3429 | otherDirectives = _partitionArray[1];
|
3430 |
|
3431 | if (argumentDirectives.length > 1) {
|
3432 | throw createUserError("Directive @".concat(ARGUMENTS, " may be used at most once per a fragment spread."), null, argumentDirectives);
|
3433 | }
|
3434 |
|
3435 | var fragmentDefinition = this._entries.get(fragmentName);
|
3436 |
|
3437 | if (fragmentDefinition == null) {
|
3438 | throw createUserError("Unknown fragment '".concat(fragmentName, "'."), null, [fragmentSpread.name]);
|
3439 | }
|
3440 |
|
3441 | var fragmentTypeNode = getFragmentType(fragmentDefinition.definition);
|
3442 |
|
3443 | var fragmentType = this._schema.assertCompositeType(this._schema.expectTypeFromAST(fragmentTypeNode));
|
3444 |
|
3445 | var rawParentType = this._schema.assertCompositeType(this._schema.getRawType(parentType));
|
3446 |
|
3447 | checkFragmentSpreadTypeCompatibility(this._schema, fragmentType, rawParentType, fragmentSpread.name.value, fragmentSpread, parentTypeAST);
|
3448 | var fragmentArgumentDefinitions = fragmentDefinition.variableDefinitions;
|
3449 | var argumentsDirective = argumentDirectives[0];
|
3450 | var args;
|
3451 |
|
3452 | if (argumentsDirective != null) {
|
3453 | var isDeprecatedUncheckedArguments = getName(argumentsDirective) === DEPRECATED_UNCHECKED_ARGUMENTS;
|
3454 | var hasInvalidArgument = false;
|
3455 | args = (argumentsDirective.arguments || []).map(function (arg) {
|
3456 | var _ref2;
|
3457 |
|
3458 | var argName = getName(arg);
|
3459 | var argValue = arg.value;
|
3460 | var argumentDefinition = fragmentArgumentDefinitions.get(argName);
|
3461 | var argumentType = (_ref2 = argumentDefinition === null || argumentDefinition === void 0 ? void 0 : argumentDefinition.type) !== null && _ref2 !== void 0 ? _ref2 : null;
|
3462 |
|
3463 | if (argValue.kind === 'Variable') {
|
3464 | if (argumentDefinition == null && !isDeprecatedUncheckedArguments) {
|
3465 | 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]);
|
3466 | }
|
3467 |
|
3468 | hasInvalidArgument = hasInvalidArgument || argumentDefinition == null; // TODO: check the type of the variable and use the type
|
3469 |
|
3470 | return {
|
3471 | kind: 'Argument',
|
3472 | loc: buildLocation(arg.loc),
|
3473 | name: argName,
|
3474 | value: _this5._transformVariable(argValue, null),
|
3475 | type: null
|
3476 | };
|
3477 | } else {
|
3478 | if (argumentType == null) {
|
3479 | 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]);
|
3480 | }
|
3481 |
|
3482 | var value = _this5._transformValue(argValue, argumentType);
|
3483 |
|
3484 | return {
|
3485 | kind: 'Argument',
|
3486 | loc: buildLocation(arg.loc),
|
3487 | name: argName,
|
3488 | value: value,
|
3489 | type: argumentType
|
3490 | };
|
3491 | }
|
3492 | });
|
3493 |
|
3494 | if (isDeprecatedUncheckedArguments && !hasInvalidArgument) {
|
3495 | throw createUserError("Invalid use of @".concat(DEPRECATED_UNCHECKED_ARGUMENTS, ": all arguments ") + "are defined, use @".concat(ARGUMENTS, " instead."), null, [argumentsDirective]);
|
3496 | }
|
3497 | }
|
3498 |
|
3499 | var directives = this._transformDirectives(otherDirectives, 'FRAGMENT_SPREAD');
|
3500 |
|
3501 | return {
|
3502 | kind: 'FragmentSpread',
|
3503 | args: args || [],
|
3504 | metadata: null,
|
3505 | loc: buildLocation(fragmentSpread.loc),
|
3506 | name: fragmentName,
|
3507 | directives: directives
|
3508 | };
|
3509 | };
|
3510 |
|
3511 | _proto2._transformField = function _transformField(field, parentType) {
|
3512 | var _ref3, _field$alias;
|
3513 |
|
3514 | var schema = this._schema;
|
3515 | var name = getName(field);
|
3516 |
|
3517 | var fieldDef = this._getFieldDefinition(schema, parentType, name, field);
|
3518 |
|
3519 | if (fieldDef == null) {
|
3520 | throw createUserError("Unknown field '".concat(name, "' on type '").concat(schema.getTypeString(parentType), "'."), null, [field]);
|
3521 | }
|
3522 |
|
3523 | var alias = (_ref3 = (_field$alias = field.alias) === null || _field$alias === void 0 ? void 0 : _field$alias.value) !== null && _ref3 !== void 0 ? _ref3 : name;
|
3524 |
|
3525 | var args = this._transformArguments(field.arguments || [], schema.getFieldArgs(fieldDef), fieldDef);
|
3526 |
|
3527 | var _partitionArray2 = partitionArray(field.directives || [], function (directive) {
|
3528 | return getName(directive) !== CLIENT_FIELD;
|
3529 | }),
|
3530 | otherDirectives = _partitionArray2[0],
|
3531 | clientFieldDirectives = _partitionArray2[1];
|
3532 |
|
3533 | var directives = this._transformDirectives(otherDirectives, 'FIELD');
|
3534 |
|
3535 | var type = schema.getFieldType(fieldDef);
|
3536 |
|
3537 | var handles = this._transformHandle(name, args, clientFieldDirectives);
|
3538 |
|
3539 | if (schema.isLeafType(schema.getRawType(type))) {
|
3540 | if (field.selectionSet && field.selectionSet.selections && field.selectionSet.selections.length) {
|
3541 | throw createUserError("Expected no selections for scalar field '".concat(name, "'."), null, [field]);
|
3542 | }
|
3543 |
|
3544 | return {
|
3545 | kind: 'ScalarField',
|
3546 | alias: alias,
|
3547 | args: args,
|
3548 | directives: directives,
|
3549 | handles: handles,
|
3550 | loc: buildLocation(field.loc),
|
3551 | metadata: null,
|
3552 | name: name,
|
3553 | type: schema.assertScalarFieldType(type)
|
3554 | };
|
3555 | } else {
|
3556 | var selections = field.selectionSet ? this._transformSelections(field.selectionSet, type) : null;
|
3557 |
|
3558 | if (selections == null || selections.length === 0) {
|
3559 | throw createUserError("Expected at least one selection for non-scalar field '".concat(name, "' on type '").concat(schema.getTypeString(type), "'."), null, [field]);
|
3560 | }
|
3561 |
|
3562 | return {
|
3563 | kind: 'LinkedField',
|
3564 | alias: alias,
|
3565 | args: args,
|
3566 | connection: false,
|
3567 | directives: directives,
|
3568 | handles: handles,
|
3569 | loc: buildLocation(field.loc),
|
3570 | metadata: null,
|
3571 | name: name,
|
3572 | selections: selections,
|
3573 | type: schema.assertLinkedFieldType(type)
|
3574 | };
|
3575 | }
|
3576 | };
|
3577 |
|
3578 | _proto2._transformHandle = function _transformHandle(fieldName, fieldArgs, clientFieldDirectives) {
|
3579 | var handles = null;
|
3580 | clientFieldDirectives.forEach(function (clientFieldDirective) {
|
3581 | var handleArgument = (clientFieldDirective.arguments || []).find(function (arg) {
|
3582 | return getName(arg) === CLIENT_FIELD_HANDLE;
|
3583 | });
|
3584 |
|
3585 | if (handleArgument) {
|
3586 | var name = null;
|
3587 | var key = DEFAULT_HANDLE_KEY;
|
3588 | var filters = null;
|
3589 | var maybeHandle = transformLiteralValue(handleArgument.value, handleArgument);
|
3590 |
|
3591 | if (typeof maybeHandle !== 'string') {
|
3592 | throw createUserError("Expected a string literal argument for the @".concat(CLIENT_FIELD, " directive."), null, [handleArgument.value]);
|
3593 | }
|
3594 |
|
3595 | name = maybeHandle;
|
3596 | var keyArgument = (clientFieldDirective.arguments || []).find(function (arg) {
|
3597 | return getName(arg) === CLIENT_FIELD_KEY;
|
3598 | });
|
3599 |
|
3600 | if (keyArgument) {
|
3601 | var maybeKey = transformLiteralValue(keyArgument.value, keyArgument);
|
3602 |
|
3603 | if (typeof maybeKey !== 'string') {
|
3604 | throw createUserError("Expected a string literal argument for the @".concat(CLIENT_FIELD, " directive."), null, [keyArgument.value]);
|
3605 | }
|
3606 |
|
3607 | key = maybeKey;
|
3608 | }
|
3609 |
|
3610 | var filtersArgument = (clientFieldDirective.arguments || []).find(function (arg) {
|
3611 | return getName(arg) === CLIENT_FIELD_FILTERS;
|
3612 | });
|
3613 |
|
3614 | if (filtersArgument) {
|
3615 | var maybeFilters = transformLiteralValue(filtersArgument.value, filtersArgument);
|
3616 |
|
3617 | if (!(Array.isArray(maybeFilters) && maybeFilters.every(function (filter) {
|
3618 | return typeof filter === 'string' && fieldArgs.some(function (fieldArg) {
|
3619 | return fieldArg.name === filter;
|
3620 | });
|
3621 | }))) {
|
3622 | throw createUserError("Expected an array of argument names on field '".concat(fieldName, "'."), null, [filtersArgument.value]);
|
3623 | } // $FlowFixMe
|
3624 |
|
3625 |
|
3626 | filters = maybeFilters;
|
3627 | }
|
3628 |
|
3629 | var dynamicKeyArgument = (clientFieldDirective.arguments || []).find(function (arg) {
|
3630 | return getName(arg) === 'dynamicKey_UNSTABLE';
|
3631 | });
|
3632 |
|
3633 | if (dynamicKeyArgument != null) {
|
3634 | throw createUserError('Dynamic keys are only supported with @connection.', null, [dynamicKeyArgument.value]);
|
3635 | }
|
3636 |
|
3637 | handles = handles || [];
|
3638 | handles.push({
|
3639 | name: name,
|
3640 | key: key,
|
3641 | filters: filters,
|
3642 | dynamicKey: null
|
3643 | });
|
3644 | }
|
3645 | });
|
3646 | return handles;
|
3647 | };
|
3648 |
|
3649 | _proto2._transformDirectives = function _transformDirectives(directives, location) {
|
3650 | var _this6 = this;
|
3651 |
|
3652 | this._validateDirectivesLocation(directives, location);
|
3653 |
|
3654 | return directives.map(function (directive) {
|
3655 | var name = getName(directive);
|
3656 |
|
3657 | var directiveDef = _this6._schema.getDirective(name);
|
3658 |
|
3659 | if (directiveDef == null) {
|
3660 | throw createUserError("Unknown directive '".concat(name, "'."), null, [directive]);
|
3661 | }
|
3662 |
|
3663 | var args = _this6._transformArguments(directive.arguments || [], directiveDef.args.map(function (item) {
|
3664 | return {
|
3665 | name: item.name,
|
3666 | type: item.type,
|
3667 | defaultValue: item.defaultValue
|
3668 | };
|
3669 | }), null, name);
|
3670 |
|
3671 | return {
|
3672 | kind: 'Directive',
|
3673 | loc: buildLocation(directive.loc),
|
3674 | name: name,
|
3675 | args: args
|
3676 | };
|
3677 | });
|
3678 | };
|
3679 |
|
3680 | _proto2._transformArguments = function _transformArguments(args, argumentDefinitions, field, directiveName) {
|
3681 | var _this7 = this;
|
3682 |
|
3683 | return args.map(function (arg) {
|
3684 | var argName = getName(arg);
|
3685 | var argDef = argumentDefinitions.find(function (def) {
|
3686 | return def.name === argName;
|
3687 | });
|
3688 |
|
3689 | if (argDef == null) {
|
3690 | 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, "'.") : '.');
|
3691 | throw createUserError(message, null, [arg]);
|
3692 | }
|
3693 |
|
3694 | var value = _this7._transformValue(arg.value, argDef.type);
|
3695 |
|
3696 | return {
|
3697 | kind: 'Argument',
|
3698 | loc: buildLocation(arg.loc),
|
3699 | name: argName,
|
3700 | value: value,
|
3701 | type: argDef.type
|
3702 | };
|
3703 | });
|
3704 | };
|
3705 |
|
3706 | _proto2._splitConditions = function _splitConditions(mixedDirectives) {
|
3707 | var _partitionArray3 = partitionArray(mixedDirectives, function (directive) {
|
3708 | return directive.name === INCLUDE || directive.name === SKIP;
|
3709 | }),
|
3710 | conditionDirectives = _partitionArray3[0],
|
3711 | otherDirectives = _partitionArray3[1];
|
3712 |
|
3713 | var conditions = conditionDirectives.map(function (directive) {
|
3714 | var passingValue = directive.name === INCLUDE;
|
3715 | var arg = directive.args[0];
|
3716 |
|
3717 | if (arg == null || arg.name !== IF) {
|
3718 | throw createUserError("Expected an 'if' argument to @".concat(directive.name, "."), [directive.loc]);
|
3719 | }
|
3720 |
|
3721 | if (!(arg.value.kind === 'Variable' || arg.value.kind === 'Literal')) {
|
3722 | throw createUserError("Expected the 'if' argument to @".concat(directive.name, " to be a variable or literal."), [directive.loc]);
|
3723 | }
|
3724 |
|
3725 | return {
|
3726 | kind: 'Condition',
|
3727 | condition: arg.value,
|
3728 | loc: directive.loc,
|
3729 | passingValue: passingValue,
|
3730 | selections: []
|
3731 | };
|
3732 | });
|
3733 | var sortedConditions = conditions.sort(function (a, b) {
|
3734 | if (a.condition.kind === 'Variable' && b.condition.kind === 'Variable') {
|
3735 | return a.condition.variableName < b.condition.variableName ? -1 : a.condition.variableName > b.condition.variableName ? 1 : 0;
|
3736 | } else {
|
3737 | // sort literals earlier, variables later
|
3738 | return a.condition.kind === 'Variable' ? 1 : b.condition.kind === 'Variable' ? -1 : 0;
|
3739 | }
|
3740 | });
|
3741 | return [sortedConditions, otherDirectives];
|
3742 | };
|
3743 |
|
3744 | _proto2._transformVariable = function _transformVariable(ast, usedAsType) {
|
3745 | var variableName = getName(ast);
|
3746 |
|
3747 | this._recordAndVerifyVariableReference(ast, variableName, usedAsType);
|
3748 |
|
3749 | return {
|
3750 | kind: 'Variable',
|
3751 | loc: buildLocation(ast.loc),
|
3752 | variableName: variableName,
|
3753 | type: usedAsType
|
3754 | };
|
3755 | };
|
3756 |
|
3757 | _proto2._transformValue = function _transformValue(ast, type) {
|
3758 | var _this8 = this;
|
3759 |
|
3760 | return transformValue(this._schema, ast, type, function (variableAst, variableType) {
|
3761 | return _this8._transformVariable(variableAst, variableType);
|
3762 | });
|
3763 | };
|
3764 |
|
3765 | return GraphQLDefinitionParser;
|
3766 | }();
|
3767 | /**
|
3768 | * Transforms and validates argument values according to the expected
|
3769 | * type.
|
3770 | */
|
3771 |
|
3772 |
|
3773 | function transformValue(schema, ast, type, transformVariable) {
|
3774 | var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
|
3775 | nonStrictEnums: false
|
3776 | };
|
3777 |
|
3778 | if (ast.kind === 'Variable') {
|
3779 | // Special case variables since there is no value to parse
|
3780 | return transformVariable(ast, type);
|
3781 | } else if (ast.kind === 'NullValue') {
|
3782 | // Special case null literals since there is no value to parse
|
3783 | if (schema.isNonNull(type)) {
|
3784 | throw createUserError("Expected a value matching type '".concat(String(type), "'."), null, [ast]);
|
3785 | }
|
3786 |
|
3787 | return {
|
3788 | kind: 'Literal',
|
3789 | loc: buildLocation(ast.loc),
|
3790 | value: null
|
3791 | };
|
3792 | } else {
|
3793 | return transformNonNullLiteral(schema, ast, type, transformVariable, options);
|
3794 | }
|
3795 | }
|
3796 | /**
|
3797 | * Transforms and validates non-null literal (non-variable) values
|
3798 | * according to the expected type.
|
3799 | */
|
3800 |
|
3801 |
|
3802 | function transformNonNullLiteral(schema, ast, type, transformVariable, options) {
|
3803 | // Transform the value based on the type without a non-null wrapper.
|
3804 | // Note that error messages should still use the original `type`
|
3805 | // since that accurately describes to the user what the expected
|
3806 | // type is (using nullableType would suggest that `null` is legal
|
3807 | // even when it may not be, for example).
|
3808 | var nullableType = schema.getNullableType(type);
|
3809 |
|
3810 | if (schema.isList(nullableType)) {
|
3811 | if (ast.kind !== 'ListValue') {
|
3812 | // Parse singular (non-list) values flowing into a list type
|
3813 | // as scalars, ie without wrapping them in an array.
|
3814 | if (!schema.isInputType(schema.getListItemType(nullableType))) {
|
3815 | throw createUserError("Expected type ".concat(schema.getTypeString(nullableType), " to be an input type."), null, [ast]);
|
3816 | }
|
3817 |
|
3818 | return transformValue(schema, ast, schema.assertInputType(schema.getListItemType(nullableType)), transformVariable, options);
|
3819 | }
|
3820 |
|
3821 | var itemType = schema.assertInputType(schema.getListItemType(nullableType));
|
3822 | var literalList = [];
|
3823 | ast.values.forEach(function (item) {
|
3824 | var itemValue = transformValue(schema, item, itemType, transformVariable, options);
|
3825 |
|
3826 | if (itemValue.kind === 'Literal') {
|
3827 | literalList.push(itemValue.value);
|
3828 | } else if (itemValue.kind === 'Variable') {
|
3829 | throw createUserError('Complex argument values (Lists or InputObjects with nested variables) are not supported.', null, [item]);
|
3830 | }
|
3831 | });
|
3832 | return {
|
3833 | kind: 'Literal',
|
3834 | loc: buildLocation(ast.loc),
|
3835 | value: literalList
|
3836 | };
|
3837 | } else if (schema.isInputObject(nullableType)) {
|
3838 | if (ast.kind !== 'ObjectValue') {
|
3839 | throw createUserError("Expected a value matching type '".concat(schema.getTypeString(type), "'."), null, [ast]);
|
3840 | }
|
3841 |
|
3842 | var literalObject = {};
|
3843 | var inputType = schema.assertInputObjectType(nullableType);
|
3844 | ast.fields.forEach(function (field) {
|
3845 | var fieldName = getName(field);
|
3846 | var fieldID = schema.getFieldByName(inputType, fieldName);
|
3847 |
|
3848 | if (!fieldID) {
|
3849 | throw createUserError("Unknown field '".concat(fieldName, "' on type '").concat(schema.getTypeString(inputType), "'."), null, [field]);
|
3850 | }
|
3851 |
|
3852 | var fieldConfig = schema.getFieldConfig(fieldID);
|
3853 | var fieldType = schema.assertInputType(fieldConfig.type);
|
3854 | var fieldValue = transformValue(schema, field.value, fieldType, transformVariable, options);
|
3855 |
|
3856 | if (fieldValue.kind === 'Literal') {
|
3857 | literalObject[field.name.value] = fieldValue.value;
|
3858 | } else if (fieldValue.kind === 'Variable') {
|
3859 | throw createUserError('Complex argument values (Lists or InputObjects with nested variables) are not supported.', null, [field.value]);
|
3860 | }
|
3861 | });
|
3862 | return {
|
3863 | kind: 'Literal',
|
3864 | loc: buildLocation(ast.loc),
|
3865 | value: literalObject
|
3866 | };
|
3867 | } else if (schema.isId(nullableType)) {
|
3868 | // GraphQLID's parseLiteral() always returns the string value. However
|
3869 | // the int/string distinction may be important at runtime, so this
|
3870 | // transform parses int/string literals into the corresponding JS types.
|
3871 | if (ast.kind === 'IntValue') {
|
3872 | return {
|
3873 | kind: 'Literal',
|
3874 | loc: buildLocation(ast.loc),
|
3875 | value: parseInt(ast.value, 10)
|
3876 | };
|
3877 | } else if (ast.kind === 'StringValue') {
|
3878 | return {
|
3879 | kind: 'Literal',
|
3880 | loc: buildLocation(ast.loc),
|
3881 | value: ast.value
|
3882 | };
|
3883 | } else {
|
3884 | throw createUserError("Invalid value, expected a value matching type '".concat(schema.getTypeString(type), "'."), null, [ast]);
|
3885 | }
|
3886 | } else if (schema.isEnum(nullableType)) {
|
3887 | var enumType = schema.assertEnumType(nullableType);
|
3888 | var value = schema.parseLiteral(enumType, ast);
|
3889 |
|
3890 | if (value == null) {
|
3891 | if (options.nonStrictEnums) {
|
3892 | if (ast.kind === 'StringValue' || ast.kind === 'EnumValue') {
|
3893 | var _schema$parseValue;
|
3894 |
|
3895 | var alternateValue = (_schema$parseValue = schema.parseValue(enumType, ast.value.toUpperCase())) !== null && _schema$parseValue !== void 0 ? _schema$parseValue : schema.parseValue(enumType, ast.value.toLowerCase());
|
3896 |
|
3897 | if (alternateValue != null) {
|
3898 | // Use the original raw value
|
3899 | return {
|
3900 | kind: 'Literal',
|
3901 | loc: buildLocation(ast.loc),
|
3902 | value: ast.value
|
3903 | };
|
3904 | }
|
3905 | }
|
3906 | }
|
3907 |
|
3908 | var suggestions = schema.getEnumValues(enumType); // parseLiteral() should return a non-null JavaScript value
|
3909 | // if the ast value is valid for the type.
|
3910 |
|
3911 | throw createUserError("Expected a value matching type '".concat(schema.getTypeString(type), "'. Possible values: ").concat(orList(suggestions), "?'"), null, [ast]);
|
3912 | }
|
3913 |
|
3914 | return {
|
3915 | kind: 'Literal',
|
3916 | loc: buildLocation(ast.loc),
|
3917 | value: value
|
3918 | };
|
3919 | } else if (schema.isScalar(nullableType)) {
|
3920 | var _value = schema.parseLiteral(schema.assertScalarType(nullableType), ast);
|
3921 |
|
3922 | if (_value == null) {
|
3923 | // parseLiteral() should return a non-null JavaScript value
|
3924 | // if the ast value is valid for the type.
|
3925 | throw createUserError("Expected a value matching type '".concat(schema.getTypeString(type), "'."), null, [ast]);
|
3926 | }
|
3927 |
|
3928 | return {
|
3929 | kind: 'Literal',
|
3930 | loc: buildLocation(ast.loc),
|
3931 | value: _value
|
3932 | };
|
3933 | } else {
|
3934 | throw createCompilerError("Unsupported type '".concat(schema.getTypeString(type), "' for input value, expected a GraphQLList, ") + 'GraphQLInputObjectType, GraphQLEnumType, or GraphQLScalarType.', null, [ast]);
|
3935 | }
|
3936 | }
|
3937 | /**
|
3938 | * @private
|
3939 | */
|
3940 |
|
3941 |
|
3942 | function transformLiteralValue(ast, context) {
|
3943 | switch (ast.kind) {
|
3944 | case 'IntValue':
|
3945 | return parseInt(ast.value, 10);
|
3946 |
|
3947 | case 'FloatValue':
|
3948 | return parseFloat(ast.value);
|
3949 |
|
3950 | case 'StringValue':
|
3951 | return ast.value;
|
3952 |
|
3953 | case 'BooleanValue':
|
3954 | // Note: duplicated because Flow does not understand fall-through cases
|
3955 | return ast.value;
|
3956 |
|
3957 | case 'EnumValue':
|
3958 | // Note: duplicated because Flow does not understand fall-through cases
|
3959 | return ast.value;
|
3960 |
|
3961 | case 'ListValue':
|
3962 | return ast.values.map(function (item) {
|
3963 | return transformLiteralValue(item, context);
|
3964 | });
|
3965 |
|
3966 | case 'NullValue':
|
3967 | return null;
|
3968 |
|
3969 | case 'ObjectValue':
|
3970 | {
|
3971 | var objectValue = {};
|
3972 | ast.fields.forEach(function (field) {
|
3973 | var fieldName = getName(field);
|
3974 | var value = transformLiteralValue(field.value, context);
|
3975 | objectValue[fieldName] = value;
|
3976 | });
|
3977 | return objectValue;
|
3978 | }
|
3979 |
|
3980 | case 'Variable':
|
3981 | throw createUserError('Unexpected variable where a literal (static) value is required.', null, [ast, context]);
|
3982 |
|
3983 | default:
|
3984 | ast.kind;
|
3985 | throw createCompilerError("Unknown ast kind '".concat(ast.kind, "'."), [ast]);
|
3986 | }
|
3987 | }
|
3988 | /**
|
3989 | * @private
|
3990 | */
|
3991 |
|
3992 |
|
3993 | function buildArgumentDefinitions(variables) {
|
3994 | return Array.from(variables.values(), function (_ref6) {
|
3995 | var ast = _ref6.ast,
|
3996 | name = _ref6.name,
|
3997 | defaultValue = _ref6.defaultValue,
|
3998 | type = _ref6.type;
|
3999 | return {
|
4000 | kind: 'LocalArgumentDefinition',
|
4001 | loc: buildLocation(ast.loc),
|
4002 | name: name,
|
4003 | type: type,
|
4004 | defaultValue: defaultValue
|
4005 | };
|
4006 | });
|
4007 | }
|
4008 | /**
|
4009 | * @private
|
4010 | */
|
4011 |
|
4012 |
|
4013 | function buildLocation(loc) {
|
4014 | if (loc == null) {
|
4015 | return {
|
4016 | kind: 'Unknown'
|
4017 | };
|
4018 | }
|
4019 |
|
4020 | return {
|
4021 | kind: 'Source',
|
4022 | start: loc.start,
|
4023 | end: loc.end,
|
4024 | source: loc.source
|
4025 | };
|
4026 | }
|
4027 | /**
|
4028 | * @private
|
4029 | */
|
4030 |
|
4031 |
|
4032 | function applyConditions(conditions, selections) {
|
4033 | var nextSelections = selections;
|
4034 | conditions.forEach(function (condition) {
|
4035 | nextSelections = [(0, _objectSpread2["default"])({}, condition, {
|
4036 | selections: nextSelections
|
4037 | })];
|
4038 | });
|
4039 | return nextSelections;
|
4040 | }
|
4041 | /**
|
4042 | * @private
|
4043 | */
|
4044 |
|
4045 |
|
4046 | function getName(ast) {
|
4047 | var _ast$name;
|
4048 |
|
4049 | var name = (_ast$name = ast.name) === null || _ast$name === void 0 ? void 0 : _ast$name.value;
|
4050 |
|
4051 | if (typeof name !== 'string') {
|
4052 | throw createCompilerError("Expected ast node to have a 'name'.", null, [ast]);
|
4053 | }
|
4054 |
|
4055 | return name;
|
4056 | }
|
4057 |
|
4058 | function getTypeName(ast) {
|
4059 | return ast ? print(ast) : 'Undefined Type Name';
|
4060 | }
|
4061 | /**
|
4062 | * @private
|
4063 | */
|
4064 |
|
4065 |
|
4066 | function getFragmentType(ast) {
|
4067 | if (ast.kind === 'FragmentDefinition') {
|
4068 | return ast.typeCondition;
|
4069 | }
|
4070 |
|
4071 | throw createCompilerError('Expected ast node to be a FragmentDefinition node.', null, [ast]);
|
4072 | }
|
4073 |
|
4074 | function checkFragmentSpreadTypeCompatibility(schema, fragmentType, parentType, fragmentName, fragmentTypeAST, parentTypeAST) {
|
4075 | if (!schema.doTypesOverlap(fragmentType, schema.assertCompositeType(parentType))) {
|
4076 | var nodes = [];
|
4077 |
|
4078 | if (parentTypeAST) {
|
4079 | nodes.push(parentTypeAST);
|
4080 | }
|
4081 |
|
4082 | if (fragmentTypeAST) {
|
4083 | nodes.push(fragmentTypeAST);
|
4084 | }
|
4085 |
|
4086 | var possibleConcreteTypes = schema.isAbstractType(parentType) ? Array.from(schema.getPossibleTypes(schema.assertAbstractType(parentType))) : [];
|
4087 | var suggestedTypesMessage = '';
|
4088 |
|
4089 | if (possibleConcreteTypes.length !== 0) {
|
4090 | suggestedTypesMessage = " Possible concrete types include ".concat(possibleConcreteTypes.slice(0, 3).map(function (type) {
|
4091 | return "'".concat(schema.getTypeString(type), "'");
|
4092 | }).join(', '), ", etc.");
|
4093 | }
|
4094 |
|
4095 | 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);
|
4096 | }
|
4097 | }
|
4098 |
|
4099 | module.exports = {
|
4100 | parse: parse,
|
4101 | transform: transform
|
4102 | };
|
4103 |
|
4104 | /***/ }),
|
4105 | /* 28 */
|
4106 | /***/ (function(module, exports, __webpack_require__) {
|
4107 |
|
4108 | "use strict";
|
4109 | /**
|
4110 | * Copyright (c) Facebook, Inc. and its affiliates.
|
4111 | *
|
4112 | * This source code is licensed under the MIT license found in the
|
4113 | * LICENSE file in the root directory of this source tree.
|
4114 | *
|
4115 | *
|
4116 | * @format
|
4117 | */
|
4118 |
|
4119 | /**
|
4120 | * Partitions an array given a predicate. All elements satisfying the predicate
|
4121 | * are part of the first returned array, and all elements that don't are in the
|
4122 | * second.
|
4123 | */
|
4124 |
|
4125 | function partitionArray(array, predicate) {
|
4126 | var first = [];
|
4127 | var second = [];
|
4128 |
|
4129 | for (var i = 0; i < array.length; i++) {
|
4130 | var item = array[i];
|
4131 |
|
4132 | if (predicate(item)) {
|
4133 | first.push(item);
|
4134 | } else {
|
4135 | second.push(item);
|
4136 | }
|
4137 | }
|
4138 |
|
4139 | return [first, second];
|
4140 | }
|
4141 |
|
4142 | module.exports = partitionArray;
|
4143 |
|
4144 | /***/ }),
|
4145 | /* 29 */
|
4146 | /***/ (function(module, exports, __webpack_require__) {
|
4147 |
|
4148 | "use strict";
|
4149 | /**
|
4150 | * Copyright (c) Facebook, Inc. and its affiliates.
|
4151 | *
|
4152 | * This source code is licensed under the MIT license found in the
|
4153 | * LICENSE file in the root directory of this source tree.
|
4154 | *
|
4155 | *
|
4156 | * @format
|
4157 | */
|
4158 |
|
4159 |
|
4160 | module.exports = {
|
4161 | DEFAULT_HANDLE_KEY: ''
|
4162 | };
|
4163 |
|
4164 | /***/ }),
|
4165 | /* 30 */
|
4166 | /***/ (function(module, exports, __webpack_require__) {
|
4167 |
|
4168 | "use strict";
|
4169 | /**
|
4170 | * Copyright (c) Facebook, Inc. and its affiliates.
|
4171 | *
|
4172 | * This source code is licensed under the MIT license found in the
|
4173 | * LICENSE file in the root directory of this source tree.
|
4174 | *
|
4175 | *
|
4176 | * @format
|
4177 | */
|
4178 |
|
4179 |
|
4180 | var _require = __webpack_require__(1),
|
4181 | createCompilerError = _require.createCompilerError;
|
4182 |
|
4183 | var _require2 = __webpack_require__(7),
|
4184 | SchemaMetaFieldDef = _require2.SchemaMetaFieldDef,
|
4185 | TypeMetaFieldDef = _require2.TypeMetaFieldDef;
|
4186 |
|
4187 | /**
|
4188 | * Find the definition of a field of the specified type using strict
|
4189 | * resolution rules per the GraphQL spec.
|
4190 | */
|
4191 | function getFieldDefinitionStrict(schema, parentType, fieldName) {
|
4192 | var type = schema.getRawType(parentType);
|
4193 | var queryType = schema.getQueryType();
|
4194 | var isQueryType = queryType != null && schema.areEqualTypes(type, queryType);
|
4195 | var hasTypeName = schema.isAbstractType(type) || schema.isObject(type);
|
4196 | var schemaFieldDef;
|
4197 |
|
4198 | if (isQueryType && fieldName === SchemaMetaFieldDef.name) {
|
4199 | schemaFieldDef = queryType != null ? schema.getFieldByName(queryType, '__schema') : null;
|
4200 | } else if (isQueryType && fieldName === TypeMetaFieldDef.name) {
|
4201 | schemaFieldDef = queryType != null ? schema.getFieldByName(queryType, '__type') : null;
|
4202 | } else if (hasTypeName && fieldName === '__typename') {
|
4203 | schemaFieldDef = schema.getFieldByName(schema.assertCompositeType(type), '__typename');
|
4204 | } else if (hasTypeName && fieldName === '__id') {
|
4205 | schemaFieldDef = schema.getFieldByName(schema.assertCompositeType(type), '__id');
|
4206 | } else if (schema.isInterface(type) || schema.isObject(type)) {
|
4207 | var compositeType = schema.assertCompositeType(type);
|
4208 |
|
4209 | if (schema.hasField(compositeType, fieldName)) {
|
4210 | schemaFieldDef = schema.getFieldByName(compositeType, fieldName);
|
4211 | } else {
|
4212 | return null;
|
4213 | }
|
4214 | }
|
4215 |
|
4216 | return schemaFieldDef;
|
4217 | }
|
4218 | /**
|
4219 | * Find the definition of a field of the specified type, first trying
|
4220 | * the standard spec-compliant resolution process and falling back
|
4221 | * to legacy mode that supports fat interfaces.
|
4222 | */
|
4223 |
|
4224 |
|
4225 | function getFieldDefinitionLegacy(schema, parentType, fieldName, fieldAST) {
|
4226 | var _schemaFieldDef;
|
4227 |
|
4228 | var schemaFieldDef = getFieldDefinitionStrict(schema, parentType, fieldName);
|
4229 |
|
4230 | if (!schemaFieldDef) {
|
4231 | schemaFieldDef = getFieldDefinitionLegacyImpl(schema, parentType, fieldName, fieldAST);
|
4232 | }
|
4233 |
|
4234 | return (_schemaFieldDef = schemaFieldDef) !== null && _schemaFieldDef !== void 0 ? _schemaFieldDef : null;
|
4235 | }
|
4236 | /**
|
4237 | * @private
|
4238 | */
|
4239 |
|
4240 |
|
4241 | function getFieldDefinitionLegacyImpl(schema, type, fieldName, fieldAST) {
|
4242 | var rawType = schema.getRawType(type);
|
4243 |
|
4244 | if (schema.isAbstractType(rawType) && fieldAST && fieldAST.directives && fieldAST.directives.some(function (directive) {
|
4245 | return getName(directive) === 'fixme_fat_interface';
|
4246 | })) {
|
4247 | var possibleTypes = schema.getPossibleTypes(schema.assertAbstractType(rawType));
|
4248 | var schemaFieldDef;
|
4249 | var _iteratorNormalCompletion = true;
|
4250 | var _didIteratorError = false;
|
4251 | var _iteratorError = undefined;
|
4252 |
|
4253 | try {
|
4254 | var _loop = function _loop() {
|
4255 | var possibleType = _step.value;
|
4256 | var possibleField = schema.getFieldByName(possibleType, fieldName);
|
4257 |
|
4258 | if (possibleField) {
|
4259 | // Fat interface fields can have differing arguments. Try to return
|
4260 | // a field with matching arguments, but still return a field if the
|
4261 | // arguments do not match.
|
4262 | schemaFieldDef = possibleField;
|
4263 |
|
4264 | if (fieldAST && fieldAST.arguments) {
|
4265 | var argumentsAllExist = fieldAST.arguments.every(function (argument) {
|
4266 | return schema.getFieldArgByName(possibleField, getName(argument)) != null;
|
4267 | });
|
4268 |
|
4269 | if (argumentsAllExist) {
|
4270 | return "break";
|
4271 | }
|
4272 | }
|
4273 | }
|
4274 | };
|
4275 |
|
4276 | for (var _iterator = possibleTypes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
4277 | var _ret = _loop();
|
4278 |
|
4279 | if (_ret === "break") break;
|
4280 | }
|
4281 | } catch (err) {
|
4282 | _didIteratorError = true;
|
4283 | _iteratorError = err;
|
4284 | } finally {
|
4285 | try {
|
4286 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
4287 | _iterator["return"]();
|
4288 | }
|
4289 | } finally {
|
4290 | if (_didIteratorError) {
|
4291 | throw _iteratorError;
|
4292 | }
|
4293 | }
|
4294 | }
|
4295 |
|
4296 | return schemaFieldDef;
|
4297 | }
|
4298 | }
|
4299 | /**
|
4300 | * @private
|
4301 | */
|
4302 |
|
4303 |
|
4304 | function getName(ast) {
|
4305 | var name = ast.name ? ast.name.value : null;
|
4306 |
|
4307 | if (typeof name !== 'string') {
|
4308 | throw createCompilerError("Expected ast node to have a 'name'.", null, [ast]);
|
4309 | }
|
4310 |
|
4311 | return name;
|
4312 | }
|
4313 |
|
4314 | module.exports = {
|
4315 | getFieldDefinitionLegacy: getFieldDefinitionLegacy,
|
4316 | getFieldDefinitionStrict: getFieldDefinitionStrict
|
4317 | };
|
4318 |
|
4319 | /***/ }),
|
4320 | /* 31 */
|
4321 | /***/ (function(module, exports, __webpack_require__) {
|
4322 |
|
4323 | "use strict";
|
4324 | /**
|
4325 | * Copyright (c) Facebook, Inc. and its affiliates.
|
4326 | *
|
4327 | * This source code is licensed under the MIT license found in the
|
4328 | * LICENSE file in the root directory of this source tree.
|
4329 | *
|
4330 | *
|
4331 | * @format
|
4332 | */
|
4333 |
|
4334 |
|
4335 | var invariant = __webpack_require__(4);
|
4336 |
|
4337 | var _require = __webpack_require__(29),
|
4338 | DEFAULT_HANDLE_KEY = _require.DEFAULT_HANDLE_KEY;
|
4339 |
|
4340 | var INDENT = ' ';
|
4341 | /**
|
4342 | * Converts a GraphQLIR node into a GraphQL string. Custom Relay
|
4343 | * extensions (directives) are not supported; to print fragments with
|
4344 | * variables or fragment spreads with arguments, transform the node
|
4345 | * prior to printing.
|
4346 | */
|
4347 |
|
4348 | function print(schema, node) {
|
4349 | switch (node.kind) {
|
4350 | case 'Fragment':
|
4351 | return "fragment ".concat(node.name, " on ").concat(schema.getTypeString(node.type)) + printFragmentArgumentDefinitions(schema, node.argumentDefinitions) + printDirectives(schema, node.directives) + printSelections(schema, node, '', {}) + '\n';
|
4352 |
|
4353 | case 'Root':
|
4354 | return "".concat(node.operation, " ").concat(node.name) + printArgumentDefinitions(schema, node.argumentDefinitions) + printDirectives(schema, node.directives) + printSelections(schema, node, '', {}) + '\n';
|
4355 |
|
4356 | case 'SplitOperation':
|
4357 | return "SplitOperation ".concat(node.name, " on ").concat(schema.getTypeString(node.type)) + printSelections(schema, node, '', {}) + '\n';
|
4358 |
|
4359 | default:
|
4360 | node;
|
4361 | true ? true ? invariant(false, 'GraphQLIRPrinter: Unsupported IR node `%s`.', node.kind) : undefined : undefined;
|
4362 | }
|
4363 | }
|
4364 |
|
4365 | function printSelections(schema, node, indent, options) {
|
4366 | var selections = node.selections;
|
4367 |
|
4368 | if (selections == null) {
|
4369 | return '';
|
4370 | }
|
4371 |
|
4372 | var printed = selections.map(function (selection) {
|
4373 | return printSelection(schema, selection, indent, options);
|
4374 | });
|
4375 | return printed.length ? " {\n".concat(indent + INDENT).concat(printed.join('\n' + indent + INDENT), "\n").concat(indent).concat((options === null || options === void 0 ? void 0 : options.isClientExtension) === true ? '# ' : '', "}") : '';
|
4376 | }
|
4377 | /**
|
4378 | * Prints a field without subselections.
|
4379 | */
|
4380 |
|
4381 |
|
4382 | function printField(schema, field, options) {
|
4383 | var _ref;
|
4384 |
|
4385 | var parentDirectives = (_ref = options === null || options === void 0 ? void 0 : options.parentDirectives) !== null && _ref !== void 0 ? _ref : '';
|
4386 | var isClientExtension = (options === null || options === void 0 ? void 0 : options.isClientExtension) === true;
|
4387 | return (isClientExtension ? '# ' : '') + (field.alias === field.name ? field.name : field.alias + ': ' + field.name) + printArguments(schema, field.args) + parentDirectives + printDirectives(schema, field.directives) + printHandles(schema, field);
|
4388 | }
|
4389 |
|
4390 | function printSelection(schema, selection, indent, options) {
|
4391 | var _ref2;
|
4392 |
|
4393 | var str;
|
4394 | var parentDirectives = (_ref2 = options === null || options === void 0 ? void 0 : options.parentDirectives) !== null && _ref2 !== void 0 ? _ref2 : '';
|
4395 | var isClientExtension = (options === null || options === void 0 ? void 0 : options.isClientExtension) === true;
|
4396 |
|
4397 | if (selection.kind === 'LinkedField' || selection.kind === 'ConnectionField') {
|
4398 | str = printField(schema, selection, {
|
4399 | parentDirectives: parentDirectives,
|
4400 | isClientExtension: isClientExtension
|
4401 | });
|
4402 | str += printSelections(schema, selection, indent + INDENT, {
|
4403 | isClientExtension: isClientExtension
|
4404 | });
|
4405 | } else if (selection.kind === 'ModuleImport' || selection.kind === 'Connection') {
|
4406 | str = selection.selections.map(function (matchSelection) {
|
4407 | return printSelection(schema, matchSelection, indent, {
|
4408 | parentDirectives: parentDirectives,
|
4409 | isClientExtension: isClientExtension
|
4410 | });
|
4411 | }).join('\n' + indent + INDENT);
|
4412 | } else if (selection.kind === 'ScalarField') {
|
4413 | str = printField(schema, selection, {
|
4414 | parentDirectives: parentDirectives,
|
4415 | isClientExtension: isClientExtension
|
4416 | });
|
4417 | } else if (selection.kind === 'InlineFragment') {
|
4418 | str = '';
|
4419 |
|
4420 | if (isClientExtension) {
|
4421 | str += '# ';
|
4422 | }
|
4423 |
|
4424 | str += '... on ' + schema.getTypeString(selection.typeCondition);
|
4425 | str += parentDirectives;
|
4426 | str += printDirectives(schema, selection.directives);
|
4427 | str += printSelections(schema, selection, indent + INDENT, {
|
4428 | isClientExtension: isClientExtension
|
4429 | });
|
4430 | } else if (selection.kind === 'FragmentSpread') {
|
4431 | str = '';
|
4432 |
|
4433 | if (isClientExtension) {
|
4434 | str += '# ';
|
4435 | }
|
4436 |
|
4437 | str += '...' + selection.name;
|
4438 | str += parentDirectives;
|
4439 | str += printFragmentArguments(schema, selection.args);
|
4440 | str += printDirectives(schema, selection.directives);
|
4441 | } else if (selection.kind === 'InlineDataFragmentSpread') {
|
4442 | str = "# ".concat(selection.name, " @inline") + "\n".concat(indent).concat(INDENT, "...") + parentDirectives + printSelections(schema, selection, indent + INDENT, {});
|
4443 | } else if (selection.kind === 'Condition') {
|
4444 | var value = printValue(schema, selection.condition, null); // For Flow
|
4445 |
|
4446 | !(value != null) ? true ? invariant(false, 'GraphQLIRPrinter: Expected a variable for condition, got a literal `null`.') : undefined : void 0;
|
4447 | var condStr = selection.passingValue ? ' @include' : ' @skip';
|
4448 | condStr += '(if: ' + value + ')';
|
4449 | condStr += parentDirectives; // For multi-selection conditions, pushes the condition down to each
|
4450 |
|
4451 | var subSelections = selection.selections.map(function (sel) {
|
4452 | return printSelection(schema, sel, indent, {
|
4453 | parentDirectives: condStr,
|
4454 | isClientExtension: isClientExtension
|
4455 | });
|
4456 | });
|
4457 | str = subSelections.join('\n' + INDENT);
|
4458 | } else if (selection.kind === 'Stream') {
|
4459 | var streamStr = " @stream(label: \"".concat(selection.label, "\"");
|
4460 |
|
4461 | if (selection["if"] !== null) {
|
4462 | var _printValue;
|
4463 |
|
4464 | streamStr += ", if: ".concat((_printValue = printValue(schema, selection["if"], null)) !== null && _printValue !== void 0 ? _printValue : '');
|
4465 | }
|
4466 |
|
4467 | if (selection.initialCount !== null) {
|
4468 | var _printValue2;
|
4469 |
|
4470 | streamStr += ", initial_count: ".concat((_printValue2 = printValue(schema, selection.initialCount, null)) !== null && _printValue2 !== void 0 ? _printValue2 : '');
|
4471 | }
|
4472 |
|
4473 | streamStr += ')';
|
4474 | streamStr += parentDirectives;
|
4475 |
|
4476 | var _subSelections = selection.selections.map(function (sel) {
|
4477 | return printSelection(schema, sel, indent, {
|
4478 | parentDirectives: streamStr,
|
4479 | isClientExtension: isClientExtension
|
4480 | });
|
4481 | });
|
4482 |
|
4483 | str = _subSelections.join('\n' + INDENT);
|
4484 | } else if (selection.kind === 'Defer') {
|
4485 | var deferStr = " @defer(label: \"".concat(selection.label, "\"");
|
4486 |
|
4487 | if (selection["if"] !== null) {
|
4488 | var _printValue3;
|
4489 |
|
4490 | deferStr += ", if: ".concat((_printValue3 = printValue(schema, selection["if"], null)) !== null && _printValue3 !== void 0 ? _printValue3 : '');
|
4491 | }
|
4492 |
|
4493 | deferStr += ')';
|
4494 | deferStr += parentDirectives;
|
4495 |
|
4496 | if (selection.selections.every(function (subSelection) {
|
4497 | return subSelection.kind === 'InlineFragment' || subSelection.kind === 'FragmentSpread';
|
4498 | })) {
|
4499 | var _subSelections2 = selection.selections.map(function (sel) {
|
4500 | return printSelection(schema, sel, indent, {
|
4501 | parentDirectives: deferStr,
|
4502 | isClientExtension: isClientExtension
|
4503 | });
|
4504 | });
|
4505 |
|
4506 | str = _subSelections2.join('\n' + INDENT);
|
4507 | } else {
|
4508 | if (selection.metadata != null && selection.metadata.fragmentTypeCondition != null) {
|
4509 | str = "... on ".concat(schema.getTypeString(selection.metadata.fragmentTypeCondition)) + deferStr;
|
4510 | } else {
|
4511 | str = '...' + deferStr;
|
4512 | }
|
4513 |
|
4514 | str += printSelections(schema, selection, indent + INDENT, {
|
4515 | isClientExtension: isClientExtension
|
4516 | });
|
4517 | }
|
4518 | } else if (selection.kind === 'ClientExtension') {
|
4519 | !(isClientExtension === false) ? true ? invariant(false, 'GraphQLIRPrinter: Did not expect to encounter a ClientExtension node ' + 'as a descendant of another ClientExtension node.') : undefined : void 0;
|
4520 | str = '# Client-only selections:\n' + indent + INDENT + selection.selections.map(function (sel) {
|
4521 | return printSelection(schema, sel, indent, {
|
4522 | parentDirectives: parentDirectives,
|
4523 | isClientExtension: true
|
4524 | });
|
4525 | }).join('\n' + indent + INDENT);
|
4526 | } else {
|
4527 | selection;
|
4528 | true ? true ? invariant(false, 'GraphQLIRPrinter: Unknown selection kind `%s`.', selection.kind) : undefined : undefined;
|
4529 | }
|
4530 |
|
4531 | return str;
|
4532 | }
|
4533 |
|
4534 | function printArgumentDefinitions(schema, argumentDefinitions) {
|
4535 | var printed = argumentDefinitions.map(function (def) {
|
4536 | var str = "$".concat(def.name, ": ").concat(schema.getTypeString(def.type));
|
4537 |
|
4538 | if (def.defaultValue != null) {
|
4539 | str += ' = ' + printLiteral(schema, def.defaultValue, def.type);
|
4540 | }
|
4541 |
|
4542 | return str;
|
4543 | });
|
4544 | return printed.length ? "(\n".concat(INDENT).concat(printed.join('\n' + INDENT), "\n)") : '';
|
4545 | }
|
4546 |
|
4547 | function printFragmentArgumentDefinitions(schema, argumentDefinitions) {
|
4548 | var printed;
|
4549 | argumentDefinitions.forEach(function (def) {
|
4550 | if (def.kind !== 'LocalArgumentDefinition') {
|
4551 | return;
|
4552 | }
|
4553 |
|
4554 | printed = printed || [];
|
4555 | var str = "".concat(def.name, ": {type: \"").concat(schema.getTypeString(def.type), "\"");
|
4556 |
|
4557 | if (def.defaultValue != null) {
|
4558 | str += ", defaultValue: ".concat(printLiteral(schema, def.defaultValue, def.type));
|
4559 | }
|
4560 |
|
4561 | str += '}';
|
4562 | printed.push(str);
|
4563 | });
|
4564 | return printed && printed.length ? " @argumentDefinitions(\n".concat(INDENT).concat(printed.join('\n' + INDENT), "\n)") : '';
|
4565 | }
|
4566 |
|
4567 | function printHandles(schema, field) {
|
4568 | if (!field.handles) {
|
4569 | return '';
|
4570 | }
|
4571 |
|
4572 | var printed = field.handles.map(function (handle) {
|
4573 | // For backward compatibility and also because this module is shared by ComponentScript.
|
4574 | var key = handle.key === DEFAULT_HANDLE_KEY ? '' : ", key: \"".concat(handle.key, "\"");
|
4575 | var filters = handle.filters == null ? '' : ", filters: ".concat(JSON.stringify(Array.from(handle.filters).sort()));
|
4576 | return "@__clientField(handle: \"".concat(handle.name, "\"").concat(key).concat(filters, ")");
|
4577 | });
|
4578 | return printed.length ? ' ' + printed.join(' ') : '';
|
4579 | }
|
4580 |
|
4581 | function printDirectives(schema, directives) {
|
4582 | var printed = directives.map(function (directive) {
|
4583 | return '@' + directive.name + printArguments(schema, directive.args);
|
4584 | });
|
4585 | return printed.length ? ' ' + printed.join(' ') : '';
|
4586 | }
|
4587 |
|
4588 | function printFragmentArguments(schema, args) {
|
4589 | var printedArgs = printArguments(schema, args);
|
4590 |
|
4591 | if (!printedArgs.length) {
|
4592 | return '';
|
4593 | }
|
4594 |
|
4595 | return " @arguments".concat(printedArgs);
|
4596 | }
|
4597 |
|
4598 | function printArguments(schema, args) {
|
4599 | var printed = [];
|
4600 | args.forEach(function (arg) {
|
4601 | var printedValue = printValue(schema, arg.value, arg.type);
|
4602 |
|
4603 | if (printedValue != null) {
|
4604 | printed.push(arg.name + ': ' + printedValue);
|
4605 | }
|
4606 | });
|
4607 | return printed.length ? '(' + printed.join(', ') + ')' : '';
|
4608 | }
|
4609 |
|
4610 | function printValue(schema, value, type) {
|
4611 | if (type != null && schema.isNonNull(type)) {
|
4612 | type = schema.getNullableType(type);
|
4613 | }
|
4614 |
|
4615 | if (value.kind === 'Variable') {
|
4616 | return '$' + value.variableName;
|
4617 | } else if (value.value != null) {
|
4618 | return printLiteral(schema, value.value, type);
|
4619 | } else {
|
4620 | return null;
|
4621 | }
|
4622 | }
|
4623 |
|
4624 | function printLiteral(schema, value, type) {
|
4625 | if (value == null) {
|
4626 | var _JSON$stringify;
|
4627 |
|
4628 | return (_JSON$stringify = JSON.stringify(value)) !== null && _JSON$stringify !== void 0 ? _JSON$stringify : 'null';
|
4629 | }
|
4630 |
|
4631 | if (type != null && schema.isNonNull(type)) {
|
4632 | type = schema.getNullableType(type);
|
4633 | }
|
4634 |
|
4635 | if (type && schema.isEnum(type)) {
|
4636 | var _JSON$stringify2;
|
4637 |
|
4638 | var result = schema.serialize(schema.assertEnumType(type), value);
|
4639 |
|
4640 | if (result == null && typeof value === 'string') {
|
4641 | // For backwards compatibility, print invalid input values as-is. This
|
4642 | // can occur with literals defined as an @argumentDefinitions
|
4643 | // defaultValue.
|
4644 | result = value;
|
4645 | }
|
4646 |
|
4647 | !(typeof result === 'string') ? true ? invariant(false, 'GraphQLIRPrinter: Expected value of type %s to be a valid enum value, got `%s`.', schema.getTypeString(type), (_JSON$stringify2 = JSON.stringify(value)) !== null && _JSON$stringify2 !== void 0 ? _JSON$stringify2 : 'null') : undefined : void 0;
|
4648 | return result;
|
4649 | } else if (type && (schema.isId(type) || schema.isInt(type))) {
|
4650 | var _JSON$stringify3;
|
4651 |
|
4652 | return (_JSON$stringify3 = JSON.stringify(value)) !== null && _JSON$stringify3 !== void 0 ? _JSON$stringify3 : '';
|
4653 | } else if (type && schema.isScalar(type)) {
|
4654 | var _JSON$stringify4;
|
4655 |
|
4656 | var _result = schema.serialize(schema.assertScalarType(type), value);
|
4657 |
|
4658 | return (_JSON$stringify4 = JSON.stringify(_result)) !== null && _JSON$stringify4 !== void 0 ? _JSON$stringify4 : '';
|
4659 | } else if (Array.isArray(value)) {
|
4660 | !(type && schema.isList(type)) ? true ? invariant(false, 'GraphQLIRPrinter: Need a type in order to print arrays.') : undefined : void 0;
|
4661 | var itemType = schema.getListItemType(type);
|
4662 | return '[' + value.map(function (item) {
|
4663 | return printLiteral(schema, item, itemType);
|
4664 | }).join(', ') + ']';
|
4665 | } else if (type && schema.isList(type) && value != null) {
|
4666 | // Not an array, but still a list. Treat as list-of-one as per spec 3.1.7:
|
4667 | // http://facebook.github.io/graphql/October2016/#sec-Lists
|
4668 | return printLiteral(schema, value, schema.getListItemType(type));
|
4669 | } else if (typeof value === 'object' && value != null) {
|
4670 | var fields = [];
|
4671 | !(type && schema.isInputObject(type)) ? true ? invariant(false, 'GraphQLIRPrinter: Need an InputObject type to print objects.') : undefined : void 0;
|
4672 | var inputType = schema.assertInputObjectType(type);
|
4673 |
|
4674 | for (var key in value) {
|
4675 | if (value.hasOwnProperty(key)) {
|
4676 | var fieldConfig = schema.getFieldConfig(schema.expectField(inputType, key));
|
4677 | fields.push(key + ': ' + printLiteral(schema, value[key], fieldConfig.type));
|
4678 | }
|
4679 | }
|
4680 |
|
4681 | return '{' + fields.join(', ') + '}';
|
4682 | } else {
|
4683 | var _JSON$stringify5;
|
4684 |
|
4685 | return (_JSON$stringify5 = JSON.stringify(value)) !== null && _JSON$stringify5 !== void 0 ? _JSON$stringify5 : 'null';
|
4686 | }
|
4687 | }
|
4688 |
|
4689 | module.exports = {
|
4690 | print: print,
|
4691 | printField: printField,
|
4692 | printArguments: printArguments,
|
4693 | printDirectives: printDirectives
|
4694 | };
|
4695 |
|
4696 | /***/ }),
|
4697 | /* 32 */
|
4698 | /***/ (function(module, exports, __webpack_require__) {
|
4699 |
|
4700 | "use strict";
|
4701 | /**
|
4702 | * Copyright (c) Facebook, Inc. and its affiliates.
|
4703 | *
|
4704 | * This source code is licensed under the MIT license found in the
|
4705 | * LICENSE file in the root directory of this source tree.
|
4706 | *
|
4707 | *
|
4708 | * @format
|
4709 | */
|
4710 |
|
4711 | /**
|
4712 | * Marks a string of code as code to be replaced later.
|
4713 | */
|
4714 |
|
4715 | function moduleDependency(code) {
|
4716 | return "@@MODULE_START@@".concat(code, "@@MODULE_END@@");
|
4717 | }
|
4718 | /**
|
4719 | * After JSON.stringify'ing some code that contained parts marked with `mark()`,
|
4720 | * this post-processes the JSON to convert the marked code strings to raw code.
|
4721 | *
|
4722 | * Example:
|
4723 | * CodeMarker.postProcess(
|
4724 | * JSON.stringify({code: CodeMarker.mark('alert(1)')})
|
4725 | * )
|
4726 | */
|
4727 |
|
4728 |
|
4729 | function postProcess(json, printModule) {
|
4730 | return json.replace(/"@@MODULE_START@@(.*?)@@MODULE_END@@"/g, function (_, moduleName) {
|
4731 | return printModule(moduleName);
|
4732 | });
|
4733 | }
|
4734 | /**
|
4735 | * Transforms a value such that any transitive CodeMarker strings are replaced
|
4736 | * with the value of the named module in the given module map.
|
4737 | */
|
4738 |
|
4739 |
|
4740 | function transform(node, moduleMap) {
|
4741 | if (node == null) {
|
4742 | return node;
|
4743 | } else if (Array.isArray(node)) {
|
4744 | return node.map(function (item) {
|
4745 | return transform(item, moduleMap);
|
4746 | });
|
4747 | } else if (typeof node === 'object') {
|
4748 | var next = {};
|
4749 | Object.keys(node).forEach(function (key) {
|
4750 | next[key] = transform(node[key], moduleMap);
|
4751 | });
|
4752 | return next;
|
4753 | } else if (typeof node === 'string') {
|
4754 | var match = /^@@MODULE_START@@(.*?)@@MODULE_END@@$/.exec(node);
|
4755 |
|
4756 | if (match != null) {
|
4757 | var moduleName = match[1];
|
4758 |
|
4759 | if (moduleMap.hasOwnProperty(moduleName)) {
|
4760 | return moduleMap[moduleName];
|
4761 | } else {
|
4762 | throw new Error("Could not find a value for CodeMarker value '".concat(moduleName, "', ") + 'make sure to supply one in the module mapping.');
|
4763 | }
|
4764 | } else if (node.indexOf('@@MODULE_START') >= 0) {
|
4765 | throw new Error("Found unprocessed CodeMarker value '".concat(node, "'."));
|
4766 | }
|
4767 |
|
4768 | return node;
|
4769 | } else {
|
4770 | // mixed
|
4771 | return node;
|
4772 | }
|
4773 | }
|
4774 |
|
4775 | module.exports = {
|
4776 | moduleDependency: moduleDependency,
|
4777 | postProcess: postProcess,
|
4778 | transform: transform
|
4779 | };
|
4780 |
|
4781 | /***/ }),
|
4782 | /* 33 */
|
4783 | /***/ (function(module, exports, __webpack_require__) {
|
4784 |
|
4785 | "use strict";
|
4786 | /**
|
4787 | * Copyright (c) Facebook, Inc. and its affiliates.
|
4788 | *
|
4789 | * This source code is licensed under the MIT license found in the
|
4790 | * LICENSE file in the root directory of this source tree.
|
4791 | *
|
4792 | *
|
4793 | * @format
|
4794 | */
|
4795 |
|
4796 | /**
|
4797 | * Based on implementations by Gary Court and Austin Appleby, 2011, MIT.
|
4798 | * @preserve-header
|
4799 | */
|
4800 |
|
4801 |
|
4802 | var BASE62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
4803 | /**
|
4804 | * @param {string} key A UTF-16 or ASCII string
|
4805 | * @return {string} a base62 murmur hash
|
4806 | */
|
4807 |
|
4808 | function murmurHash(str) {
|
4809 | /* eslint-disable no-bitwise */
|
4810 | var length = str.length;
|
4811 | var rem = length & 3;
|
4812 | var len = length ^ rem;
|
4813 | var h = 0;
|
4814 | var i = 0;
|
4815 | var k;
|
4816 |
|
4817 | while (i !== len) {
|
4818 | var ch4 = str.charCodeAt(i + 3);
|
4819 | k = str.charCodeAt(i) ^ str.charCodeAt(i + 1) << 8 ^ str.charCodeAt(i + 2) << 16 ^ (ch4 & 0xff) << 24 ^ (ch4 & 0xff00) >> 8;
|
4820 | i += 4;
|
4821 | k = k * 0x2d51 + (k & 0xffff) * 0xcc9e0000 >>> 0;
|
4822 | k = k << 15 | k >>> 17;
|
4823 | k = k * 0x3593 + (k & 0xffff) * 0x1b870000 >>> 0;
|
4824 | h ^= k;
|
4825 | h = h << 13 | h >>> 19;
|
4826 | h = h * 5 + 0xe6546b64 >>> 0;
|
4827 | }
|
4828 |
|
4829 | k = 0;
|
4830 |
|
4831 | switch (rem) {
|
4832 | /* eslint-disable no-fallthrough */
|
4833 | case 3:
|
4834 | k ^= str.charCodeAt(len + 2) << 16;
|
4835 |
|
4836 | case 2:
|
4837 | k ^= str.charCodeAt(len + 1) << 8;
|
4838 |
|
4839 | case 1:
|
4840 | k ^= str.charCodeAt(len);
|
4841 | k = k * 0x2d51 + (k & 0xffff) * 0xcc9e0000 >>> 0;
|
4842 | k = k << 15 | k >>> 17;
|
4843 | k = k * 0x3593 + (k & 0xffff) * 0x1b870000 >>> 0;
|
4844 | h ^= k;
|
4845 | }
|
4846 |
|
4847 | h ^= length;
|
4848 | h ^= h >>> 16;
|
4849 | h = h * 0xca6b + (h & 0xffff) * 0x85eb0000 >>> 0;
|
4850 | h ^= h >>> 13;
|
4851 | h = h * 0xae35 + (h & 0xffff) * 0xc2b20000 >>> 0;
|
4852 | h ^= h >>> 16;
|
4853 | h >>>= 0;
|
4854 |
|
4855 | if (!h) {
|
4856 | return '0';
|
4857 | }
|
4858 |
|
4859 | var s = '';
|
4860 |
|
4861 | while (h) {
|
4862 | var d = h % 62;
|
4863 | s = BASE62[d] + s;
|
4864 | h = (h - d) / 62;
|
4865 | }
|
4866 |
|
4867 | return s;
|
4868 | }
|
4869 |
|
4870 | module.exports = murmurHash;
|
4871 |
|
4872 | /***/ }),
|
4873 | /* 34 */
|
4874 | /***/ (function(module, exports, __webpack_require__) {
|
4875 |
|
4876 | "use strict";
|
4877 | /**
|
4878 | * Copyright (c) Facebook, Inc. and its affiliates.
|
4879 | *
|
4880 | * This source code is licensed under the MIT license found in the
|
4881 | * LICENSE file in the root directory of this source tree.
|
4882 | *
|
4883 | *
|
4884 | * @format
|
4885 | */
|
4886 |
|
4887 |
|
4888 | var _interopRequireDefault = __webpack_require__(0);
|
4889 |
|
4890 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
4891 |
|
4892 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
4893 |
|
4894 | var IRTransformer = __webpack_require__(3);
|
4895 |
|
4896 | var _require = __webpack_require__(1),
|
4897 | createUserError = _require.createUserError;
|
4898 |
|
4899 | var _require2 = __webpack_require__(35),
|
4900 | buildConnectionMetadata = _require2.buildConnectionMetadata;
|
4901 |
|
4902 | var _require3 = __webpack_require__(9),
|
4903 | ConnectionInterface = _require3.ConnectionInterface;
|
4904 |
|
4905 | var SCHEMA_EXTENSION = "\n directive @connection_resolver(label: String!) on FIELD\n directive @stream_connection_resolver(\n label: String!\n initial_count: Int!\n if: Boolean = true\n ) on FIELD\n";
|
4906 |
|
4907 | /**
|
4908 | * This transform rewrites LinkedField nodes with @connection_resolver and
|
4909 | * rewrites their edges/pageInfo selections to be wrapped in a Connection node.
|
4910 | */
|
4911 | function connectionFieldTransform(context) {
|
4912 | return IRTransformer.transform(context, {
|
4913 | Fragment: visitFragmentOrRoot,
|
4914 | LinkedField: visitLinkedField,
|
4915 | Root: visitFragmentOrRoot,
|
4916 | ScalarField: visitScalarField
|
4917 | }, function (node) {
|
4918 | return {
|
4919 | documentName: node.name,
|
4920 | labels: new Map(),
|
4921 | path: [],
|
4922 | connectionMetadata: []
|
4923 | };
|
4924 | });
|
4925 | }
|
4926 |
|
4927 | function visitFragmentOrRoot(node, state) {
|
4928 | var transformedNode = this.traverse(node, state);
|
4929 | var connectionMetadata = state.connectionMetadata;
|
4930 |
|
4931 | if (connectionMetadata.length) {
|
4932 | return (0, _objectSpread2["default"])({}, transformedNode, {
|
4933 | metadata: (0, _objectSpread2["default"])({}, transformedNode.metadata, {
|
4934 | connection: connectionMetadata
|
4935 | })
|
4936 | });
|
4937 | }
|
4938 |
|
4939 | return transformedNode;
|
4940 | }
|
4941 |
|
4942 | function visitLinkedField(field, state) {
|
4943 | var context = this.getContext();
|
4944 | var schema = context.getSchema();
|
4945 | var path = state.path.concat(field.alias);
|
4946 | var transformed = this.traverse(field, (0, _objectSpread2["default"])({}, state, {
|
4947 | path: path
|
4948 | }));
|
4949 | var connectionDirective = transformed.directives.find(function (directive) {
|
4950 | return directive.name === 'connection_resolver' || directive.name === 'stream_connection_resolver';
|
4951 | });
|
4952 |
|
4953 | if (connectionDirective == null) {
|
4954 | return transformed;
|
4955 | }
|
4956 |
|
4957 | if (schema.isList(schema.getNullableType(transformed.type))) {
|
4958 | throw createUserError("@connection_resolver fields must return a single value, not a list, found '" + "".concat(schema.getTypeString(transformed.type), "'"), [transformed.loc]);
|
4959 | }
|
4960 |
|
4961 | var labelArg = connectionDirective.args.find(function (_ref4) {
|
4962 | var name = _ref4.name;
|
4963 | return name === 'label';
|
4964 | });
|
4965 | var label = getLiteralStringArgument(connectionDirective, 'label');
|
4966 |
|
4967 | if (typeof label !== 'string' || label !== state.documentName && label.indexOf(state.documentName + '$') !== 0) {
|
4968 | var _ref;
|
4969 |
|
4970 | throw createUserError('Invalid usage of @connection_resolver, expected a static string ' + "'label'. Labels may be the document name ('".concat(state.documentName, "') ") + "or be prefixed with the document name ('".concat(state.documentName, "$<name>')"), [(_ref = labelArg === null || labelArg === void 0 ? void 0 : labelArg.loc) !== null && _ref !== void 0 ? _ref : connectionDirective.loc]);
|
4971 | }
|
4972 |
|
4973 | var previousDirective = state.labels.get(label);
|
4974 |
|
4975 | if (previousDirective != null) {
|
4976 | var _ref2;
|
4977 |
|
4978 | var prevLabelArg = previousDirective.args.find(function (_ref5) {
|
4979 | var name = _ref5.name;
|
4980 | return name === 'label';
|
4981 | });
|
4982 | var previousLocation = (_ref2 = prevLabelArg === null || prevLabelArg === void 0 ? void 0 : prevLabelArg.loc) !== null && _ref2 !== void 0 ? _ref2 : previousDirective.loc;
|
4983 |
|
4984 | if (labelArg) {
|
4985 | throw createUserError('Invalid use of @connection_resolver, the provided label is ' + "not unique. Specify a unique 'label' as a literal string.", [labelArg === null || labelArg === void 0 ? void 0 : labelArg.loc, previousLocation]);
|
4986 | } else {
|
4987 | throw createUserError('Invalid use of @connection_resolver, could not generate a ' + "default label that is unique. Specify a unique 'label' " + 'as a literal string.', [connectionDirective.loc, previousLocation]);
|
4988 | }
|
4989 | }
|
4990 |
|
4991 | state.labels.set(label, connectionDirective);
|
4992 | var stream = null;
|
4993 |
|
4994 | if (connectionDirective.name === 'stream_connection_resolver') {
|
4995 | var initialCountArg = connectionDirective.args.find(function (arg) {
|
4996 | return arg.name === 'initial_count';
|
4997 | });
|
4998 | var ifArg = connectionDirective.args.find(function (arg) {
|
4999 | return arg.name === 'if';
|
5000 | });
|
5001 |
|
5002 | if (initialCountArg == null || initialCountArg.value.kind === 'Literal' && !Number.isInteger(initialCountArg.value.value)) {
|
5003 | var _ref3;
|
5004 |
|
5005 | throw createUserError("Invalid use of @connection_resolver, 'initial_count' is required " + "and must be an integer or variable of type 'Int!''.", [(_ref3 = initialCountArg === null || initialCountArg === void 0 ? void 0 : initialCountArg.loc) !== null && _ref3 !== void 0 ? _ref3 : connectionDirective.loc]);
|
5006 | }
|
5007 |
|
5008 | stream = {
|
5009 | deferLabel: label,
|
5010 | initialCount: initialCountArg.value,
|
5011 | "if": ifArg != null ? ifArg.value : null,
|
5012 | streamLabel: label
|
5013 | };
|
5014 | }
|
5015 |
|
5016 | var _ConnectionInterface$ = ConnectionInterface.get(),
|
5017 | EDGES = _ConnectionInterface$.EDGES,
|
5018 | PAGE_INFO = _ConnectionInterface$.PAGE_INFO;
|
5019 |
|
5020 | var edgeField;
|
5021 | var pageInfoField;
|
5022 | var selections = [];
|
5023 | transformed.selections.forEach(function (selection) {
|
5024 | if (!(selection.kind === 'LinkedField' || selection.kind === 'ScalarField')) {
|
5025 | throw createUserError('Invalid use of @connection_resolver, selections on the connection ' + 'must be linked or scalar fields.', [selection.loc]);
|
5026 | }
|
5027 |
|
5028 | if (selection.kind === 'LinkedField') {
|
5029 | if (selection.name === EDGES) {
|
5030 | edgeField = selection;
|
5031 | } else if (selection.name === PAGE_INFO) {
|
5032 | pageInfoField = selection;
|
5033 | } else {
|
5034 | selections.push(selection);
|
5035 | }
|
5036 | } else {
|
5037 | selections.push(selection);
|
5038 | }
|
5039 | });
|
5040 |
|
5041 | if (edgeField == null || pageInfoField == null) {
|
5042 | throw createUserError("Invalid use of @connection_resolver, fields '".concat(EDGES, "' and ") + "'".concat(PAGE_INFO, "' must be fetched."), [connectionDirective.loc]);
|
5043 | }
|
5044 |
|
5045 | var connectionType = schema.getRawType(transformed.type);
|
5046 | var edgesFieldDef = schema.isObject(connectionType) ? schema.getFieldByName(schema.assertObjectType(connectionType), 'edges') : null;
|
5047 | var edgesType = edgesFieldDef != null ? schema.getRawType(schema.getFieldType(edgesFieldDef)) : null;
|
5048 | var nodeFieldDef = edgesType != null && schema.isObject(edgesType) ? schema.getFieldByName(schema.assertObjectType(edgesType), 'node') : null;
|
5049 | var nodeType = nodeFieldDef != null ? schema.getRawType(schema.getFieldType(nodeFieldDef)) : null;
|
5050 |
|
5051 | if (edgesType == null || nodeType == null || !(schema.isObject(nodeType) || schema.isInterface(nodeType) || schema.isUnion(nodeType))) {
|
5052 | throw createUserError('Invalid usage of @connection_resolver, expected field to have shape ' + "'field { edges { node { ...} } }'.", [transformed.loc]);
|
5053 | }
|
5054 |
|
5055 | edgeField = (0, _objectSpread2["default"])({}, edgeField, {
|
5056 | selections: [].concat((0, _toConsumableArray2["default"])(edgeField.selections), [{
|
5057 | alias: '__id',
|
5058 | args: [],
|
5059 | directives: [],
|
5060 | handles: null,
|
5061 | kind: 'ScalarField',
|
5062 | loc: edgeField.loc,
|
5063 | metadata: null,
|
5064 | name: '__id',
|
5065 | type: schema.assertScalarFieldType(schema.getNonNullType(schema.expectIdType()))
|
5066 | }, {
|
5067 | alias: 'node',
|
5068 | args: [],
|
5069 | connection: false,
|
5070 | directives: [],
|
5071 | handles: null,
|
5072 | kind: 'LinkedField',
|
5073 | loc: edgeField.loc,
|
5074 | metadata: null,
|
5075 | name: 'node',
|
5076 | selections: [{
|
5077 | alias: '__id',
|
5078 | args: [],
|
5079 | directives: [],
|
5080 | handles: null,
|
5081 | kind: 'ScalarField',
|
5082 | loc: edgeField.loc,
|
5083 | metadata: null,
|
5084 | name: '__id',
|
5085 | type: schema.assertScalarFieldType(schema.getNonNullType(schema.expectIdType()))
|
5086 | }],
|
5087 | type: schema.assertLinkedFieldType(nodeType)
|
5088 | }])
|
5089 | });
|
5090 | selections.push({
|
5091 | args: transformed.args,
|
5092 | kind: 'Connection',
|
5093 | label: label,
|
5094 | loc: transformed.loc,
|
5095 | name: transformed.name,
|
5096 | selections: [edgeField, pageInfoField],
|
5097 | stream: stream,
|
5098 | type: transformed.type
|
5099 | });
|
5100 | var connectionMetadata = buildConnectionMetadata(transformed, path, stream != null);
|
5101 | state.connectionMetadata.push(connectionMetadata);
|
5102 | return {
|
5103 | alias: transformed.alias,
|
5104 | args: transformed.args,
|
5105 | directives: transformed.directives.filter(function (directive) {
|
5106 | return directive !== connectionDirective;
|
5107 | }),
|
5108 | kind: 'ConnectionField',
|
5109 | loc: transformed.loc,
|
5110 | metadata: null,
|
5111 | name: transformed.name,
|
5112 | selections: selections,
|
5113 | type: transformed.type
|
5114 | };
|
5115 | }
|
5116 |
|
5117 | function visitScalarField(field) {
|
5118 | var connectionDirective = field.directives.find(function (directive) {
|
5119 | return directive.name === 'connection_resolver';
|
5120 | });
|
5121 |
|
5122 | if (connectionDirective != null) {
|
5123 | throw createUserError('The @connection_resolver direction is not supported on scalar fields, ' + 'only fields returning an object/interface/union', [connectionDirective.loc]);
|
5124 | }
|
5125 |
|
5126 | return field;
|
5127 | }
|
5128 |
|
5129 | function getLiteralStringArgument(directive, argName) {
|
5130 | var arg = directive.args.find(function (_ref6) {
|
5131 | var name = _ref6.name;
|
5132 | return name === argName;
|
5133 | });
|
5134 |
|
5135 | if (arg == null) {
|
5136 | return null;
|
5137 | }
|
5138 |
|
5139 | var value = arg.value.kind === 'Literal' ? arg.value.value : null;
|
5140 |
|
5141 | if (value == null || typeof value !== 'string') {
|
5142 | throw createUserError("Expected the '".concat(argName, "' value to @").concat(directive.name, " to be a string literal if provided."), [arg.value.loc]);
|
5143 | }
|
5144 |
|
5145 | return value;
|
5146 | }
|
5147 |
|
5148 | module.exports = {
|
5149 | SCHEMA_EXTENSION: SCHEMA_EXTENSION,
|
5150 | transform: connectionFieldTransform
|
5151 | };
|
5152 |
|
5153 | /***/ }),
|
5154 | /* 35 */
|
5155 | /***/ (function(module, exports, __webpack_require__) {
|
5156 |
|
5157 | "use strict";
|
5158 | /**
|
5159 | * Copyright (c) Facebook, Inc. and its affiliates.
|
5160 | *
|
5161 | * This source code is licensed under the MIT license found in the
|
5162 | * LICENSE file in the root directory of this source tree.
|
5163 | *
|
5164 | *
|
5165 | * @format
|
5166 | */
|
5167 |
|
5168 |
|
5169 | var _interopRequireDefault = __webpack_require__(0);
|
5170 |
|
5171 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
5172 |
|
5173 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
5174 |
|
5175 | var IRTransformer = __webpack_require__(3);
|
5176 |
|
5177 | var RelayParser = __webpack_require__(27);
|
5178 |
|
5179 | var SchemaUtils = __webpack_require__(11);
|
5180 |
|
5181 | var getLiteralArgumentValues = __webpack_require__(16);
|
5182 |
|
5183 | var _require = __webpack_require__(1),
|
5184 | createCompilerError = _require.createCompilerError,
|
5185 | createUserError = _require.createUserError;
|
5186 |
|
5187 | var _require2 = __webpack_require__(7),
|
5188 | parse = _require2.parse;
|
5189 |
|
5190 | var _require3 = __webpack_require__(9),
|
5191 | ConnectionInterface = _require3.ConnectionInterface,
|
5192 | RelayFeatureFlags = _require3.RelayFeatureFlags;
|
5193 |
|
5194 | var AFTER = 'after';
|
5195 | var BEFORE = 'before';
|
5196 | var FIRST = 'first';
|
5197 | var KEY = 'key';
|
5198 | var LAST = 'last';
|
5199 | var CONNECTION = 'connection';
|
5200 | var STREAM_CONNECTION = 'stream_connection';
|
5201 | var HANDLER = 'handler';
|
5202 | /**
|
5203 | * @public
|
5204 | *
|
5205 | * Transforms fields with the `@connection` directive:
|
5206 | * - Verifies that the field type is connection-like.
|
5207 | * - Adds a `handle` property to the field, either the user-provided `handle`
|
5208 | * argument or the default value "connection".
|
5209 | * - Inserts a sub-fragment on the field to ensure that standard connection
|
5210 | * fields are fetched (e.g. cursors, node ids, page info).
|
5211 | */
|
5212 |
|
5213 | function connectionTransform(context) {
|
5214 | return IRTransformer.transform(context, {
|
5215 | Fragment: visitFragmentOrRoot,
|
5216 | LinkedField: visitLinkedField,
|
5217 | Root: visitFragmentOrRoot
|
5218 | }, function (node) {
|
5219 | return {
|
5220 | documentName: node.name,
|
5221 | path: [],
|
5222 | connectionMetadata: []
|
5223 | };
|
5224 | });
|
5225 | }
|
5226 |
|
5227 | var SCHEMA_EXTENSION = "\n directive @connection(\n key: String!\n filters: [String]\n handler: String\n dynamicKey_UNSTABLE: String\n ) on FIELD\n\n directive @stream_connection(\n key: String!\n filters: [String]\n handler: String\n label: String!\n initial_count: Int!\n if: Boolean = true\n dynamicKey_UNSTABLE: String\n ) on FIELD\n";
|
5228 | /**
|
5229 | * @internal
|
5230 | */
|
5231 |
|
5232 | function visitFragmentOrRoot(node, options) {
|
5233 | var transformedNode = this.traverse(node, options);
|
5234 | var connectionMetadata = options.connectionMetadata;
|
5235 |
|
5236 | if (connectionMetadata.length) {
|
5237 | return (0, _objectSpread2["default"])({}, transformedNode, {
|
5238 | metadata: (0, _objectSpread2["default"])({}, transformedNode.metadata, {
|
5239 | connection: connectionMetadata
|
5240 | })
|
5241 | });
|
5242 | }
|
5243 |
|
5244 | return transformedNode;
|
5245 | }
|
5246 | /**
|
5247 | * @internal
|
5248 | */
|
5249 |
|
5250 |
|
5251 | function visitLinkedField(field, options) {
|
5252 | var _connectionArguments$;
|
5253 |
|
5254 | var context = this.getContext();
|
5255 | var schema = context.getSchema();
|
5256 | var nullableType = schema.getNullableType(field.type);
|
5257 | var isPlural = schema.isList(nullableType);
|
5258 | var path = options.path.concat(isPlural ? null : field.alias || field.name);
|
5259 | var transformedField = this.traverse(field, (0, _objectSpread2["default"])({}, options, {
|
5260 | path: path
|
5261 | }));
|
5262 | var connectionDirective = field.directives.find(function (directive) {
|
5263 | return directive.name === CONNECTION || directive.name === STREAM_CONNECTION;
|
5264 | });
|
5265 |
|
5266 | if (!connectionDirective) {
|
5267 | return transformedField;
|
5268 | }
|
5269 |
|
5270 | if (!schema.isObject(nullableType) && !schema.isInterface(nullableType)) {
|
5271 | throw new createUserError("@".concat(connectionDirective.name, " used on invalid field '").concat(field.name, "'. ") + 'Expected the return type to be a non-plural interface or object, ' + "got '".concat(schema.getTypeString(field.type), "'."), [transformedField.loc]);
|
5272 | }
|
5273 |
|
5274 | validateConnectionSelection(transformedField);
|
5275 | validateConnectionType(schema, transformedField, schema.assertCompositeType(nullableType), connectionDirective);
|
5276 | var connectionArguments = buildConnectionArguments(transformedField, connectionDirective);
|
5277 | var connectionMetadata = buildConnectionMetadata(transformedField, path, connectionArguments.stream != null);
|
5278 | options.connectionMetadata.push(connectionMetadata);
|
5279 | var handle = {
|
5280 | name: (_connectionArguments$ = connectionArguments.handler) !== null && _connectionArguments$ !== void 0 ? _connectionArguments$ : CONNECTION,
|
5281 | key: connectionArguments.key,
|
5282 | dynamicKey: connectionArguments.dynamicKey,
|
5283 | filters: connectionArguments.filters
|
5284 | };
|
5285 | var direction = connectionMetadata.direction;
|
5286 |
|
5287 | if (direction != null) {
|
5288 | var selections = transformConnectionSelections(this.getContext(), transformedField, schema.assertCompositeType(nullableType), direction, connectionArguments, connectionDirective.loc, options.documentName);
|
5289 | transformedField = (0, _objectSpread2["default"])({}, transformedField, {
|
5290 | selections: selections
|
5291 | });
|
5292 | }
|
5293 |
|
5294 | return (0, _objectSpread2["default"])({}, transformedField, {
|
5295 | directives: transformedField.directives.filter(function (directive) {
|
5296 | return directive !== connectionDirective;
|
5297 | }),
|
5298 | connection: true,
|
5299 | handles: transformedField.handles ? [].concat((0, _toConsumableArray2["default"])(transformedField.handles), [handle]) : [handle]
|
5300 | });
|
5301 | }
|
5302 |
|
5303 | function buildConnectionArguments(field, connectionDirective) {
|
5304 | var _getLiteralArgumentVa = getLiteralArgumentValues(connectionDirective.args),
|
5305 | handler = _getLiteralArgumentVa.handler,
|
5306 | key = _getLiteralArgumentVa.key,
|
5307 | label = _getLiteralArgumentVa.label,
|
5308 | literalFilters = _getLiteralArgumentVa.filters;
|
5309 |
|
5310 | if (handler != null && typeof handler !== 'string') {
|
5311 | var _ref, _handleArg$value;
|
5312 |
|
5313 | var handleArg = connectionDirective.args.find(function (arg) {
|
5314 | return arg.name === 'key';
|
5315 | });
|
5316 | throw createUserError("Expected the ".concat(HANDLER, " argument to @").concat(connectionDirective.name, " to ") + "be a string literal for field ".concat(field.name, "."), [(_ref = handleArg === null || handleArg === void 0 ? void 0 : (_handleArg$value = handleArg.value) === null || _handleArg$value === void 0 ? void 0 : _handleArg$value.loc) !== null && _ref !== void 0 ? _ref : connectionDirective.loc]);
|
5317 | }
|
5318 |
|
5319 | if (typeof key !== 'string') {
|
5320 | var _ref2, _keyArg$value;
|
5321 |
|
5322 | var keyArg = connectionDirective.args.find(function (arg) {
|
5323 | return arg.name === 'key';
|
5324 | });
|
5325 | throw createUserError("Expected the ".concat(KEY, " argument to @").concat(connectionDirective.name, " to be a ") + "string literal for field ".concat(field.name, "."), [(_ref2 = keyArg === null || keyArg === void 0 ? void 0 : (_keyArg$value = keyArg.value) === null || _keyArg$value === void 0 ? void 0 : _keyArg$value.loc) !== null && _ref2 !== void 0 ? _ref2 : connectionDirective.loc]);
|
5326 | }
|
5327 |
|
5328 | var postfix = field.alias || field.name;
|
5329 |
|
5330 | if (!key.endsWith('_' + postfix)) {
|
5331 | var _ref3, _keyArg$value2;
|
5332 |
|
5333 | var _keyArg = connectionDirective.args.find(function (arg) {
|
5334 | return arg.name === 'key';
|
5335 | });
|
5336 |
|
5337 | throw createUserError("Expected the ".concat(KEY, " argument to @").concat(connectionDirective.name, " to be of ") + "form <SomeName>_".concat(postfix, ", got '").concat(key, "'. ") + 'For a detailed explanation, check out ' + 'https://relay.dev/docs/en/pagination-container#connection', [(_ref3 = _keyArg === null || _keyArg === void 0 ? void 0 : (_keyArg$value2 = _keyArg.value) === null || _keyArg$value2 === void 0 ? void 0 : _keyArg$value2.loc) !== null && _ref3 !== void 0 ? _ref3 : connectionDirective.loc]);
|
5338 | }
|
5339 |
|
5340 | if (literalFilters != null && (!Array.isArray(literalFilters) || literalFilters.some(function (filter) {
|
5341 | return typeof filter !== 'string';
|
5342 | }))) {
|
5343 | var _ref4, _filtersArg$value;
|
5344 |
|
5345 | var filtersArg = connectionDirective.args.find(function (arg) {
|
5346 | return arg.name === 'filters';
|
5347 | });
|
5348 | throw createUserError("Expected the 'filters' argument to @".concat(connectionDirective.name, " to be ") + 'a string literal.', [(_ref4 = filtersArg === null || filtersArg === void 0 ? void 0 : (_filtersArg$value = filtersArg.value) === null || _filtersArg$value === void 0 ? void 0 : _filtersArg$value.loc) !== null && _ref4 !== void 0 ? _ref4 : connectionDirective.loc]);
|
5349 | }
|
5350 |
|
5351 | var filters = literalFilters;
|
5352 |
|
5353 | if (filters == null) {
|
5354 | var generatedFilters = field.args.filter(function (arg) {
|
5355 | return !ConnectionInterface.isConnectionCall({
|
5356 | name: arg.name,
|
5357 | value: null
|
5358 | });
|
5359 | }).map(function (arg) {
|
5360 | return arg.name;
|
5361 | });
|
5362 | filters = generatedFilters.length !== 0 ? generatedFilters : null;
|
5363 | }
|
5364 |
|
5365 | var stream = null;
|
5366 |
|
5367 | if (connectionDirective.name === STREAM_CONNECTION) {
|
5368 | var _label;
|
5369 |
|
5370 | var initialCountArg = connectionDirective.args.find(function (arg) {
|
5371 | return arg.name === 'initial_count';
|
5372 | });
|
5373 | var ifArg = connectionDirective.args.find(function (arg) {
|
5374 | return arg.name === 'if';
|
5375 | });
|
5376 |
|
5377 | if (label != null && typeof label !== 'string') {
|
5378 | var _ref5, _labelArg$value;
|
5379 |
|
5380 | var labelArg = connectionDirective.args.find(function (arg) {
|
5381 | return arg.name === 'label';
|
5382 | });
|
5383 | throw createUserError("Expected the 'label' argument to @".concat(connectionDirective.name, " to be a string literal for field ").concat(field.name, "."), [(_ref5 = labelArg === null || labelArg === void 0 ? void 0 : (_labelArg$value = labelArg.value) === null || _labelArg$value === void 0 ? void 0 : _labelArg$value.loc) !== null && _ref5 !== void 0 ? _ref5 : connectionDirective.loc]);
|
5384 | }
|
5385 |
|
5386 | stream = {
|
5387 | "if": ifArg,
|
5388 | initialCount: initialCountArg,
|
5389 | label: (_label = label) !== null && _label !== void 0 ? _label : key
|
5390 | };
|
5391 | } // T45504512: new connection model
|
5392 |
|
5393 |
|
5394 | var dynamicKeyArg = connectionDirective.args.find(function (arg) {
|
5395 | return arg.name === 'dynamicKey_UNSTABLE';
|
5396 | });
|
5397 | var dynamicKey = null;
|
5398 |
|
5399 | if (dynamicKeyArg != null) {
|
5400 | if (RelayFeatureFlags.ENABLE_VARIABLE_CONNECTION_KEY && dynamicKeyArg.value.kind === 'Variable') {
|
5401 | dynamicKey = dynamicKeyArg.value;
|
5402 | } else {
|
5403 | throw createUserError("Unsupported 'dynamicKey_UNSTABLE' argument to @".concat(connectionDirective.name, ". This argument is only valid when the feature flag is enabled and ") + 'the variable must be a variable', [connectionDirective.loc]);
|
5404 | }
|
5405 | }
|
5406 |
|
5407 | return {
|
5408 | handler: handler,
|
5409 | key: key,
|
5410 | dynamicKey: dynamicKey,
|
5411 | filters: filters,
|
5412 | stream: stream
|
5413 | };
|
5414 | }
|
5415 |
|
5416 | function buildConnectionMetadata(field, path, stream) {
|
5417 | var pathHasPlural = path.includes(null);
|
5418 | var firstArg = findArg(field, FIRST);
|
5419 | var lastArg = findArg(field, LAST);
|
5420 | var direction = null;
|
5421 | var countArg = null;
|
5422 | var cursorArg = null;
|
5423 |
|
5424 | if (firstArg && !lastArg) {
|
5425 | direction = 'forward';
|
5426 | countArg = firstArg;
|
5427 | cursorArg = findArg(field, AFTER);
|
5428 | } else if (lastArg && !firstArg) {
|
5429 | direction = 'backward';
|
5430 | countArg = lastArg;
|
5431 | cursorArg = findArg(field, BEFORE);
|
5432 | } else if (lastArg && firstArg) {
|
5433 | direction = 'bidirectional'; // TODO(T26511885) Maybe add connection metadata to this case
|
5434 | }
|
5435 |
|
5436 | var countVariable = countArg && countArg.value.kind === 'Variable' ? countArg.value.variableName : null;
|
5437 | var cursorVariable = cursorArg && cursorArg.value.kind === 'Variable' ? cursorArg.value.variableName : null;
|
5438 |
|
5439 | if (stream) {
|
5440 | return {
|
5441 | count: countVariable,
|
5442 | cursor: cursorVariable,
|
5443 | direction: direction,
|
5444 | path: pathHasPlural ? null : path,
|
5445 | stream: true
|
5446 | };
|
5447 | }
|
5448 |
|
5449 | return {
|
5450 | count: countVariable,
|
5451 | cursor: cursorVariable,
|
5452 | direction: direction,
|
5453 | path: pathHasPlural ? null : path
|
5454 | };
|
5455 | }
|
5456 | /**
|
5457 | * @internal
|
5458 | *
|
5459 | * Transforms the selections on a connection field, generating fields necessary
|
5460 | * for pagination (edges.cursor, pageInfo, etc) and adding/merging them with
|
5461 | * existing selections.
|
5462 | */
|
5463 |
|
5464 |
|
5465 | function transformConnectionSelections(context, field, nullableType, direction, connectionArguments, directiveLocation, documentName) {
|
5466 | var schema = context.getSchema();
|
5467 | var derivedFieldLocation = {
|
5468 | kind: 'Derived',
|
5469 | source: field.loc
|
5470 | };
|
5471 | var derivedDirectiveLocation = {
|
5472 | kind: 'Derived',
|
5473 | source: directiveLocation
|
5474 | };
|
5475 |
|
5476 | var _ConnectionInterface$ = ConnectionInterface.get(),
|
5477 | CURSOR = _ConnectionInterface$.CURSOR,
|
5478 | EDGES = _ConnectionInterface$.EDGES,
|
5479 | END_CURSOR = _ConnectionInterface$.END_CURSOR,
|
5480 | HAS_NEXT_PAGE = _ConnectionInterface$.HAS_NEXT_PAGE,
|
5481 | HAS_PREV_PAGE = _ConnectionInterface$.HAS_PREV_PAGE,
|
5482 | NODE = _ConnectionInterface$.NODE,
|
5483 | PAGE_INFO = _ConnectionInterface$.PAGE_INFO,
|
5484 | START_CURSOR = _ConnectionInterface$.START_CURSOR; // Find existing edges/pageInfo selections
|
5485 |
|
5486 |
|
5487 | var edgesSelection;
|
5488 | var pageInfoSelection;
|
5489 | field.selections.forEach(function (selection) {
|
5490 | if (selection.kind === 'LinkedField') {
|
5491 | if (selection.name === EDGES) {
|
5492 | if (edgesSelection != null) {
|
5493 | throw createCompilerError("ConnectionTransform: Unexpected duplicate field '".concat(EDGES, "'."), [edgesSelection.loc, selection.loc]);
|
5494 | }
|
5495 |
|
5496 | edgesSelection = selection;
|
5497 | return;
|
5498 | } else if (selection.name === PAGE_INFO) {
|
5499 | if (pageInfoSelection != null) {
|
5500 | throw createCompilerError("ConnectionTransform: Unexpected duplicate field '".concat(PAGE_INFO, "'."), [pageInfoSelection.loc, selection.loc]);
|
5501 | }
|
5502 |
|
5503 | pageInfoSelection = selection;
|
5504 | return;
|
5505 | }
|
5506 | }
|
5507 | }); // If streaming is enabled, construct directives to apply to the edges/
|
5508 | // pageInfo fields
|
5509 |
|
5510 | var streamDirective;
|
5511 | var stream = connectionArguments.stream;
|
5512 |
|
5513 | if (stream != null) {
|
5514 | streamDirective = {
|
5515 | args: [stream["if"], stream.initialCount, {
|
5516 | kind: 'Argument',
|
5517 | loc: derivedDirectiveLocation,
|
5518 | name: 'label',
|
5519 | type: SchemaUtils.getNullableStringInput(schema),
|
5520 | value: {
|
5521 | kind: 'Literal',
|
5522 | loc: derivedDirectiveLocation,
|
5523 | value: stream.label
|
5524 | }
|
5525 | }].filter(Boolean),
|
5526 | kind: 'Directive',
|
5527 | loc: derivedDirectiveLocation,
|
5528 | name: 'stream'
|
5529 | };
|
5530 | } // For backwards compatibility with earlier versions of this transform,
|
5531 | // edges/pageInfo have to be generated as non-aliased fields (since product
|
5532 | // code may be accessing the non-aliased response keys). But for streaming
|
5533 | // mode we need to generate @stream/@defer directives on these fields *and*
|
5534 | // we prefer to avoid generating extra selections (we want one payload per
|
5535 | // item, not two as could happen with separate @stream directives on the
|
5536 | // aliased and non-aliased edges fields). So we keep things simple by
|
5537 | // disallowing aliases on edges/pageInfo in streaming mode.
|
5538 |
|
5539 |
|
5540 | if (edgesSelection && edgesSelection.alias !== edgesSelection.name) {
|
5541 | if (stream) {
|
5542 | throw createUserError("@stream_connection does not support aliasing the '".concat(EDGES, "' field."), [edgesSelection.loc]);
|
5543 | }
|
5544 |
|
5545 | edgesSelection = null;
|
5546 | }
|
5547 |
|
5548 | if (pageInfoSelection && pageInfoSelection.alias !== pageInfoSelection.name) {
|
5549 | if (stream) {
|
5550 | throw createUserError("@stream_connection does not support aliasing the '".concat(PAGE_INFO, "' field."), [pageInfoSelection.loc]);
|
5551 | }
|
5552 |
|
5553 | pageInfoSelection = null;
|
5554 | } // Separately create transformed versions of edges/pageInfo so that we can
|
5555 | // later replace the originals at the same point within the selection array
|
5556 |
|
5557 |
|
5558 | var transformedEdgesSelection = edgesSelection;
|
5559 | var transformedPageInfoSelection = pageInfoSelection;
|
5560 | var edgesType = schema.getFieldConfig(schema.expectField(nullableType, EDGES)).type;
|
5561 | var pageInfoType = schema.getFieldConfig(schema.expectField(nullableType, PAGE_INFO)).type;
|
5562 |
|
5563 | if (transformedEdgesSelection == null) {
|
5564 | transformedEdgesSelection = {
|
5565 | alias: EDGES,
|
5566 | args: [],
|
5567 | connection: false,
|
5568 | directives: [],
|
5569 | handles: null,
|
5570 | kind: 'LinkedField',
|
5571 | loc: derivedFieldLocation,
|
5572 | metadata: null,
|
5573 | name: EDGES,
|
5574 | selections: [],
|
5575 | type: schema.assertLinkedFieldType(edgesType)
|
5576 | };
|
5577 | }
|
5578 |
|
5579 | if (transformedPageInfoSelection == null) {
|
5580 | transformedPageInfoSelection = {
|
5581 | alias: PAGE_INFO,
|
5582 | args: [],
|
5583 | connection: false,
|
5584 | directives: [],
|
5585 | handles: null,
|
5586 | kind: 'LinkedField',
|
5587 | loc: derivedFieldLocation,
|
5588 | metadata: null,
|
5589 | name: PAGE_INFO,
|
5590 | selections: [],
|
5591 | type: schema.assertLinkedFieldType(pageInfoType)
|
5592 | };
|
5593 | } // Generate (additional) fields on pageInfo and add to the transformed
|
5594 | // pageInfo field
|
5595 |
|
5596 |
|
5597 | var pageInfoRawType = schema.getRawType(pageInfoType);
|
5598 | var pageInfoText;
|
5599 |
|
5600 | if (direction === 'forward') {
|
5601 | pageInfoText = "fragment PageInfo on ".concat(schema.getTypeString(pageInfoRawType), " {\n ").concat(END_CURSOR, "\n ").concat(HAS_NEXT_PAGE, "\n }");
|
5602 | } else if (direction === 'backward') {
|
5603 | pageInfoText = "fragment PageInfo on ".concat(schema.getTypeString(pageInfoRawType), " {\n ").concat(HAS_PREV_PAGE, "\n ").concat(START_CURSOR, "\n }");
|
5604 | } else {
|
5605 | pageInfoText = "fragment PageInfo on ".concat(schema.getTypeString(pageInfoRawType), " {\n ").concat(END_CURSOR, "\n ").concat(HAS_NEXT_PAGE, "\n ").concat(HAS_PREV_PAGE, "\n ").concat(START_CURSOR, "\n }");
|
5606 | }
|
5607 |
|
5608 | var pageInfoAst = parse(pageInfoText);
|
5609 | var pageInfoFragment = RelayParser.transform(schema, [pageInfoAst.definitions[0]])[0];
|
5610 |
|
5611 | if (transformedPageInfoSelection.kind !== 'LinkedField') {
|
5612 | throw createCompilerError('ConnectionTransform: Expected generated pageInfo selection to be ' + 'a LinkedField', [field.loc]);
|
5613 | }
|
5614 |
|
5615 | transformedPageInfoSelection = (0, _objectSpread2["default"])({}, transformedPageInfoSelection, {
|
5616 | selections: [].concat((0, _toConsumableArray2["default"])(transformedPageInfoSelection.selections), [{
|
5617 | directives: [],
|
5618 | kind: 'InlineFragment',
|
5619 | loc: derivedFieldLocation,
|
5620 | metadata: null,
|
5621 | selections: pageInfoFragment.selections,
|
5622 | typeCondition: pageInfoFragment.type
|
5623 | }])
|
5624 | }); // When streaming the pageInfo field has to be deferred
|
5625 |
|
5626 | if (stream != null) {
|
5627 | var _ref6, _stream$if;
|
5628 |
|
5629 | transformedPageInfoSelection = {
|
5630 | "if": (_ref6 = (_stream$if = stream["if"]) === null || _stream$if === void 0 ? void 0 : _stream$if.value) !== null && _ref6 !== void 0 ? _ref6 : null,
|
5631 | label: "".concat(documentName, "$defer$").concat(stream.label, "$").concat(PAGE_INFO),
|
5632 | kind: 'Defer',
|
5633 | loc: derivedFieldLocation,
|
5634 | metadata: {
|
5635 | fragmentTypeCondition: nullableType
|
5636 | },
|
5637 | selections: [transformedPageInfoSelection]
|
5638 | };
|
5639 | } // Generate additional fields on edges and append to the transformed edges
|
5640 | // selection
|
5641 |
|
5642 |
|
5643 | var edgeText = "\n fragment Edges on ".concat(schema.getTypeString(schema.getRawType(edgesType)), " {\n ").concat(CURSOR, "\n ").concat(NODE, " {\n __typename # rely on GenerateRequisiteFieldTransform to add \"id\"\n }\n }\n ");
|
5644 | var edgeAst = parse(edgeText);
|
5645 | var edgeFragment = RelayParser.transform(schema, [edgeAst.definitions[0]])[0]; // When streaming the edges field needs @stream
|
5646 |
|
5647 | transformedEdgesSelection = (0, _objectSpread2["default"])({}, transformedEdgesSelection, {
|
5648 | directives: streamDirective != null ? [].concat((0, _toConsumableArray2["default"])(transformedEdgesSelection.directives), [streamDirective]) : transformedEdgesSelection.directives,
|
5649 | selections: [].concat((0, _toConsumableArray2["default"])(transformedEdgesSelection.selections), [{
|
5650 | directives: [],
|
5651 | kind: 'InlineFragment',
|
5652 | loc: derivedFieldLocation,
|
5653 | metadata: null,
|
5654 | selections: edgeFragment.selections,
|
5655 | typeCondition: edgeFragment.type
|
5656 | }])
|
5657 | }); // Copy the original selections, replacing edges/pageInfo (if present)
|
5658 | // with the generated locations. This is to maintain the original field
|
5659 | // ordering.
|
5660 |
|
5661 | var selections = field.selections.map(function (selection) {
|
5662 | if (transformedEdgesSelection != null && edgesSelection != null && selection === edgesSelection) {
|
5663 | return transformedEdgesSelection;
|
5664 | } else if (transformedPageInfoSelection != null && pageInfoSelection != null && selection === pageInfoSelection) {
|
5665 | return transformedPageInfoSelection;
|
5666 | } else {
|
5667 | return selection;
|
5668 | }
|
5669 | }); // If edges/pageInfo were missing, append the generated versions instead.
|
5670 |
|
5671 | if (edgesSelection == null && transformedEdgesSelection != null) {
|
5672 | selections.push(transformedEdgesSelection);
|
5673 | }
|
5674 |
|
5675 | if (pageInfoSelection == null && transformedPageInfoSelection != null) {
|
5676 | selections.push(transformedPageInfoSelection);
|
5677 | }
|
5678 |
|
5679 | return selections;
|
5680 | }
|
5681 |
|
5682 | function findArg(field, argName) {
|
5683 | return field.args && field.args.find(function (arg) {
|
5684 | return arg.name === argName;
|
5685 | });
|
5686 | }
|
5687 | /**
|
5688 | * @internal
|
5689 | *
|
5690 | * Validates that the selection is a valid connection:
|
5691 | * - Specifies a first or last argument to prevent accidental, unconstrained
|
5692 | * data access.
|
5693 | * - Has an `edges` selection, otherwise there is nothing to paginate.
|
5694 | *
|
5695 | * TODO: This implementation requires the edges field to be a direct selection
|
5696 | * and not contained within an inline fragment or fragment spread. It's
|
5697 | * technically possible to remove this restriction if this pattern becomes
|
5698 | * common/necessary.
|
5699 | */
|
5700 |
|
5701 |
|
5702 | function validateConnectionSelection(field) {
|
5703 | var _ConnectionInterface$2 = ConnectionInterface.get(),
|
5704 | EDGES = _ConnectionInterface$2.EDGES;
|
5705 |
|
5706 | if (!findArg(field, FIRST) && !findArg(field, LAST)) {
|
5707 | throw createUserError("Expected field '".concat(field.name, "' to have a '").concat(FIRST, "' or '").concat(LAST, "' ") + 'argument.', [field.loc]);
|
5708 | }
|
5709 |
|
5710 | if (!field.selections.some(function (selection) {
|
5711 | return selection.kind === 'LinkedField' && selection.name === EDGES;
|
5712 | })) {
|
5713 | throw createUserError("Expected field '".concat(field.name, "' to have an '").concat(EDGES, "' selection."), [field.loc]);
|
5714 | }
|
5715 | }
|
5716 | /**
|
5717 | * @internal
|
5718 | *
|
5719 | * Validates that the type satisfies the Connection specification:
|
5720 | * - The type has an edges field, and edges have scalar `cursor` and object
|
5721 | * `node` fields.
|
5722 | * - The type has a page info field which is an object with the correct
|
5723 | * subfields.
|
5724 | */
|
5725 |
|
5726 |
|
5727 | function validateConnectionType(schema, field, nullableType, connectionDirective) {
|
5728 | var directiveName = connectionDirective.name;
|
5729 |
|
5730 | var _ConnectionInterface$3 = ConnectionInterface.get(),
|
5731 | CURSOR = _ConnectionInterface$3.CURSOR,
|
5732 | EDGES = _ConnectionInterface$3.EDGES,
|
5733 | END_CURSOR = _ConnectionInterface$3.END_CURSOR,
|
5734 | HAS_NEXT_PAGE = _ConnectionInterface$3.HAS_NEXT_PAGE,
|
5735 | HAS_PREV_PAGE = _ConnectionInterface$3.HAS_PREV_PAGE,
|
5736 | NODE = _ConnectionInterface$3.NODE,
|
5737 | PAGE_INFO = _ConnectionInterface$3.PAGE_INFO,
|
5738 | START_CURSOR = _ConnectionInterface$3.START_CURSOR;
|
5739 |
|
5740 | var typeName = schema.getTypeString(nullableType);
|
5741 |
|
5742 | if (!schema.hasField(nullableType, EDGES)) {
|
5743 | throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, "' field"), [field.loc]);
|
5744 | }
|
5745 |
|
5746 | var edges = schema.getFieldConfig(schema.expectField(nullableType, EDGES));
|
5747 | var edgesType = schema.getNullableType(edges.type);
|
5748 |
|
5749 | if (!schema.isList(edgesType)) {
|
5750 | throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, "' field that returns ") + 'a list of objects.', [field.loc]);
|
5751 | }
|
5752 |
|
5753 | var edgeType = schema.getNullableType(schema.getListItemType(edgesType));
|
5754 |
|
5755 | if (!schema.isObject(edgeType) && !schema.isInterface(edgeType)) {
|
5756 | throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, "' field that returns ") + 'a list of objects.', [field.loc]);
|
5757 | }
|
5758 |
|
5759 | edgeType = schema.assertCompositeType(edgeType);
|
5760 |
|
5761 | if (!schema.hasField(edgeType, NODE)) {
|
5762 | throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, " { ").concat(NODE, " }' field ") + 'that returns an object, interface, or union.', [field.loc]);
|
5763 | }
|
5764 |
|
5765 | var node = schema.getFieldConfig(schema.expectField(edgeType, NODE));
|
5766 | var nodeType = schema.getNullableType(node.type);
|
5767 |
|
5768 | if (!(schema.isAbstractType(nodeType) || schema.isObject(nodeType))) {
|
5769 | throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, " { ").concat(NODE, " }' field ") + 'that returns an object, interface, or union.', [field.loc]);
|
5770 | }
|
5771 |
|
5772 | if (!schema.hasField(edgeType, CURSOR)) {
|
5773 | throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, " { ").concat(CURSOR, " }' field ") + 'that returns a scalar value.', [field.loc]);
|
5774 | }
|
5775 |
|
5776 | var cursor = schema.getFieldConfig(schema.expectField(edgeType, CURSOR));
|
5777 |
|
5778 | if (!schema.isScalar(schema.getNullableType(cursor.type))) {
|
5779 | throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have an '").concat(EDGES, " { ").concat(CURSOR, " }' field ") + 'that returns a scalar value.', [field.loc]);
|
5780 | }
|
5781 |
|
5782 | if (!schema.hasField(nullableType, PAGE_INFO)) {
|
5783 | throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have a '").concat(PAGE_INFO, "' field that returns ") + 'an object.', [field.loc]);
|
5784 | }
|
5785 |
|
5786 | var pageInfo = schema.getFieldConfig(schema.expectField(nullableType, PAGE_INFO));
|
5787 | var pageInfoType = schema.getNullableType(pageInfo.type);
|
5788 |
|
5789 | if (!schema.isObject(pageInfoType)) {
|
5790 | throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected the ") + "field type '".concat(typeName, "' to have a '").concat(PAGE_INFO, "' field that ") + 'returns an object.', [field.loc]);
|
5791 | }
|
5792 |
|
5793 | [END_CURSOR, HAS_NEXT_PAGE, HAS_PREV_PAGE, START_CURSOR].forEach(function (fieldName) {
|
5794 | var pageInfoField = schema.getFieldConfig(schema.expectField(schema.assertObjectType(pageInfoType), fieldName));
|
5795 |
|
5796 | if (!schema.isScalar(schema.getNullableType(pageInfoField.type))) {
|
5797 | throw createUserError("@".concat(directiveName, " used on invalid field '").concat(field.name, "'. Expected ") + "the field type '".concat(typeName, "' to have a '").concat(PAGE_INFO, " { ").concat(fieldName, " }' ") + 'field returns a scalar.', [field.loc]);
|
5798 | }
|
5799 | });
|
5800 | }
|
5801 |
|
5802 | module.exports = {
|
5803 | buildConnectionMetadata: buildConnectionMetadata,
|
5804 | CONNECTION: CONNECTION,
|
5805 | SCHEMA_EXTENSION: SCHEMA_EXTENSION,
|
5806 | transform: connectionTransform
|
5807 | };
|
5808 |
|
5809 | /***/ }),
|
5810 | /* 36 */
|
5811 | /***/ (function(module, exports, __webpack_require__) {
|
5812 |
|
5813 | "use strict";
|
5814 | /**
|
5815 | * Copyright (c) Facebook, Inc. and its affiliates.
|
5816 | *
|
5817 | * This source code is licensed under the MIT license found in the
|
5818 | * LICENSE file in the root directory of this source tree.
|
5819 | *
|
5820 | * @format
|
5821 | *
|
5822 | */
|
5823 |
|
5824 |
|
5825 | var _interopRequireDefault = __webpack_require__(0);
|
5826 |
|
5827 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
5828 |
|
5829 | var GraphQLIRTransformer = __webpack_require__(3);
|
5830 |
|
5831 | var areEqual = __webpack_require__(81);
|
5832 |
|
5833 | var getIdentifierForSelection = __webpack_require__(37);
|
5834 |
|
5835 | var _require = __webpack_require__(1),
|
5836 | createCompilerError = _require.createCompilerError,
|
5837 | createUserError = _require.createUserError;
|
5838 |
|
5839 | /**
|
5840 | * Transform that flattens inline fragments, fragment spreads, and conditionals.
|
5841 | *
|
5842 | * Inline fragments are inlined (replaced with their selections) when:
|
5843 | * - The fragment type matches the type of its parent.
|
5844 | * - The fragment has an abstract type and the `flattenAbstractTypes` option has
|
5845 | * been set.
|
5846 | */
|
5847 | function flattenTransformImpl(context, options) {
|
5848 | var state = {
|
5849 | flattenAbstractTypes: !!(options && options.flattenAbstractTypes),
|
5850 | parentType: null
|
5851 | };
|
5852 | var visitorFn = memoizedFlattenSelection(new Map());
|
5853 | return GraphQLIRTransformer.transform(context, {
|
5854 | Condition: visitorFn,
|
5855 | Connection: visitorFn,
|
5856 | ConnectionField: visitorFn,
|
5857 | Defer: visitorFn,
|
5858 | Fragment: visitorFn,
|
5859 | InlineFragment: visitorFn,
|
5860 | InlineDataFragmentSpread: visitorFn,
|
5861 | LinkedField: visitorFn,
|
5862 | Root: visitorFn,
|
5863 | SplitOperation: visitorFn
|
5864 | }, function () {
|
5865 | return state;
|
5866 | });
|
5867 | }
|
5868 |
|
5869 | function memoizedFlattenSelection(cache) {
|
5870 | return function flattenSelectionsFn(node, state) {
|
5871 | var context = this.getContext();
|
5872 | var nodeCache = cache.get(node);
|
5873 |
|
5874 | if (nodeCache == null) {
|
5875 | nodeCache = new Map();
|
5876 | cache.set(node, nodeCache);
|
5877 | } // Determine the current type.
|
5878 |
|
5879 |
|
5880 | var parentType = state.parentType;
|
5881 | var result = nodeCache.get(parentType);
|
5882 |
|
5883 | if (result != null) {
|
5884 | return result;
|
5885 | }
|
5886 |
|
5887 | var type = node.kind === 'LinkedField' || node.kind === 'Fragment' || node.kind === 'Root' || node.kind === 'SplitOperation' ? node.type : node.kind === 'InlineFragment' ? node.typeCondition : parentType;
|
5888 |
|
5889 | if (type == null) {
|
5890 | throw createCompilerError('FlattenTransform: Expected a parent type.', [node.loc]);
|
5891 | } // Flatten the selections in this node, creating a new node with flattened
|
5892 | // selections if possible, then deeply traverse the flattened node, while
|
5893 | // keeping track of the parent type.
|
5894 |
|
5895 |
|
5896 | var nextSelections = new Map();
|
5897 | var hasFlattened = flattenSelectionsInto(context.getSchema(), nextSelections, node, state, type);
|
5898 | var flattenedNode = hasFlattened ? (0, _objectSpread2["default"])({}, node, {
|
5899 | selections: Array.from(nextSelections.values())
|
5900 | }) : node;
|
5901 | state.parentType = type;
|
5902 | var deeplyFlattenedNode = this.traverse(flattenedNode, state);
|
5903 | state.parentType = parentType;
|
5904 | nodeCache.set(parentType, deeplyFlattenedNode);
|
5905 | return deeplyFlattenedNode;
|
5906 | };
|
5907 | }
|
5908 | /**
|
5909 | * @private
|
5910 | */
|
5911 |
|
5912 |
|
5913 | function flattenSelectionsInto(schema, flattenedSelections, node, state, type) {
|
5914 | var hasFlattened = false;
|
5915 | node.selections.forEach(function (selection) {
|
5916 | if (selection.kind === 'InlineFragment' && shouldFlattenInlineFragment(schema, selection, state, type)) {
|
5917 | hasFlattened = true;
|
5918 | flattenSelectionsInto(schema, flattenedSelections, selection, state, type);
|
5919 | return;
|
5920 | }
|
5921 |
|
5922 | var nodeIdentifier = getIdentifierForSelection(schema, selection);
|
5923 | var flattenedSelection = flattenedSelections.get(nodeIdentifier); // If this selection hasn't been seen before, keep track of it.
|
5924 |
|
5925 | if (!flattenedSelection) {
|
5926 | flattenedSelections.set(nodeIdentifier, selection);
|
5927 | return;
|
5928 | } // Otherwise a similar selection exists which should be merged.
|
5929 |
|
5930 |
|
5931 | hasFlattened = true;
|
5932 |
|
5933 | if (flattenedSelection.kind === 'InlineFragment') {
|
5934 | if (selection.kind !== 'InlineFragment') {
|
5935 | throw createCompilerError("FlattenTransform: Expected an InlineFragment, got a '".concat(selection.kind, "'"), [selection.loc]);
|
5936 | }
|
5937 |
|
5938 | flattenedSelections.set(nodeIdentifier, (0, _objectSpread2["default"])({}, flattenedSelection, {
|
5939 | selections: mergeSelections(schema, flattenedSelection, selection, state, selection.typeCondition)
|
5940 | }));
|
5941 | } else if (flattenedSelection.kind === 'Condition') {
|
5942 | if (selection.kind !== 'Condition') {
|
5943 | throw createCompilerError("FlattenTransform: Expected a Condition, got a '".concat(selection.kind, "'"), [selection.loc]);
|
5944 | }
|
5945 |
|
5946 | flattenedSelections.set(nodeIdentifier, (0, _objectSpread2["default"])({}, flattenedSelection, {
|
5947 | selections: mergeSelections(schema, flattenedSelection, selection, state, type)
|
5948 | }));
|
5949 | } else if (flattenedSelection.kind === 'ClientExtension') {
|
5950 | if (selection.kind !== 'ClientExtension') {
|
5951 | throw createCompilerError("FlattenTransform: Expected a ClientExtension, got a '".concat(selection.kind, "'"), [selection.loc]);
|
5952 | }
|
5953 |
|
5954 | flattenedSelections.set(nodeIdentifier, (0, _objectSpread2["default"])({}, flattenedSelection, {
|
5955 | selections: mergeSelections(schema, flattenedSelection, selection, state, type)
|
5956 | }));
|
5957 | } else if (flattenedSelection.kind === 'FragmentSpread') {// Ignore duplicate fragment spreads.
|
5958 | } else if (flattenedSelection.kind === 'ModuleImport') {
|
5959 | if (selection.kind !== 'ModuleImport') {
|
5960 | throw createCompilerError("FlattenTransform: Expected a ModuleImport, got a '".concat(selection.kind, "'"), [selection.loc]);
|
5961 | }
|
5962 |
|
5963 | if (selection.name !== flattenedSelection.name || selection.module !== flattenedSelection.module || selection.documentName !== flattenedSelection.documentName) {
|
5964 | throw createUserError('Found conflicting @module selections: use a unique alias on the ' + 'parent fields.', [selection.loc, flattenedSelection.loc]);
|
5965 | }
|
5966 |
|
5967 | flattenedSelections.set(nodeIdentifier, (0, _objectSpread2["default"])({}, flattenedSelection, {
|
5968 | selections: mergeSelections(schema, flattenedSelection, selection, state, type)
|
5969 | }));
|
5970 | } else if (flattenedSelection.kind === 'Defer') {
|
5971 | if (selection.kind !== 'Defer') {
|
5972 | throw createCompilerError("FlattenTransform: Expected a Defer, got a '".concat(selection.kind, "'"), [selection.loc]);
|
5973 | }
|
5974 |
|
5975 | flattenedSelections.set(nodeIdentifier, (0, _objectSpread2["default"])({
|
5976 | kind: 'Defer'
|
5977 | }, flattenedSelection, {
|
5978 | selections: mergeSelections(schema, flattenedSelection, selection, state, type)
|
5979 | }));
|
5980 | } else if (flattenedSelection.kind === 'Stream') {
|
5981 | if (selection.kind !== 'Stream') {
|
5982 | throw createCompilerError("FlattenTransform: Expected a Stream, got a '".concat(selection.kind, "'"), [selection.loc]);
|
5983 | }
|
5984 |
|
5985 | flattenedSelections.set(nodeIdentifier, (0, _objectSpread2["default"])({
|
5986 | kind: 'Stream'
|
5987 | }, flattenedSelection, {
|
5988 | selections: mergeSelections(schema, flattenedSelection, selection, state, type)
|
5989 | }));
|
5990 | } else if (flattenedSelection.kind === 'LinkedField') {
|
5991 | if (selection.kind !== 'LinkedField') {
|
5992 | throw createCompilerError("FlattenTransform: Expected a LinkedField, got a '".concat(selection.kind, "'"), [selection.loc]);
|
5993 | }
|
5994 |
|
5995 | assertUniqueArgsForAlias(selection, flattenedSelection); // NOTE: not using object spread here as this code is pretty hot
|
5996 |
|
5997 | flattenedSelections.set(nodeIdentifier, {
|
5998 | kind: 'LinkedField',
|
5999 | alias: flattenedSelection.alias,
|
6000 | args: flattenedSelection.args,
|
6001 | connection: flattenedSelection.connection || selection.connection,
|
6002 | directives: flattenedSelection.directives,
|
6003 | handles: mergeHandles(flattenedSelection, selection),
|
6004 | loc: flattenedSelection.loc,
|
6005 | metadata: flattenedSelection.metadata,
|
6006 | name: flattenedSelection.name,
|
6007 | selections: mergeSelections(schema, flattenedSelection, selection, state, selection.type),
|
6008 | type: flattenedSelection.type
|
6009 | });
|
6010 | } else if (flattenedSelection.kind === 'ScalarField') {
|
6011 | if (selection.kind !== 'ScalarField') {
|
6012 | throw createCompilerError("FlattenTransform: Expected a ScalarField, got a '".concat(selection.kind, "'"), [selection.loc]);
|
6013 | }
|
6014 |
|
6015 | assertUniqueArgsForAlias(selection, flattenedSelection);
|
6016 |
|
6017 | if (selection.handles && selection.handles.length > 0) {
|
6018 | flattenedSelections.set(nodeIdentifier, (0, _objectSpread2["default"])({
|
6019 | kind: 'ScalarField'
|
6020 | }, flattenedSelection, {
|
6021 | handles: mergeHandles(selection, flattenedSelection)
|
6022 | }));
|
6023 | }
|
6024 | } else if (flattenedSelection.kind === 'ConnectionField') {
|
6025 | if (selection.kind !== 'ConnectionField') {
|
6026 | throw createCompilerError("FlattenTransform: Expected a ConnectionField, got a '".concat(selection.kind, "'"), [selection.loc]);
|
6027 | }
|
6028 |
|
6029 | assertUniqueArgsForAlias(selection, flattenedSelection); // NOTE: not using object spread here as this code is pretty hot
|
6030 |
|
6031 | flattenedSelections.set(nodeIdentifier, {
|
6032 | kind: 'ConnectionField',
|
6033 | alias: flattenedSelection.alias,
|
6034 | args: flattenedSelection.args,
|
6035 | directives: flattenedSelection.directives,
|
6036 | loc: flattenedSelection.loc,
|
6037 | metadata: flattenedSelection.metadata,
|
6038 | name: flattenedSelection.name,
|
6039 | selections: mergeSelections(schema, flattenedSelection, selection, state, selection.type),
|
6040 | type: flattenedSelection.type
|
6041 | });
|
6042 | } else if (flattenedSelection.kind === 'InlineDataFragmentSpread') {
|
6043 | throw createCompilerError('FlattenTransform: did not expect an InlineDataFragmentSpread node. ' + 'Only expecting InlineDataFragmentSpread in reader ASTs and this ' + 'transform to run only on normalization ASTs.', [selection.loc]);
|
6044 | } else if (flattenedSelection.kind === 'Connection') {
|
6045 | if (selection.kind !== 'Connection') {
|
6046 | throw createCompilerError("FlattenTransform: Expected a Connection, got a '".concat(selection.kind, "'"), [selection.loc]);
|
6047 | }
|
6048 |
|
6049 | flattenedSelections.set(nodeIdentifier, (0, _objectSpread2["default"])({
|
6050 | kind: 'Connection'
|
6051 | }, flattenedSelection, {
|
6052 | selections: mergeSelections(schema, flattenedSelection, selection, state, selection.type)
|
6053 | }));
|
6054 | } else {
|
6055 | flattenedSelection.kind;
|
6056 | throw createCompilerError("FlattenTransform: Unknown kind '".concat(flattenedSelection.kind, "'"));
|
6057 | }
|
6058 | });
|
6059 | return hasFlattened;
|
6060 | }
|
6061 | /**
|
6062 | * @private
|
6063 | */
|
6064 |
|
6065 |
|
6066 | function mergeSelections(schema, nodeA, nodeB, state, type) {
|
6067 | var flattenedSelections = new Map();
|
6068 | flattenSelectionsInto(schema, flattenedSelections, nodeA, state, type);
|
6069 | flattenSelectionsInto(schema, flattenedSelections, nodeB, state, type);
|
6070 | return Array.from(flattenedSelections.values());
|
6071 | }
|
6072 | /**
|
6073 | * @private
|
6074 | * TODO(T19327202) This is redundant with OverlappingFieldsCanBeMergedRule once
|
6075 | * it can be enabled.
|
6076 | */
|
6077 |
|
6078 |
|
6079 | function assertUniqueArgsForAlias(field, otherField) {
|
6080 | if (!areEqualFields(field, otherField)) {
|
6081 | throw createUserError('Expected all fields on the same parent with the name or alias ' + "'".concat(field.alias, "' to have the same name and arguments."), [field.loc, otherField.loc]);
|
6082 | }
|
6083 | }
|
6084 | /**
|
6085 | * @private
|
6086 | */
|
6087 |
|
6088 |
|
6089 | function shouldFlattenInlineFragment(schema, fragment, state, type) {
|
6090 | return schema.areEqualTypes(fragment.typeCondition, schema.getRawType(type)) || state.flattenAbstractTypes && schema.isAbstractType(fragment.typeCondition);
|
6091 | }
|
6092 | /**
|
6093 | * @private
|
6094 | *
|
6095 | * Verify that two fields are equal in all properties other than their
|
6096 | * selections.
|
6097 | */
|
6098 |
|
6099 |
|
6100 | function areEqualFields(thisField, thatField) {
|
6101 | return thisField.kind === thatField.kind && thisField.name === thatField.name && thisField.alias === thatField.alias && areEqualArgs(thisField.args, thatField.args);
|
6102 | }
|
6103 | /**
|
6104 | * Verify that two sets of arguments are equivalent - same argument names
|
6105 | * and values. Notably this ignores the types of arguments and values, which
|
6106 | * may not always be inferred identically.
|
6107 | */
|
6108 |
|
6109 |
|
6110 | function areEqualArgs(thisArgs, thatArgs) {
|
6111 | return thisArgs.length === thatArgs.length && thisArgs.every(function (thisArg, index) {
|
6112 | var thatArg = thatArgs[index];
|
6113 | return thisArg.name === thatArg.name && thisArg.value.kind === thatArg.value.kind && thisArg.value.variableName === thatArg.value.variableName && areEqual(thisArg.value.value, thatArg.value.value);
|
6114 | });
|
6115 | }
|
6116 | /**
|
6117 | * @private
|
6118 | */
|
6119 |
|
6120 |
|
6121 | function mergeHandles(nodeA, nodeB) {
|
6122 | if (!nodeA.handles) {
|
6123 | return nodeB.handles;
|
6124 | }
|
6125 |
|
6126 | if (!nodeB.handles) {
|
6127 | return nodeA.handles;
|
6128 | }
|
6129 |
|
6130 | var uniqueItems = new Map();
|
6131 | nodeA.handles.concat(nodeB.handles).forEach(function (item) {
|
6132 | return uniqueItems.set(item.name + item.key, item);
|
6133 | });
|
6134 | return Array.from(uniqueItems.values());
|
6135 | }
|
6136 |
|
6137 | function transformWithOptions(options) {
|
6138 | return function flattenTransform(context) {
|
6139 | return flattenTransformImpl(context, options);
|
6140 | };
|
6141 | }
|
6142 |
|
6143 | module.exports = {
|
6144 | transformWithOptions: transformWithOptions
|
6145 | };
|
6146 |
|
6147 | /***/ }),
|
6148 | /* 37 */
|
6149 | /***/ (function(module, exports, __webpack_require__) {
|
6150 |
|
6151 | "use strict";
|
6152 | /**
|
6153 | * Copyright (c) Facebook, Inc. and its affiliates.
|
6154 | *
|
6155 | * This source code is licensed under the MIT license found in the
|
6156 | * LICENSE file in the root directory of this source tree.
|
6157 | *
|
6158 | *
|
6159 | * @format
|
6160 | */
|
6161 |
|
6162 |
|
6163 | var invariant = __webpack_require__(4);
|
6164 |
|
6165 | var _require = __webpack_require__(31),
|
6166 | printArguments = _require.printArguments,
|
6167 | printDirectives = _require.printDirectives;
|
6168 |
|
6169 | /**
|
6170 | * Generates an identifier that is unique to a given selection: the alias for
|
6171 | * fields, the type for inline fragments, and a summary of the condition
|
6172 | * variable and passing value for conditions.
|
6173 | */
|
6174 | function getIdentifierForSelection(schema, node) {
|
6175 | if (node.kind === 'LinkedField' || node.kind === 'ScalarField' || node.kind === 'ConnectionField') {
|
6176 | return 'Field: ' + node.directives.length === 0 ? node.alias : node.alias + printDirectives(schema, node.directives);
|
6177 | } else if (node.kind === 'Connection') {
|
6178 | return 'Connection:' + node.label;
|
6179 | } else if (node.kind === 'FragmentSpread') {
|
6180 | return 'FragmentSpread:' + node.args.length === 0 ? node.name : node.name + printArguments(schema, node.args);
|
6181 | } else if (node.kind === 'ModuleImport') {
|
6182 | return 'ModuleImport:';
|
6183 | } else if (node.kind === 'Defer') {
|
6184 | return 'Defer:' + node.label;
|
6185 | } else if (node.kind === 'Stream') {
|
6186 | return 'Stream:' + node.label;
|
6187 | } else if (node.kind === 'InlineFragment') {
|
6188 | return 'InlineFragment:' + schema.getTypeString(node.typeCondition);
|
6189 | } else if (node.kind === 'ClientExtension') {
|
6190 | return 'ClientExtension:';
|
6191 | } else if (node.kind === 'InlineDataFragmentSpread') {
|
6192 | return 'InlineDataFragment:' + node.name;
|
6193 | } else if (node.kind === 'Condition') {
|
6194 | return 'Condition:' + (node.condition.kind === 'Variable' ? '$' + node.condition.variableName : String(node.condition.value)) + String(node.passingValue);
|
6195 | } else {
|
6196 | true ? true ? invariant(false, 'getIdentifierForSelection: Unexpected kind `%s`.', node.kind) : undefined : undefined;
|
6197 | }
|
6198 | }
|
6199 |
|
6200 | module.exports = getIdentifierForSelection;
|
6201 |
|
6202 | /***/ }),
|
6203 | /* 38 */
|
6204 | /***/ (function(module, exports, __webpack_require__) {
|
6205 |
|
6206 | "use strict";
|
6207 | /**
|
6208 | * Copyright (c) Facebook, Inc. and its affiliates.
|
6209 | *
|
6210 | * This source code is licensed under the MIT license found in the
|
6211 | * LICENSE file in the root directory of this source tree.
|
6212 | *
|
6213 | *
|
6214 | * @format
|
6215 | */
|
6216 |
|
6217 |
|
6218 | function hasUnaliasedSelection(field, fieldName) {
|
6219 | return field.selections.some(function (selection) {
|
6220 | return selection.kind === 'ScalarField' && selection.alias === fieldName && selection.name === fieldName;
|
6221 | });
|
6222 | }
|
6223 |
|
6224 | module.exports = {
|
6225 | hasUnaliasedSelection: hasUnaliasedSelection
|
6226 | };
|
6227 |
|
6228 | /***/ }),
|
6229 | /* 39 */
|
6230 | /***/ (function(module, exports, __webpack_require__) {
|
6231 |
|
6232 | "use strict";
|
6233 | /**
|
6234 | * Copyright (c) Facebook, Inc. and its affiliates.
|
6235 | *
|
6236 | * This source code is licensed under the MIT license found in the
|
6237 | * LICENSE file in the root directory of this source tree.
|
6238 | *
|
6239 | *
|
6240 | * @format
|
6241 | */
|
6242 |
|
6243 |
|
6244 | var _interopRequireDefault = __webpack_require__(0);
|
6245 |
|
6246 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
6247 |
|
6248 | var IRTransformer = __webpack_require__(3);
|
6249 |
|
6250 | var invariant = __webpack_require__(4);
|
6251 |
|
6252 | var joinArgumentDefinitions = __webpack_require__(86);
|
6253 |
|
6254 | var _require = __webpack_require__(1),
|
6255 | createUserError = _require.createUserError;
|
6256 |
|
6257 | /**
|
6258 | * A transform that inlines fragment spreads with the @relay(mask: false)
|
6259 | * directive.
|
6260 | */
|
6261 | function maskTransform(context) {
|
6262 | return IRTransformer.transform(context, {
|
6263 | FragmentSpread: visitFragmentSpread,
|
6264 | Fragment: visitFragment
|
6265 | }, function () {
|
6266 | return {
|
6267 | reachableArguments: []
|
6268 | };
|
6269 | });
|
6270 | }
|
6271 |
|
6272 | function visitFragment(fragment, state) {
|
6273 | var result = this.traverse(fragment, state);
|
6274 |
|
6275 | if (state.reachableArguments.length === 0) {
|
6276 | return result;
|
6277 | }
|
6278 |
|
6279 | var joinedArgumentDefinitions = joinArgumentDefinitions(this.getContext().getSchema(), fragment, state.reachableArguments, '@relay(unmask: true)');
|
6280 | return (0, _objectSpread2["default"])({}, result, {
|
6281 | argumentDefinitions: joinedArgumentDefinitions
|
6282 | });
|
6283 | }
|
6284 |
|
6285 | function visitFragmentSpread(fragmentSpread, state) {
|
6286 | if (!isUnmaskedSpread(fragmentSpread)) {
|
6287 | return fragmentSpread;
|
6288 | }
|
6289 |
|
6290 | !(fragmentSpread.args.length === 0) ? true ? invariant(false, 'MaskTransform: Cannot unmask fragment spread `%s` with ' + 'arguments. Use the `ApplyFragmentArgumentTransform` before flattening', fragmentSpread.name) : undefined : void 0;
|
6291 | var context = this.getContext();
|
6292 | var fragment = context.getFragment(fragmentSpread.name);
|
6293 | var result = {
|
6294 | kind: 'InlineFragment',
|
6295 | directives: fragmentSpread.directives,
|
6296 | loc: {
|
6297 | kind: 'Derived',
|
6298 | source: fragmentSpread.loc
|
6299 | },
|
6300 | metadata: fragmentSpread.metadata,
|
6301 | selections: fragment.selections,
|
6302 | typeCondition: fragment.type
|
6303 | };
|
6304 |
|
6305 | if (fragment.directives.length > 0) {
|
6306 | throw new createUserError('Cannot use @relay(mask: false) on fragment spreads for fragments ' + 'with directives.', [fragmentSpread.loc, fragment.directives[0].loc]);
|
6307 | }
|
6308 |
|
6309 | var localArgDef = fragment.argumentDefinitions.find(function (argDef) {
|
6310 | return argDef.kind === 'LocalArgumentDefinition';
|
6311 | });
|
6312 |
|
6313 | if (localArgDef != null) {
|
6314 | throw createUserError('MaskTransform: Cannot use @relay(mask: false) on fragment spread ' + 'because the fragment definition uses @argumentDefinitions.', [fragmentSpread.loc, localArgDef.loc]);
|
6315 | } // Note: defer validating arguments to the containing fragment in order
|
6316 | // to list all invalid variables/arguments instead of only one.
|
6317 |
|
6318 |
|
6319 | var _iteratorNormalCompletion = true;
|
6320 | var _didIteratorError = false;
|
6321 | var _iteratorError = undefined;
|
6322 |
|
6323 | try {
|
6324 | for (var _iterator = fragment.argumentDefinitions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
6325 | var argDef = _step.value;
|
6326 | state.reachableArguments.push(argDef);
|
6327 | }
|
6328 | } catch (err) {
|
6329 | _didIteratorError = true;
|
6330 | _iteratorError = err;
|
6331 | } finally {
|
6332 | try {
|
6333 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
6334 | _iterator["return"]();
|
6335 | }
|
6336 | } finally {
|
6337 | if (_didIteratorError) {
|
6338 | throw _iteratorError;
|
6339 | }
|
6340 | }
|
6341 | }
|
6342 |
|
6343 | return this.traverse(result, state);
|
6344 | }
|
6345 | /**
|
6346 | * @private
|
6347 | */
|
6348 |
|
6349 |
|
6350 | function isUnmaskedSpread(spread) {
|
6351 | return Boolean(spread.metadata && spread.metadata.mask === false);
|
6352 | }
|
6353 |
|
6354 | module.exports = {
|
6355 | transform: maskTransform
|
6356 | };
|
6357 |
|
6358 | /***/ }),
|
6359 | /* 40 */
|
6360 | /***/ (function(module, exports, __webpack_require__) {
|
6361 |
|
6362 | "use strict";
|
6363 | /**
|
6364 | * Copyright (c) Facebook, Inc. and its affiliates.
|
6365 | *
|
6366 | * This source code is licensed under the MIT license found in the
|
6367 | * LICENSE file in the root directory of this source tree.
|
6368 | *
|
6369 | *
|
6370 | * @format
|
6371 | */
|
6372 |
|
6373 |
|
6374 | var _interopRequireDefault = __webpack_require__(0);
|
6375 |
|
6376 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
6377 |
|
6378 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
6379 |
|
6380 | var IRTransformer = __webpack_require__(3);
|
6381 |
|
6382 | var getLiteralArgumentValues = __webpack_require__(16);
|
6383 |
|
6384 | var getNormalizationOperationName = __webpack_require__(41);
|
6385 |
|
6386 | var _require = __webpack_require__(1),
|
6387 | createUserError = _require.createUserError;
|
6388 |
|
6389 | var _require2 = __webpack_require__(9),
|
6390 | getModuleComponentKey = _require2.getModuleComponentKey,
|
6391 | getModuleOperationKey = _require2.getModuleOperationKey;
|
6392 |
|
6393 | var SUPPORTED_ARGUMENT_NAME = 'supported';
|
6394 | var JS_FIELD_TYPE = 'JSDependency';
|
6395 | var JS_FIELD_MODULE_ARG = 'module';
|
6396 | var JS_FIELD_ID_ARG = 'id';
|
6397 | var JS_FIELD_NAME = 'js';
|
6398 | var SCHEMA_EXTENSION = "\n directive @match on FIELD\n\n directive @module(\n name: String!\n ) on FRAGMENT_SPREAD\n";
|
6399 |
|
6400 | /**
|
6401 | * This transform rewrites LinkedField nodes with @match and rewrites them
|
6402 | * into `LinkedField` nodes with a `supported` argument.
|
6403 | */
|
6404 | function matchTransform(context) {
|
6405 | return IRTransformer.transform(context, {
|
6406 | // TODO: type IRTransformer to allow changing result type
|
6407 | FragmentSpread: visitFragmentSpread,
|
6408 | LinkedField: visitLinkedField,
|
6409 | InlineFragment: visitInlineFragment,
|
6410 | ScalarField: visitScalarField
|
6411 | }, function (node) {
|
6412 | return {
|
6413 | documentName: node.name,
|
6414 | parentType: node.type,
|
6415 | path: []
|
6416 | };
|
6417 | });
|
6418 | }
|
6419 |
|
6420 | function visitInlineFragment(node, state) {
|
6421 | return this.traverse(node, (0, _objectSpread2["default"])({}, state, {
|
6422 | parentType: node.typeCondition
|
6423 | }));
|
6424 | }
|
6425 |
|
6426 | function visitScalarField(field) {
|
6427 | var context = this.getContext();
|
6428 | var schema = context.getSchema();
|
6429 |
|
6430 | if (field.name === JS_FIELD_NAME) {
|
6431 | var jsModuleType = schema.getTypeFromString(JS_FIELD_TYPE);
|
6432 |
|
6433 | if (jsModuleType == null || !schema.isServerType(jsModuleType)) {
|
6434 | throw new createUserError("'".concat(JS_FIELD_NAME, "' should be defined on the server schema."), [field.loc]);
|
6435 | }
|
6436 |
|
6437 | if (schema.isScalar(jsModuleType) && schema.areEqualTypes(schema.getRawType(field.type), jsModuleType)) {
|
6438 | throw new createUserError("Direct use of the '".concat(JS_FIELD_NAME, "' field is not allowed, use ") + '@match/@module instead.', [field.loc]);
|
6439 | }
|
6440 | }
|
6441 |
|
6442 | return field;
|
6443 | }
|
6444 |
|
6445 | function visitLinkedField(node, state) {
|
6446 | var context = this.getContext();
|
6447 | var schema = context.getSchema();
|
6448 | state.path.push(node.alias);
|
6449 | var transformedNode = this.traverse(node, (0, _objectSpread2["default"])({}, state, {
|
6450 | parentType: node.type
|
6451 | }));
|
6452 | state.path.pop();
|
6453 | var matchDirective = transformedNode.directives.find(function (directive) {
|
6454 | return directive.name === 'match';
|
6455 | });
|
6456 |
|
6457 | if (matchDirective == null) {
|
6458 | return transformedNode;
|
6459 | }
|
6460 |
|
6461 | var parentType = state.parentType;
|
6462 | var rawType = schema.getRawType(parentType);
|
6463 |
|
6464 | if (!(schema.isInterface(rawType) || schema.isObject(rawType))) {
|
6465 | throw createUserError("@match used on incompatible field '".concat(transformedNode.name, "'.") + '@match may only be used with fields whose parent type is an ' + "interface or object, got invalid type '".concat(schema.getTypeString(parentType), "'."), [node.loc]);
|
6466 | }
|
6467 |
|
6468 | var currentField = schema.getFieldConfig(schema.expectField(schema.assertCompositeType(rawType), transformedNode.name));
|
6469 | var supportedArgumentDefinition = currentField.args.find(function (_ref4) {
|
6470 | var name = _ref4.name;
|
6471 | return name === SUPPORTED_ARGUMENT_NAME;
|
6472 | });
|
6473 | var supportedArgType = supportedArgumentDefinition != null ? schema.getNullableType(supportedArgumentDefinition.type) : null;
|
6474 | var supportedArgOfType = supportedArgType != null && schema.isList(supportedArgType) ? schema.getListItemType(supportedArgType) : null;
|
6475 |
|
6476 | if (supportedArgumentDefinition == null || supportedArgType == null || supportedArgOfType == null || !schema.isString(schema.getNullableType(supportedArgOfType))) {
|
6477 | throw createUserError("@match used on incompatible field '".concat(transformedNode.name, "'. ") + '@match may only be used with fields that accept a ' + "'supported: [String!]!' argument.", [node.loc]);
|
6478 | }
|
6479 |
|
6480 | var rawFieldType = schema.getRawType(transformedNode.type);
|
6481 |
|
6482 | if (!schema.isAbstractType(rawFieldType)) {
|
6483 | throw createUserError("@match used on incompatible field '".concat(transformedNode.name, "'.") + '@match may only be used with fields that return a union or interface.', [node.loc]);
|
6484 | }
|
6485 |
|
6486 | var seenTypes = new Map();
|
6487 | var selections = [];
|
6488 | transformedNode.selections.forEach(function (matchSelection) {
|
6489 | if (matchSelection.kind === 'ScalarField' && matchSelection.name === '__typename') {
|
6490 | selections.push(matchSelection);
|
6491 | return;
|
6492 | }
|
6493 |
|
6494 | var moduleImport = matchSelection.kind === 'InlineFragment' ? matchSelection.selections[0] : null;
|
6495 |
|
6496 | if (matchSelection.kind !== 'InlineFragment' || moduleImport == null || moduleImport.kind !== 'ModuleImport') {
|
6497 | throw createUserError('Invalid @match selection: all selections should be ' + 'fragment spreads with @module.', [matchSelection.loc]);
|
6498 | }
|
6499 |
|
6500 | var matchedType = matchSelection.typeCondition;
|
6501 | var previousTypeUsage = seenTypes.get(matchedType);
|
6502 |
|
6503 | if (previousTypeUsage) {
|
6504 | throw createUserError('Invalid @match selection: each concrete variant/implementor of ' + "'".concat(schema.getTypeString(rawFieldType), "' may be matched against at-most once, ") + "but '".concat(schema.getTypeString(matchedType), "' was matched against multiple times."), [matchSelection.loc, previousTypeUsage.loc]);
|
6505 | }
|
6506 |
|
6507 | seenTypes.set(matchedType, matchSelection);
|
6508 | selections.push(matchSelection);
|
6509 | });
|
6510 |
|
6511 | if (seenTypes.size === 0) {
|
6512 | throw createUserError('Invalid @match selection: expected at least one @module selection. ' + "Remove @match or add a '...Fragment @module()' selection.", [matchDirective.loc]);
|
6513 | }
|
6514 |
|
6515 | var supportedArg = transformedNode.args.find(function (arg) {
|
6516 | return arg.name === SUPPORTED_ARGUMENT_NAME;
|
6517 | });
|
6518 |
|
6519 | if (supportedArg != null) {
|
6520 | throw createUserError("Invalid @match selection: the '".concat(SUPPORTED_ARGUMENT_NAME, "' argument ") + 'is automatically added and cannot be supplied explicitly.', [supportedArg.loc]);
|
6521 | }
|
6522 |
|
6523 | return {
|
6524 | kind: 'LinkedField',
|
6525 | alias: transformedNode.alias,
|
6526 | args: [].concat((0, _toConsumableArray2["default"])(transformedNode.args), [{
|
6527 | kind: 'Argument',
|
6528 | name: SUPPORTED_ARGUMENT_NAME,
|
6529 | type: supportedArgumentDefinition.type,
|
6530 | value: {
|
6531 | kind: 'Literal',
|
6532 | loc: node.loc,
|
6533 | value: Array.from(seenTypes.keys()).map(function (type) {
|
6534 | return schema.getTypeString(type);
|
6535 | })
|
6536 | },
|
6537 | loc: node.loc
|
6538 | }]),
|
6539 | connection: false,
|
6540 | directives: [],
|
6541 | handles: null,
|
6542 | loc: node.loc,
|
6543 | metadata: null,
|
6544 | name: transformedNode.name,
|
6545 | type: transformedNode.type,
|
6546 | selections: selections
|
6547 | };
|
6548 | } // Transform @module
|
6549 |
|
6550 |
|
6551 | function visitFragmentSpread(spread, _ref5) {
|
6552 | var _ref, _moduleDirective$args2, _ref2, _moduleDirective$args3, _ref3, _moduleDirective$args4;
|
6553 |
|
6554 | var documentName = _ref5.documentName,
|
6555 | path = _ref5.path;
|
6556 | var transformedNode = this.traverse(spread);
|
6557 | var moduleDirective = transformedNode.directives.find(function (directive) {
|
6558 | return directive.name === 'module';
|
6559 | });
|
6560 |
|
6561 | if (moduleDirective == null) {
|
6562 | return transformedNode;
|
6563 | }
|
6564 |
|
6565 | if (spread.args.length !== 0) {
|
6566 | var _spread$args$;
|
6567 |
|
6568 | throw createUserError('@module does not support @arguments.', [(_spread$args$ = spread.args[0]) === null || _spread$args$ === void 0 ? void 0 : _spread$args$.loc].filter(Boolean));
|
6569 | }
|
6570 |
|
6571 | var context = this.getContext();
|
6572 | var schema = context.getSchema();
|
6573 | var jsModuleType = schema.asScalarFieldType(schema.getTypeFromString(JS_FIELD_TYPE));
|
6574 |
|
6575 | if (jsModuleType == null || !schema.isServerType(jsModuleType)) {
|
6576 | throw new createUserError("'".concat(JS_FIELD_NAME, "' should be defined on the server schema."), [spread.loc]);
|
6577 | }
|
6578 |
|
6579 | if (!schema.isScalar(jsModuleType)) {
|
6580 | throw createUserError('Using @module requires the schema to define a scalar ' + "'".concat(JS_FIELD_TYPE, "' type."));
|
6581 | }
|
6582 |
|
6583 | var fragment = context.getFragment(spread.name, spread.loc);
|
6584 |
|
6585 | if (!schema.isObject(fragment.type)) {
|
6586 | throw createUserError("@module used on invalid fragment spread '...".concat(spread.name, "'. @module ") + 'may only be used with fragments on a concrete (object) type, ' + "but the fragment has abstract type '".concat(schema.getTypeString(fragment.type), "'."), [spread.loc, fragment.loc]);
|
6587 | }
|
6588 |
|
6589 | var field = schema.getFieldByName(fragment.type, JS_FIELD_NAME);
|
6590 |
|
6591 | if (!field) {
|
6592 | throw createUserError("@module used on invalid fragment spread '...".concat(spread.name, "'. @module ") + "requires the fragment type '".concat(schema.getTypeString(fragment.type), "' to have a ") + "'".concat(JS_FIELD_NAME, "(").concat(JS_FIELD_MODULE_ARG, ": String! ") + "[".concat(JS_FIELD_ID_ARG, ": String]): ").concat(JS_FIELD_TYPE, "' field (your ") + "schema may choose to omit the 'id' argument but if present it " + "must accept a 'String').", [moduleDirective.loc]);
|
6593 | }
|
6594 |
|
6595 | var jsField = schema.getFieldConfig(field);
|
6596 | var jsFieldModuleArg = jsField ? jsField.args.find(function (arg) {
|
6597 | return arg.name === JS_FIELD_MODULE_ARG;
|
6598 | }) : null;
|
6599 | var jsFieldIdArg = jsField ? jsField.args.find(function (arg) {
|
6600 | return arg.name === JS_FIELD_ID_ARG;
|
6601 | }) : null;
|
6602 |
|
6603 | if (jsFieldModuleArg == null || !schema.isString(schema.getNullableType(jsFieldModuleArg.type)) || jsFieldIdArg != null && !schema.isString(jsFieldIdArg.type) || jsField.type !== jsModuleType) {
|
6604 | throw createUserError("@module used on invalid fragment spread '...".concat(spread.name, "'. @module ") + "requires the fragment type '".concat(schema.getTypeString(fragment.type), "' to have a ") + "'".concat(JS_FIELD_NAME, "(").concat(JS_FIELD_MODULE_ARG, ": String! ") + "[".concat(JS_FIELD_ID_ARG, ": String]): ").concat(JS_FIELD_TYPE, "' field (your ") + "schema may choose to omit the 'id' argument but if present it " + "must accept a 'String').", [moduleDirective.loc]);
|
6605 | }
|
6606 |
|
6607 | if (spread.directives.length !== 1) {
|
6608 | throw createUserError("@module used on invalid fragment spread '...".concat(spread.name, "'. @module ") + 'may not have additional directives.', [spread.loc]);
|
6609 | }
|
6610 |
|
6611 | var _getLiteralArgumentVa = getLiteralArgumentValues(moduleDirective.args),
|
6612 | moduleName = _getLiteralArgumentVa.name;
|
6613 |
|
6614 | if (typeof moduleName !== 'string') {
|
6615 | var _moduleDirective$args;
|
6616 |
|
6617 | throw createUserError("Expected the 'name' argument of @module to be a literal string", [((_moduleDirective$args = moduleDirective.args.find(function (arg) {
|
6618 | return arg.name === 'name';
|
6619 | })) !== null && _moduleDirective$args !== void 0 ? _moduleDirective$args : spread).loc]);
|
6620 | }
|
6621 |
|
6622 | var moduleId = [documentName].concat((0, _toConsumableArray2["default"])(path)).join('.');
|
6623 | var normalizationName = getNormalizationOperationName(spread.name) + '.graphql';
|
6624 | var componentKey = getModuleComponentKey(documentName);
|
6625 | var componentField = {
|
6626 | alias: componentKey,
|
6627 | args: [{
|
6628 | kind: 'Argument',
|
6629 | name: JS_FIELD_MODULE_ARG,
|
6630 | type: jsFieldModuleArg.type,
|
6631 | value: {
|
6632 | kind: 'Literal',
|
6633 | loc: (_ref = (_moduleDirective$args2 = moduleDirective.args[0]) === null || _moduleDirective$args2 === void 0 ? void 0 : _moduleDirective$args2.loc) !== null && _ref !== void 0 ? _ref : moduleDirective.loc,
|
6634 | value: moduleName
|
6635 | },
|
6636 | loc: moduleDirective.loc
|
6637 | }, jsFieldIdArg != null ? {
|
6638 | kind: 'Argument',
|
6639 | name: JS_FIELD_ID_ARG,
|
6640 | type: jsFieldIdArg.type,
|
6641 | value: {
|
6642 | kind: 'Literal',
|
6643 | loc: (_ref2 = (_moduleDirective$args3 = moduleDirective.args[0]) === null || _moduleDirective$args3 === void 0 ? void 0 : _moduleDirective$args3.loc) !== null && _ref2 !== void 0 ? _ref2 : moduleDirective.loc,
|
6644 | value: moduleId
|
6645 | },
|
6646 | loc: moduleDirective.loc
|
6647 | } : null].filter(Boolean),
|
6648 | directives: [],
|
6649 | handles: null,
|
6650 | kind: 'ScalarField',
|
6651 | loc: moduleDirective.loc,
|
6652 | metadata: {
|
6653 | skipNormalizationNode: true
|
6654 | },
|
6655 | name: JS_FIELD_NAME,
|
6656 | type: jsModuleType
|
6657 | };
|
6658 | var operationKey = getModuleOperationKey(documentName);
|
6659 | var operationField = {
|
6660 | alias: operationKey,
|
6661 | args: [{
|
6662 | kind: 'Argument',
|
6663 | name: JS_FIELD_MODULE_ARG,
|
6664 | type: jsFieldModuleArg.type,
|
6665 | value: {
|
6666 | kind: 'Literal',
|
6667 | loc: moduleDirective.loc,
|
6668 | value: normalizationName
|
6669 | },
|
6670 | loc: moduleDirective.loc
|
6671 | }, jsFieldIdArg != null ? {
|
6672 | kind: 'Argument',
|
6673 | name: JS_FIELD_ID_ARG,
|
6674 | type: jsFieldIdArg.type,
|
6675 | value: {
|
6676 | kind: 'Literal',
|
6677 | loc: (_ref3 = (_moduleDirective$args4 = moduleDirective.args[0]) === null || _moduleDirective$args4 === void 0 ? void 0 : _moduleDirective$args4.loc) !== null && _ref3 !== void 0 ? _ref3 : moduleDirective.loc,
|
6678 | value: moduleId
|
6679 | },
|
6680 | loc: moduleDirective.loc
|
6681 | } : null].filter(Boolean),
|
6682 | directives: [],
|
6683 | handles: null,
|
6684 | kind: 'ScalarField',
|
6685 | loc: moduleDirective.loc,
|
6686 | metadata: {
|
6687 | skipNormalizationNode: true
|
6688 | },
|
6689 | name: JS_FIELD_NAME,
|
6690 | type: jsModuleType
|
6691 | };
|
6692 | return {
|
6693 | kind: 'InlineFragment',
|
6694 | directives: [],
|
6695 | loc: moduleDirective.loc,
|
6696 | metadata: null,
|
6697 | selections: [{
|
6698 | kind: 'ModuleImport',
|
6699 | loc: moduleDirective.loc,
|
6700 | documentName: documentName,
|
6701 | id: moduleId,
|
6702 | module: moduleName,
|
6703 | name: spread.name,
|
6704 | selections: [(0, _objectSpread2["default"])({}, spread, {
|
6705 | directives: spread.directives.filter(function (directive) {
|
6706 | return directive !== moduleDirective;
|
6707 | })
|
6708 | }), operationField, componentField]
|
6709 | }],
|
6710 | typeCondition: fragment.type
|
6711 | };
|
6712 | }
|
6713 |
|
6714 | module.exports = {
|
6715 | SCHEMA_EXTENSION: SCHEMA_EXTENSION,
|
6716 | transform: matchTransform
|
6717 | };
|
6718 |
|
6719 | /***/ }),
|
6720 | /* 41 */
|
6721 | /***/ (function(module, exports, __webpack_require__) {
|
6722 |
|
6723 | "use strict";
|
6724 | /**
|
6725 | * Copyright (c) Facebook, Inc. and its affiliates.
|
6726 | *
|
6727 | * This source code is licensed under the MIT license found in the
|
6728 | * LICENSE file in the root directory of this source tree.
|
6729 | *
|
6730 | *
|
6731 | * @format
|
6732 | */
|
6733 |
|
6734 |
|
6735 | function getNormalizationOperationName(name) {
|
6736 | return "".concat(name, "$normalization");
|
6737 | }
|
6738 |
|
6739 | module.exports = getNormalizationOperationName;
|
6740 |
|
6741 | /***/ }),
|
6742 | /* 42 */
|
6743 | /***/ (function(module, exports, __webpack_require__) {
|
6744 |
|
6745 | "use strict";
|
6746 | /**
|
6747 | * Copyright (c) Facebook, Inc. and its affiliates.
|
6748 | *
|
6749 | * This source code is licensed under the MIT license found in the
|
6750 | * LICENSE file in the root directory of this source tree.
|
6751 | *
|
6752 | *
|
6753 | * @format
|
6754 | */
|
6755 |
|
6756 |
|
6757 | var _interopRequireDefault = __webpack_require__(0);
|
6758 |
|
6759 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
6760 |
|
6761 | var GraphQLIRVisitor = __webpack_require__(15);
|
6762 |
|
6763 | var getLiteralArgumentValues = __webpack_require__(16);
|
6764 |
|
6765 | var inferRootArgumentDefinitions = __webpack_require__(17);
|
6766 |
|
6767 | var _require = __webpack_require__(1),
|
6768 | createUserError = _require.createUserError,
|
6769 | eachWithCombinedError = _require.eachWithCombinedError;
|
6770 |
|
6771 | var _require2 = __webpack_require__(87),
|
6772 | buildRefetchOperation = _require2.buildRefetchOperation;
|
6773 |
|
6774 | var SCHEMA_EXTENSION = "\n directive @refetchable(\n queryName: String!\n ) on FRAGMENT_DEFINITION\n";
|
6775 | /**
|
6776 | * This transform synthesizes "refetch" queries for fragments that
|
6777 | * are trivially refetchable. This is comprised of three main stages:
|
6778 | *
|
6779 | * 1. Validating that fragments marked with @refetchable qualify for
|
6780 | * refetch query generation; mainly this means that the fragment
|
6781 | * type is able to be refetched in some canonical way.
|
6782 | * 2. Determining the variable definitions to use for each generated
|
6783 | * query. GraphQL does not have a notion of fragment-local variables
|
6784 | * at all, and although Relay adds this concept developers are still
|
6785 | * allowed to reference global variables. This necessitates a
|
6786 | * visiting all reachable fragments for each @refetchable fragment,
|
6787 | * and finding the union of all global variables expceted to be defined.
|
6788 | * 3. Building the refetch queries, a straightforward copying transform from
|
6789 | * Fragment to Root IR nodes.
|
6790 | */
|
6791 |
|
6792 | function refetchableFragmentTransform(context) {
|
6793 | var schema = context.getSchema();
|
6794 | var refetchOperations = buildRefetchMap(context);
|
6795 | var nextContext = context;
|
6796 | eachWithCombinedError(refetchOperations, function (_ref2) {
|
6797 | var _connectionMetadata;
|
6798 |
|
6799 | var refetchName = _ref2[0],
|
6800 | fragment = _ref2[1];
|
6801 |
|
6802 | var _buildRefetchOperatio = buildRefetchOperation(schema, fragment, refetchName),
|
6803 | path = _buildRefetchOperatio.path,
|
6804 | node = _buildRefetchOperatio.node,
|
6805 | transformedFragment = _buildRefetchOperatio.transformedFragment;
|
6806 |
|
6807 | var connectionMetadata = extractConnectionMetadata(context.getSchema(), transformedFragment);
|
6808 | nextContext = nextContext.replace((0, _objectSpread2["default"])({}, transformedFragment, {
|
6809 | metadata: (0, _objectSpread2["default"])({}, transformedFragment.metadata || {}, {
|
6810 | refetch: {
|
6811 | connection: (_connectionMetadata = connectionMetadata) !== null && _connectionMetadata !== void 0 ? _connectionMetadata : null,
|
6812 | operation: refetchName,
|
6813 | fragmentPathInResult: path
|
6814 | }
|
6815 | })
|
6816 | }));
|
6817 | nextContext = nextContext.add((0, _objectSpread2["default"])({}, node, {
|
6818 | metadata: (0, _objectSpread2["default"])({}, node.metadata || {}, {
|
6819 | derivedFrom: transformedFragment.name,
|
6820 | isRefetchableQuery: true
|
6821 | })
|
6822 | }));
|
6823 | });
|
6824 | return nextContext;
|
6825 | }
|
6826 | /**
|
6827 | * Walk the documents of a compiler context and create a mapping of
|
6828 | * refetch operation names to the source fragment from which the refetch
|
6829 | * operation should be derived.
|
6830 | */
|
6831 |
|
6832 |
|
6833 | function buildRefetchMap(context) {
|
6834 | var refetchOperations = new Map();
|
6835 | eachWithCombinedError(context.documents(), function (node) {
|
6836 | if (node.kind !== 'Fragment') {
|
6837 | return;
|
6838 | }
|
6839 |
|
6840 | var refetchName = getRefetchQueryName(node);
|
6841 |
|
6842 | if (refetchName === null) {
|
6843 | return;
|
6844 | }
|
6845 |
|
6846 | var previousOperation = refetchOperations.get(refetchName);
|
6847 |
|
6848 | if (previousOperation != null) {
|
6849 | throw createUserError("Duplicate definition for @refetchable operation '".concat(refetchName, "' from fragments '").concat(node.name, "' and '").concat(previousOperation.name, "'"), [node.loc, previousOperation.loc]);
|
6850 | }
|
6851 |
|
6852 | refetchOperations.set(refetchName, node);
|
6853 | });
|
6854 | var transformed = inferRootArgumentDefinitions(context);
|
6855 | return new Map(Array.from(refetchOperations.entries(), function (_ref3) {
|
6856 | var name = _ref3[0],
|
6857 | fragment = _ref3[1];
|
6858 | return [name, transformed.getFragment(fragment.name)];
|
6859 | }));
|
6860 | }
|
6861 | /**
|
6862 | * Validate that any @connection usage is valid for refetching:
|
6863 | * - Variables are used for both the "count" and "cursor" arguments
|
6864 | * (after/first or before/last)
|
6865 | * - Exactly one connection
|
6866 | * - Has a stable path to the connection data
|
6867 | *
|
6868 | * Returns connection metadata to add to the transformed fragment or undefined
|
6869 | * if there is no connection.
|
6870 | */
|
6871 |
|
6872 |
|
6873 | function extractConnectionMetadata(schema, fragment) {
|
6874 | var fields = [];
|
6875 | var connectionField = null;
|
6876 | var path = null;
|
6877 | GraphQLIRVisitor.visit(fragment, {
|
6878 | ConnectionField: {
|
6879 | enter: function enter(field) {
|
6880 | fields.push(field); // Disallow connections within plurals
|
6881 |
|
6882 | var pluralOnPath = fields.find(function (pathField) {
|
6883 | return schema.isList(schema.getNullableType(pathField.type));
|
6884 | });
|
6885 |
|
6886 | if (pluralOnPath) {
|
6887 | throw createUserError("Invalid use of @refetchable with @connection in fragment '".concat(fragment.name, "', refetchable connections cannot appear inside plural fields."), [field.loc, pluralOnPath.loc]);
|
6888 | }
|
6889 |
|
6890 | connectionField = field;
|
6891 | path = fields.map(function (pathField) {
|
6892 | return pathField.alias;
|
6893 | });
|
6894 | },
|
6895 | leave: function leave() {
|
6896 | fields.pop();
|
6897 | }
|
6898 | },
|
6899 | LinkedField: {
|
6900 | enter: function enter(field) {
|
6901 | fields.push(field);
|
6902 |
|
6903 | if (field.connection === true || field.handles && field.handles.some(function (handle) {
|
6904 | return handle.name === 'connection';
|
6905 | })) {
|
6906 | // Disallow multiple @connections
|
6907 | if (connectionField != null) {
|
6908 | throw createUserError("Invalid use of @refetchable with @connection in fragment '".concat(fragment.name, "', at most once @connection can appear in a refetchable fragment."), [field.loc]);
|
6909 | } // Disallow connections within plurals
|
6910 |
|
6911 |
|
6912 | var pluralOnPath = fields.find(function (pathField) {
|
6913 | return schema.isList(schema.getNullableType(pathField.type));
|
6914 | });
|
6915 |
|
6916 | if (pluralOnPath) {
|
6917 | throw createUserError("Invalid use of @refetchable with @connection in fragment '".concat(fragment.name, "', refetchable connections cannot appear inside plural fields."), [field.loc, pluralOnPath.loc]);
|
6918 | }
|
6919 |
|
6920 | connectionField = field;
|
6921 | path = fields.map(function (pathField) {
|
6922 | return pathField.alias;
|
6923 | });
|
6924 | }
|
6925 | },
|
6926 | leave: function leave() {
|
6927 | fields.pop();
|
6928 | }
|
6929 | }
|
6930 | });
|
6931 |
|
6932 | if (connectionField == null || path == null) {
|
6933 | return;
|
6934 | } // Validate arguments: if either of before/last appear they must both appear
|
6935 | // and use variables (not scalar values)
|
6936 |
|
6937 |
|
6938 | var backward = null;
|
6939 | var before = findArgument(connectionField, 'before');
|
6940 | var last = findArgument(connectionField, 'last');
|
6941 |
|
6942 | if (before || last) {
|
6943 | if (!before || !last || before.value.kind !== 'Variable' || last.value.kind !== 'Variable') {
|
6944 | throw createUserError("Invalid use of @refetchable with @connection in fragment '".concat(fragment.name, "', refetchable connections must use variables for the before and last arguments."), [connectionField.loc, before && before.value.kind !== 'Variable' ? before.value.loc : null, last && last.value.kind !== 'Variable' ? last.value.loc : null].filter(Boolean));
|
6945 | }
|
6946 |
|
6947 | backward = {
|
6948 | count: last.value.variableName,
|
6949 | cursor: before.value.variableName
|
6950 | };
|
6951 | } // Validate arguments: if either of after/first appear they must both appear
|
6952 | // and use variables (not scalar values)
|
6953 |
|
6954 |
|
6955 | var forward = null;
|
6956 | var after = findArgument(connectionField, 'after');
|
6957 | var first = findArgument(connectionField, 'first');
|
6958 |
|
6959 | if (after || first) {
|
6960 | if (!after || !first || after.value.kind !== 'Variable' || first.value.kind !== 'Variable') {
|
6961 | throw createUserError("Invalid use of @refetchable with @connection in fragment '".concat(fragment.name, "', refetchable connections must use variables for the after and first arguments."), [connectionField.loc, after && after.value.kind !== 'Variable' ? after.value.loc : null, first && first.value.kind !== 'Variable' ? first.value.loc : null].filter(Boolean));
|
6962 | }
|
6963 |
|
6964 | forward = {
|
6965 | count: first.value.variableName,
|
6966 | cursor: after.value.variableName
|
6967 | };
|
6968 | }
|
6969 |
|
6970 | return {
|
6971 | forward: forward,
|
6972 | backward: backward,
|
6973 | path: path
|
6974 | };
|
6975 | }
|
6976 |
|
6977 | function getRefetchQueryName(fragment) {
|
6978 | var refetchableDirective = fragment.directives.find(function (directive) {
|
6979 | return directive.name === 'refetchable';
|
6980 | });
|
6981 |
|
6982 | if (refetchableDirective == null) {
|
6983 | return null;
|
6984 | }
|
6985 |
|
6986 | var refetchArguments = getLiteralArgumentValues(refetchableDirective.args);
|
6987 | var queryName = refetchArguments.queryName;
|
6988 |
|
6989 | if (queryName == null) {
|
6990 | throw createUserError("Expected the 'queryName' argument of @refetchable to be provided", [refetchableDirective.loc]);
|
6991 | } else if (typeof queryName !== 'string') {
|
6992 | var _ref;
|
6993 |
|
6994 | var queryNameArg = refetchableDirective.args.find(function (arg) {
|
6995 | return arg.name === 'queryName';
|
6996 | });
|
6997 | throw createUserError("Expected the 'queryName' argument of @refetchable to be a string, got '".concat(String(queryName), "'."), [(_ref = queryNameArg === null || queryNameArg === void 0 ? void 0 : queryNameArg.loc) !== null && _ref !== void 0 ? _ref : refetchableDirective.loc]);
|
6998 | }
|
6999 |
|
7000 | return queryName;
|
7001 | }
|
7002 |
|
7003 | function findArgument(field, argumentName) {
|
7004 | var _field$args$find;
|
7005 |
|
7006 | return (_field$args$find = field.args.find(function (arg) {
|
7007 | return arg.name === argumentName;
|
7008 | })) !== null && _field$args$find !== void 0 ? _field$args$find : null;
|
7009 | }
|
7010 |
|
7011 | module.exports = {
|
7012 | SCHEMA_EXTENSION: SCHEMA_EXTENSION,
|
7013 | transform: refetchableFragmentTransform
|
7014 | };
|
7015 |
|
7016 | /***/ }),
|
7017 | /* 43 */
|
7018 | /***/ (function(module, exports, __webpack_require__) {
|
7019 |
|
7020 | "use strict";
|
7021 | /**
|
7022 | * Copyright (c) Facebook, Inc. and its affiliates.
|
7023 | *
|
7024 | * This source code is licensed under the MIT license found in the
|
7025 | * LICENSE file in the root directory of this source tree.
|
7026 | *
|
7027 | *
|
7028 | * @format
|
7029 | */
|
7030 |
|
7031 |
|
7032 | var _interopRequireDefault = __webpack_require__(0);
|
7033 |
|
7034 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
7035 |
|
7036 | var IRTransformer = __webpack_require__(3);
|
7037 |
|
7038 | var getLiteralArgumentValues = __webpack_require__(16);
|
7039 |
|
7040 | var invariant = __webpack_require__(4);
|
7041 |
|
7042 | var RELAY = 'relay';
|
7043 | var SCHEMA_EXTENSION = "\ndirective @relay(\n # Marks a fragment as being backed by a GraphQLList.\n plural: Boolean,\n\n # Marks a fragment spread which should be unmasked if provided false\n mask: Boolean = true,\n) on FRAGMENT_DEFINITION | FRAGMENT_SPREAD\n";
|
7044 | /**
|
7045 | * A transform that extracts `@relay(plural: Boolean)` directives and converts
|
7046 | * them to metadata that can be accessed at runtime.
|
7047 | */
|
7048 |
|
7049 | function relayDirectiveTransform(context) {
|
7050 | return IRTransformer.transform(context, {
|
7051 | Fragment: visitRelayMetadata(fragmentMetadata),
|
7052 | FragmentSpread: visitRelayMetadata(fragmentSpreadMetadata)
|
7053 | });
|
7054 | }
|
7055 |
|
7056 | function visitRelayMetadata(metadataFn) {
|
7057 | return function (node) {
|
7058 | var relayDirective = node.directives.find(function (_ref) {
|
7059 | var name = _ref.name;
|
7060 | return name === RELAY;
|
7061 | });
|
7062 |
|
7063 | if (!relayDirective) {
|
7064 | return this.traverse(node);
|
7065 | }
|
7066 |
|
7067 | var argValues = getLiteralArgumentValues(relayDirective.args);
|
7068 | var metadata = metadataFn(argValues);
|
7069 | return this.traverse((0, _objectSpread2["default"])({}, node, {
|
7070 | directives: node.directives.filter(function (directive) {
|
7071 | return directive !== relayDirective;
|
7072 | }),
|
7073 | metadata: (0, _objectSpread2["default"])({}, node.metadata || {}, metadata)
|
7074 | }));
|
7075 | };
|
7076 | }
|
7077 |
|
7078 | function fragmentMetadata(_ref2) {
|
7079 | var mask = _ref2.mask,
|
7080 | plural = _ref2.plural;
|
7081 | !(plural === undefined || typeof plural === 'boolean') ? true ? invariant(false, 'RelayDirectiveTransform: Expected the "plural" argument to @relay ' + 'to be a boolean literal if specified.') : undefined : void 0;
|
7082 | !(mask === undefined || typeof mask === 'boolean') ? true ? invariant(false, 'RelayDirectiveTransform: Expected the "mask" argument to @relay ' + 'to be a boolean literal if specified.') : undefined : void 0;
|
7083 | return {
|
7084 | mask: mask,
|
7085 | plural: plural
|
7086 | };
|
7087 | }
|
7088 |
|
7089 | function fragmentSpreadMetadata(_ref3) {
|
7090 | var mask = _ref3.mask;
|
7091 | !(mask === undefined || typeof mask === 'boolean') ? true ? invariant(false, 'RelayDirectiveTransform: Expected the "mask" argument to @relay ' + 'to be a boolean literal if specified.') : undefined : void 0;
|
7092 | return {
|
7093 | mask: mask
|
7094 | };
|
7095 | }
|
7096 |
|
7097 | module.exports = {
|
7098 | RELAY: RELAY,
|
7099 | SCHEMA_EXTENSION: SCHEMA_EXTENSION,
|
7100 | transform: relayDirectiveTransform
|
7101 | };
|
7102 |
|
7103 | /***/ }),
|
7104 | /* 44 */
|
7105 | /***/ (function(module, exports, __webpack_require__) {
|
7106 |
|
7107 | "use strict";
|
7108 | /**
|
7109 | * Copyright (c) Facebook, Inc. and its affiliates.
|
7110 | *
|
7111 | * This source code is licensed under the MIT license found in the
|
7112 | * LICENSE file in the root directory of this source tree.
|
7113 | *
|
7114 | *
|
7115 | * @format
|
7116 | */
|
7117 |
|
7118 |
|
7119 | var _interopRequireDefault = __webpack_require__(0);
|
7120 |
|
7121 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
7122 |
|
7123 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
7124 |
|
7125 | var ConnectionFieldTransform = __webpack_require__(34);
|
7126 |
|
7127 | var FlattenTransform = __webpack_require__(36);
|
7128 |
|
7129 | var IRVisitor = __webpack_require__(15);
|
7130 |
|
7131 | var MaskTransform = __webpack_require__(39);
|
7132 |
|
7133 | var MatchTransform = __webpack_require__(40);
|
7134 |
|
7135 | var Profiler = __webpack_require__(6);
|
7136 |
|
7137 | var RefetchableFragmentTransform = __webpack_require__(42);
|
7138 |
|
7139 | var RelayDirectiveTransform = __webpack_require__(43);
|
7140 |
|
7141 | var _require = __webpack_require__(1),
|
7142 | createUserError = _require.createUserError;
|
7143 |
|
7144 | var _require2 = __webpack_require__(45),
|
7145 | anyTypeAlias = _require2.anyTypeAlias,
|
7146 | declareExportOpaqueType = _require2.declareExportOpaqueType,
|
7147 | exactObjectTypeAnnotation = _require2.exactObjectTypeAnnotation,
|
7148 | exportType = _require2.exportType,
|
7149 | exportTypes = _require2.exportTypes,
|
7150 | importTypes = _require2.importTypes,
|
7151 | intersectionTypeAnnotation = _require2.intersectionTypeAnnotation,
|
7152 | lineComments = _require2.lineComments,
|
7153 | readOnlyArrayOfType = _require2.readOnlyArrayOfType,
|
7154 | readOnlyObjectTypeProperty = _require2.readOnlyObjectTypeProperty,
|
7155 | unionTypeAnnotation = _require2.unionTypeAnnotation;
|
7156 |
|
7157 | var _require3 = __webpack_require__(91),
|
7158 | transformInputType = _require3.transformInputType,
|
7159 | transformScalarType = _require3.transformScalarType;
|
7160 |
|
7161 | var _require4 = __webpack_require__(9),
|
7162 | ConnectionInterface = _require4.ConnectionInterface;
|
7163 |
|
7164 | var babelGenerator = __webpack_require__(92)["default"];
|
7165 |
|
7166 | var t = __webpack_require__(22);
|
7167 |
|
7168 | var invariant = __webpack_require__(4);
|
7169 |
|
7170 | var nullthrows = __webpack_require__(20);
|
7171 |
|
7172 | function generate(schema, node, options) {
|
7173 | var ast = IRVisitor.visit(node, createVisitor(schema, options));
|
7174 | return babelGenerator(ast).code;
|
7175 | }
|
7176 |
|
7177 | function makeProp(schema, _ref, state, unmasked, concreteType) {
|
7178 | var key = _ref.key,
|
7179 | schemaName = _ref.schemaName,
|
7180 | value = _ref.value,
|
7181 | conditional = _ref.conditional,
|
7182 | nodeType = _ref.nodeType,
|
7183 | nodeSelections = _ref.nodeSelections;
|
7184 |
|
7185 | if (schemaName === '__typename' && concreteType) {
|
7186 | value = t.stringLiteralTypeAnnotation(concreteType);
|
7187 | } else if (nodeType) {
|
7188 | value = transformScalarType(schema, nodeType, state, selectionsToBabel(schema, [Array.from(nullthrows(nodeSelections).values())], state, unmasked));
|
7189 | }
|
7190 |
|
7191 | var typeProperty = readOnlyObjectTypeProperty(key, value);
|
7192 |
|
7193 | if (conditional) {
|
7194 | typeProperty.optional = true;
|
7195 | }
|
7196 |
|
7197 | return typeProperty;
|
7198 | }
|
7199 |
|
7200 | var isTypenameSelection = function isTypenameSelection(selection) {
|
7201 | return selection.schemaName === '__typename';
|
7202 | };
|
7203 |
|
7204 | var hasTypenameSelection = function hasTypenameSelection(selections) {
|
7205 | return selections.some(isTypenameSelection);
|
7206 | };
|
7207 |
|
7208 | var onlySelectsTypename = function onlySelectsTypename(selections) {
|
7209 | return selections.every(isTypenameSelection);
|
7210 | };
|
7211 |
|
7212 | function selectionsToBabel(schema, selections, state, unmasked, fragmentTypeName) {
|
7213 | var baseFields = new Map();
|
7214 | var byConcreteType = {};
|
7215 | flattenArray(selections).forEach(function (selection) {
|
7216 | var concreteType = selection.concreteType;
|
7217 |
|
7218 | if (concreteType) {
|
7219 | var _byConcreteType$concr;
|
7220 |
|
7221 | byConcreteType[concreteType] = (_byConcreteType$concr = byConcreteType[concreteType]) !== null && _byConcreteType$concr !== void 0 ? _byConcreteType$concr : [];
|
7222 | byConcreteType[concreteType].push(selection);
|
7223 | } else {
|
7224 | var previousSel = baseFields.get(selection.key);
|
7225 | baseFields.set(selection.key, previousSel ? mergeSelection(selection, previousSel) : selection);
|
7226 | }
|
7227 | });
|
7228 | var types = [];
|
7229 |
|
7230 | if (Object.keys(byConcreteType).length > 0 && onlySelectsTypename(Array.from(baseFields.values())) && (hasTypenameSelection(Array.from(baseFields.values())) || Object.keys(byConcreteType).every(function (type) {
|
7231 | return hasTypenameSelection(byConcreteType[type]);
|
7232 | }))) {
|
7233 | (function () {
|
7234 | var typenameAliases = new Set();
|
7235 |
|
7236 | var _loop = function _loop(concreteType) {
|
7237 | types.push(groupRefs([].concat((0, _toConsumableArray2["default"])(Array.from(baseFields.values())), (0, _toConsumableArray2["default"])(byConcreteType[concreteType]))).map(function (selection) {
|
7238 | if (selection.schemaName === '__typename') {
|
7239 | typenameAliases.add(selection.key);
|
7240 | }
|
7241 |
|
7242 | return makeProp(schema, selection, state, unmasked, concreteType);
|
7243 | }));
|
7244 | };
|
7245 |
|
7246 | for (var concreteType in byConcreteType) {
|
7247 | _loop(concreteType);
|
7248 | } // It might be some other type then the listed concrete types. Ideally, we
|
7249 | // would set the type to diff(string, set of listed concrete types), but
|
7250 | // this doesn't exist in Flow at the time.
|
7251 |
|
7252 |
|
7253 | types.push(Array.from(typenameAliases).map(function (typenameAlias) {
|
7254 | var otherProp = readOnlyObjectTypeProperty(typenameAlias, t.stringLiteralTypeAnnotation('%other'));
|
7255 | otherProp.leadingComments = lineComments("This will never be '%other', but we need some", 'value in case none of the concrete values match.');
|
7256 | return otherProp;
|
7257 | }));
|
7258 | })();
|
7259 | } else {
|
7260 | var selectionMap = selectionsToMap(Array.from(baseFields.values()));
|
7261 |
|
7262 | for (var concreteType in byConcreteType) {
|
7263 | selectionMap = mergeSelections(selectionMap, selectionsToMap(byConcreteType[concreteType].map(function (sel) {
|
7264 | return (0, _objectSpread2["default"])({}, sel, {
|
7265 | conditional: true
|
7266 | });
|
7267 | })));
|
7268 | }
|
7269 |
|
7270 | var selectionMapValues = groupRefs(Array.from(selectionMap.values())).map(function (sel) {
|
7271 | return isTypenameSelection(sel) && sel.concreteType ? makeProp(schema, (0, _objectSpread2["default"])({}, sel, {
|
7272 | conditional: false
|
7273 | }), state, unmasked, sel.concreteType) : makeProp(schema, sel, state, unmasked);
|
7274 | });
|
7275 | types.push(selectionMapValues);
|
7276 | }
|
7277 |
|
7278 | return unionTypeAnnotation(types.map(function (props) {
|
7279 | if (fragmentTypeName) {
|
7280 | props.push(readOnlyObjectTypeProperty('$refType', t.genericTypeAnnotation(t.identifier(fragmentTypeName))));
|
7281 | }
|
7282 |
|
7283 | return unmasked ? t.objectTypeAnnotation(props) : exactObjectTypeAnnotation(props);
|
7284 | }));
|
7285 | }
|
7286 |
|
7287 | function mergeSelection(a, b) {
|
7288 | var shouldSetConditional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
7289 |
|
7290 | if (!a) {
|
7291 | if (shouldSetConditional) {
|
7292 | return (0, _objectSpread2["default"])({}, b, {
|
7293 | conditional: true
|
7294 | });
|
7295 | }
|
7296 |
|
7297 | return b;
|
7298 | }
|
7299 |
|
7300 | return (0, _objectSpread2["default"])({}, a, {
|
7301 | nodeSelections: a.nodeSelections ? mergeSelections(a.nodeSelections, nullthrows(b.nodeSelections), shouldSetConditional) : null,
|
7302 | conditional: a.conditional && b.conditional
|
7303 | });
|
7304 | }
|
7305 |
|
7306 | function mergeSelections(a, b) {
|
7307 | var shouldSetConditional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
7308 | var merged = new Map();
|
7309 | var _iteratorNormalCompletion = true;
|
7310 | var _didIteratorError = false;
|
7311 | var _iteratorError = undefined;
|
7312 |
|
7313 | try {
|
7314 | for (var _iterator = a.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
7315 | var _step$value = _step.value,
|
7316 | key = _step$value[0],
|
7317 | value = _step$value[1];
|
7318 | merged.set(key, value);
|
7319 | }
|
7320 | } catch (err) {
|
7321 | _didIteratorError = true;
|
7322 | _iteratorError = err;
|
7323 | } finally {
|
7324 | try {
|
7325 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
7326 | _iterator["return"]();
|
7327 | }
|
7328 | } finally {
|
7329 | if (_didIteratorError) {
|
7330 | throw _iteratorError;
|
7331 | }
|
7332 | }
|
7333 | }
|
7334 |
|
7335 | var _iteratorNormalCompletion2 = true;
|
7336 | var _didIteratorError2 = false;
|
7337 | var _iteratorError2 = undefined;
|
7338 |
|
7339 | try {
|
7340 | for (var _iterator2 = b.entries()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
7341 | var _step2$value = _step2.value,
|
7342 | key = _step2$value[0],
|
7343 | value = _step2$value[1];
|
7344 | merged.set(key, mergeSelection(a.get(key), value, shouldSetConditional));
|
7345 | }
|
7346 | } catch (err) {
|
7347 | _didIteratorError2 = true;
|
7348 | _iteratorError2 = err;
|
7349 | } finally {
|
7350 | try {
|
7351 | if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
7352 | _iterator2["return"]();
|
7353 | }
|
7354 | } finally {
|
7355 | if (_didIteratorError2) {
|
7356 | throw _iteratorError2;
|
7357 | }
|
7358 | }
|
7359 | }
|
7360 |
|
7361 | return merged;
|
7362 | }
|
7363 |
|
7364 | function isPlural(node) {
|
7365 | return Boolean(node.metadata && node.metadata.plural);
|
7366 | }
|
7367 |
|
7368 | function createVisitor(schema, options) {
|
7369 | var state = {
|
7370 | customScalars: options.customScalars,
|
7371 | enumsHasteModule: options.enumsHasteModule,
|
7372 | existingFragmentNames: options.existingFragmentNames,
|
7373 | generatedFragments: new Set(),
|
7374 | generatedInputObjectTypes: {},
|
7375 | hasConnectionResolver: false,
|
7376 | optionalInputFields: options.optionalInputFields,
|
7377 | usedEnums: {},
|
7378 | usedFragments: new Set(),
|
7379 | useHaste: options.useHaste,
|
7380 | useSingleArtifactDirectory: options.useSingleArtifactDirectory,
|
7381 | noFutureProofEnums: options.noFutureProofEnums,
|
7382 | matchFields: new Map(),
|
7383 | runtimeImports: new Set()
|
7384 | };
|
7385 | return {
|
7386 | leave: {
|
7387 | Root: function Root(node) {
|
7388 | var inputVariablesType = generateInputVariablesType(schema, node, state);
|
7389 | var inputObjectTypes = generateInputObjectTypes(state);
|
7390 | var responseType = exportType("".concat(node.name, "Response"), selectionsToBabel(schema,
|
7391 | /* $FlowFixMe: selections have already been transformed */
|
7392 | node.selections, state, false));
|
7393 | var operationTypes = [t.objectTypeProperty(t.identifier('variables'), t.genericTypeAnnotation(t.identifier("".concat(node.name, "Variables")))), t.objectTypeProperty(t.identifier('response'), t.genericTypeAnnotation(t.identifier("".concat(node.name, "Response"))))]; // Generate raw response type
|
7394 |
|
7395 | var rawResponseType;
|
7396 | var normalizationIR = options.normalizationIR;
|
7397 |
|
7398 | if (normalizationIR && node.directives.some(function (d) {
|
7399 | return d.name === DIRECTIVE_NAME;
|
7400 | })) {
|
7401 | rawResponseType = IRVisitor.visit(normalizationIR, createRawResponseTypeVisitor(schema, state));
|
7402 | }
|
7403 |
|
7404 | var refetchableFragmentName = getRefetchableQueryParentFragmentName(state, node.metadata);
|
7405 |
|
7406 | if (state.hasConnectionResolver) {
|
7407 | state.runtimeImports.add('ConnectionReference');
|
7408 | }
|
7409 |
|
7410 | if (refetchableFragmentName != null) {
|
7411 | state.runtimeImports.add('FragmentReference');
|
7412 | }
|
7413 |
|
7414 | var babelNodes = [];
|
7415 |
|
7416 | if (state.runtimeImports.size) {
|
7417 | babelNodes.push(importTypes(Array.from(state.runtimeImports).sort(), 'relay-runtime'));
|
7418 | }
|
7419 |
|
7420 | babelNodes.push.apply(babelNodes, (0, _toConsumableArray2["default"])(refetchableFragmentName ? generateFragmentRefsForRefetchable(refetchableFragmentName) : getFragmentImports(state)).concat((0, _toConsumableArray2["default"])(getEnumDefinitions(schema, state)), (0, _toConsumableArray2["default"])(inputObjectTypes), [inputVariablesType, responseType]));
|
7421 |
|
7422 | if (rawResponseType) {
|
7423 | var _iteratorNormalCompletion3 = true;
|
7424 | var _didIteratorError3 = false;
|
7425 | var _iteratorError3 = undefined;
|
7426 |
|
7427 | try {
|
7428 | for (var _iterator3 = state.matchFields[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
7429 | var _step3$value = _step3.value,
|
7430 | key = _step3$value[0],
|
7431 | ast = _step3$value[1];
|
7432 | babelNodes.push(t.typeAlias(t.identifier(key), null, ast));
|
7433 | }
|
7434 | } catch (err) {
|
7435 | _didIteratorError3 = true;
|
7436 | _iteratorError3 = err;
|
7437 | } finally {
|
7438 | try {
|
7439 | if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
|
7440 | _iterator3["return"]();
|
7441 | }
|
7442 | } finally {
|
7443 | if (_didIteratorError3) {
|
7444 | throw _iteratorError3;
|
7445 | }
|
7446 | }
|
7447 | }
|
7448 |
|
7449 | operationTypes.push(t.objectTypeProperty(t.identifier('rawResponse'), t.genericTypeAnnotation(t.identifier("".concat(node.name, "RawResponse")))));
|
7450 | babelNodes.push(rawResponseType);
|
7451 | }
|
7452 |
|
7453 | babelNodes.push(exportType(node.name, exactObjectTypeAnnotation(operationTypes)));
|
7454 | return t.program(babelNodes);
|
7455 | },
|
7456 | Fragment: function Fragment(node) {
|
7457 | var selections = flattenArray(
|
7458 | /* $FlowFixMe: selections have already been transformed */
|
7459 | node.selections);
|
7460 | var numConecreteSelections = selections.filter(function (s) {
|
7461 | return s.concreteType;
|
7462 | }).length;
|
7463 | selections = selections.map(function (selection) {
|
7464 | if (numConecreteSelections <= 1 && isTypenameSelection(selection) && !schema.isAbstractType(node.type)) {
|
7465 | return [(0, _objectSpread2["default"])({}, selection, {
|
7466 | concreteType: schema.getTypeString(node.type)
|
7467 | })];
|
7468 | }
|
7469 |
|
7470 | return [selection];
|
7471 | });
|
7472 | state.generatedFragments.add(node.name);
|
7473 | var fragmentTypes = getFragmentTypes(node.name, getRefetchableQueryPath(state, node.directives));
|
7474 | var refTypeName = getRefTypeName(node.name);
|
7475 | var refTypeDataProperty = readOnlyObjectTypeProperty('$data', t.genericTypeAnnotation(t.identifier("".concat(node.name, "$data"))));
|
7476 | refTypeDataProperty.optional = true;
|
7477 | var refTypeFragmentRefProperty = readOnlyObjectTypeProperty('$fragmentRefs', t.genericTypeAnnotation(t.identifier(getOldFragmentTypeName(node.name))));
|
7478 | var isPluralFragment = isPlural(node);
|
7479 | var refType = t.objectTypeAnnotation([refTypeDataProperty, refTypeFragmentRefProperty]);
|
7480 | var dataTypeName = getDataTypeName(node.name);
|
7481 | var dataType = t.genericTypeAnnotation(t.identifier(node.name));
|
7482 | var unmasked = node.metadata != null && node.metadata.mask === false;
|
7483 | var baseType = selectionsToBabel(schema, selections, state, unmasked, unmasked ? undefined : getOldFragmentTypeName(node.name));
|
7484 | var type = isPluralFragment ? readOnlyArrayOfType(baseType) : baseType;
|
7485 | state.runtimeImports.add('FragmentReference');
|
7486 |
|
7487 | if (state.hasConnectionResolver) {
|
7488 | state.runtimeImports.add('ConnectionReference');
|
7489 | }
|
7490 |
|
7491 | return t.program([].concat((0, _toConsumableArray2["default"])(getFragmentImports(state)), (0, _toConsumableArray2["default"])(getEnumDefinitions(schema, state)), [importTypes(Array.from(state.runtimeImports).sort(), 'relay-runtime')], (0, _toConsumableArray2["default"])(fragmentTypes), [exportType(node.name, type), exportType(dataTypeName, dataType), exportType(refTypeName, isPluralFragment ? readOnlyArrayOfType(refType) : refType)]));
|
7492 | },
|
7493 | InlineFragment: function InlineFragment(node) {
|
7494 | return flattenArray(
|
7495 | /* $FlowFixMe: selections have already been transformed */
|
7496 | node.selections).map(function (typeSelection) {
|
7497 | return schema.isAbstractType(node.typeCondition) ? (0, _objectSpread2["default"])({}, typeSelection, {
|
7498 | conditional: true
|
7499 | }) : (0, _objectSpread2["default"])({}, typeSelection, {
|
7500 | concreteType: schema.getTypeString(node.typeCondition)
|
7501 | });
|
7502 | });
|
7503 | },
|
7504 | Condition: function Condition(node) {
|
7505 | return flattenArray(
|
7506 | /* $FlowFixMe: selections have already been transformed */
|
7507 | node.selections).map(function (selection) {
|
7508 | return (0, _objectSpread2["default"])({}, selection, {
|
7509 | conditional: true
|
7510 | });
|
7511 | });
|
7512 | },
|
7513 | ScalarField: function ScalarField(node) {
|
7514 | return visitScalarField(schema, node, state);
|
7515 | },
|
7516 | Connection: function Connection(node) {
|
7517 | return visitConnection(schema, node, state);
|
7518 | },
|
7519 | ConnectionField: visitLinkedField,
|
7520 | LinkedField: visitLinkedField,
|
7521 | ModuleImport: function ModuleImport(node) {
|
7522 | return [{
|
7523 | key: '__fragmentPropName',
|
7524 | conditional: true,
|
7525 | value: transformScalarType(schema, schema.expectStringType(), state)
|
7526 | }, {
|
7527 | key: '__module_component',
|
7528 | conditional: true,
|
7529 | value: transformScalarType(schema, schema.expectStringType(), state)
|
7530 | }, {
|
7531 | key: '__fragments_' + node.name,
|
7532 | ref: node.name
|
7533 | }];
|
7534 | },
|
7535 | FragmentSpread: function FragmentSpread(node) {
|
7536 | state.usedFragments.add(node.name);
|
7537 | return [{
|
7538 | key: '__fragments_' + node.name,
|
7539 | ref: node.name
|
7540 | }];
|
7541 | }
|
7542 | }
|
7543 | };
|
7544 | }
|
7545 |
|
7546 | function visitNodeWithSelectionsOnly(node) {
|
7547 | return flattenArray(
|
7548 | /* $FlowFixMe: selections have already been transformed */
|
7549 | node.selections);
|
7550 | }
|
7551 |
|
7552 | function visitScalarField(schema, node, state) {
|
7553 | return [{
|
7554 | key: node.alias,
|
7555 | schemaName: node.name,
|
7556 | value: transformScalarType(schema, node.type, state)
|
7557 | }];
|
7558 | }
|
7559 |
|
7560 | function visitConnection(schema, node, state) {
|
7561 | var _ConnectionInterface$ = ConnectionInterface.get(),
|
7562 | EDGES = _ConnectionInterface$.EDGES;
|
7563 |
|
7564 | state.hasConnectionResolver = true;
|
7565 | var edgesSelection = node.selections.find(function (selections) {
|
7566 | var mixedSelections = selections;
|
7567 | return Array.isArray(mixedSelections) && mixedSelections.some(function (selection) {
|
7568 | return selection != null && typeof selection === 'object' && selection.key === EDGES && selection.schemaName === EDGES;
|
7569 | });
|
7570 | });
|
7571 | var edgesItem = Array.isArray(edgesSelection) ? edgesSelection[0] : null;
|
7572 | var nodeSelections = edgesItem != null && typeof edgesItem === 'object' && edgesItem.nodeSelections instanceof Map ? edgesItem.nodeSelections : null;
|
7573 |
|
7574 | if (nodeSelections == null) {
|
7575 | throw createUserError('Cannot generate flow types for connection field, expected an edges ' + 'selection.', [node.loc]);
|
7576 | }
|
7577 |
|
7578 | var edgesFields = Array.from(nodeSelections.values());
|
7579 | var edgesType = selectionsToBabel(schema, [edgesFields], state, false);
|
7580 | return [{
|
7581 | key: '__connection',
|
7582 | conditional: true,
|
7583 | value: t.genericTypeAnnotation(t.identifier('ConnectionReference'), t.typeParameterInstantiation([edgesType]))
|
7584 | }];
|
7585 | }
|
7586 |
|
7587 | function visitLinkedField(node) {
|
7588 | return [{
|
7589 | key: node.alias,
|
7590 | schemaName: node.name,
|
7591 | nodeType: node.type,
|
7592 | nodeSelections: selectionsToMap(flattenArray(
|
7593 | /* $FlowFixMe: selections have already been transformed */
|
7594 | node.selections),
|
7595 | /*
|
7596 | * append concreteType to key so overlapping fields with different
|
7597 | * concreteTypes don't get overwritten by each other
|
7598 | */
|
7599 | true)
|
7600 | }];
|
7601 | }
|
7602 |
|
7603 | function makeRawResponseProp(schema, _ref2, state, concreteType) {
|
7604 | var key = _ref2.key,
|
7605 | schemaName = _ref2.schemaName,
|
7606 | value = _ref2.value,
|
7607 | conditional = _ref2.conditional,
|
7608 | nodeType = _ref2.nodeType,
|
7609 | nodeSelections = _ref2.nodeSelections,
|
7610 | kind = _ref2.kind;
|
7611 |
|
7612 | if (kind === 'ModuleImport') {
|
7613 | return t.objectTypeSpreadProperty(t.genericTypeAnnotation(t.identifier(key)));
|
7614 | }
|
7615 |
|
7616 | if (schemaName === '__typename' && concreteType) {
|
7617 | value = t.stringLiteralTypeAnnotation(concreteType);
|
7618 | } else if (nodeType) {
|
7619 | value = transformScalarType(schema, nodeType, state, selectionsToRawResponseBabel(schema, [Array.from(nullthrows(nodeSelections).values())], state, schema.isAbstractType(nodeType) || schema.isWrapper(nodeType) ? null : schema.getTypeString(nodeType)));
|
7620 | }
|
7621 |
|
7622 | var typeProperty = readOnlyObjectTypeProperty(key, value);
|
7623 |
|
7624 | if (conditional) {
|
7625 | typeProperty.optional = true;
|
7626 | }
|
7627 |
|
7628 | return typeProperty;
|
7629 | } // Trasform the codegen IR selections into Babel flow types
|
7630 |
|
7631 |
|
7632 | function selectionsToRawResponseBabel(schema, selections, state, nodeTypeName) {
|
7633 | var baseFields = [];
|
7634 | var byConcreteType = {};
|
7635 | flattenArray(selections).forEach(function (selection) {
|
7636 | var concreteType = selection.concreteType;
|
7637 |
|
7638 | if (concreteType) {
|
7639 | var _byConcreteType$concr2;
|
7640 |
|
7641 | byConcreteType[concreteType] = (_byConcreteType$concr2 = byConcreteType[concreteType]) !== null && _byConcreteType$concr2 !== void 0 ? _byConcreteType$concr2 : [];
|
7642 | byConcreteType[concreteType].push(selection);
|
7643 | } else {
|
7644 | baseFields.push(selection);
|
7645 | }
|
7646 | });
|
7647 | var types = [];
|
7648 |
|
7649 | if (Object.keys(byConcreteType).length) {
|
7650 | var baseFieldsMap = selectionsToMap(baseFields);
|
7651 |
|
7652 | var _loop2 = function _loop2(concreteType) {
|
7653 | var mergedSeletions = Array.from(mergeSelections(baseFieldsMap, selectionsToMap(byConcreteType[concreteType]), false).values());
|
7654 | var moduleImport = mergedSeletions.find(function (sel) {
|
7655 | return sel.kind === 'ModuleImport';
|
7656 | });
|
7657 |
|
7658 | if (moduleImport) {
|
7659 | types.push(exactObjectTypeAnnotation(mergedSeletions.map(function (selection) {
|
7660 | return makeRawResponseProp(schema, selection, state, concreteType);
|
7661 | }))); // Generate an extra opaque type for client 3D fields
|
7662 |
|
7663 | state.runtimeImports.add('Local3DPayload');
|
7664 | types.push(t.genericTypeAnnotation(t.identifier('Local3DPayload'), t.typeParameterInstantiation([t.stringLiteralTypeAnnotation(moduleImport.documentName), exactObjectTypeAnnotation(mergedSeletions.filter(function (sel) {
|
7665 | return sel.schemaName !== 'js';
|
7666 | }).map(function (selection) {
|
7667 | return makeRawResponseProp(schema, selection, state, concreteType);
|
7668 | }))])));
|
7669 | } else {
|
7670 | types.push(exactObjectTypeAnnotation(mergedSeletions.map(function (selection) {
|
7671 | return makeRawResponseProp(schema, selection, state, concreteType);
|
7672 | })));
|
7673 | }
|
7674 | };
|
7675 |
|
7676 | for (var concreteType in byConcreteType) {
|
7677 | _loop2(concreteType);
|
7678 | }
|
7679 | }
|
7680 |
|
7681 | if (baseFields.length) {
|
7682 | types.push(exactObjectTypeAnnotation(baseFields.map(function (selection) {
|
7683 | return makeRawResponseProp(schema, selection, state, isTypenameSelection(selection) ? nodeTypeName : null);
|
7684 | })));
|
7685 | }
|
7686 |
|
7687 | return unionTypeAnnotation(types);
|
7688 | } // Visitor for generating raw response type
|
7689 |
|
7690 |
|
7691 | function createRawResponseTypeVisitor(schema, state) {
|
7692 | var visitor = {
|
7693 | leave: {
|
7694 | Root: function Root(node) {
|
7695 | return exportType("".concat(node.name, "RawResponse"), selectionsToRawResponseBabel(schema,
|
7696 | /* $FlowFixMe: selections have already been transformed */
|
7697 | node.selections, state, null));
|
7698 | },
|
7699 | InlineFragment: function InlineFragment(node) {
|
7700 | var typeCondition = node.typeCondition;
|
7701 | return flattenArray(
|
7702 | /* $FlowFixMe: selections have already been transformed */
|
7703 | node.selections).map(function (typeSelection) {
|
7704 | return schema.isAbstractType(typeCondition) ? typeSelection : (0, _objectSpread2["default"])({}, typeSelection, {
|
7705 | concreteType: schema.getTypeString(typeCondition)
|
7706 | });
|
7707 | });
|
7708 | },
|
7709 | ScalarField: function ScalarField(node) {
|
7710 | return visitScalarField(schema, node, state);
|
7711 | },
|
7712 | Connection: function Connection(node) {
|
7713 | return visitConnection(schema, node, state);
|
7714 | },
|
7715 | ClientExtension: function ClientExtension(node) {
|
7716 | return flattenArray(
|
7717 | /* $FlowFixMe: selections have already been transformed */
|
7718 | node.selections).map(function (sel) {
|
7719 | return (0, _objectSpread2["default"])({}, sel, {
|
7720 | conditional: true
|
7721 | });
|
7722 | });
|
7723 | },
|
7724 | ConnectionField: visitLinkedField,
|
7725 | LinkedField: visitLinkedField,
|
7726 | Condition: visitNodeWithSelectionsOnly,
|
7727 | Defer: visitNodeWithSelectionsOnly,
|
7728 | Stream: visitNodeWithSelectionsOnly,
|
7729 | ModuleImport: function ModuleImport(node) {
|
7730 | return visitRawResposneModuleImport(schema, node, state);
|
7731 | },
|
7732 | FragmentSpread: function FragmentSpread(node) {
|
7733 | true ? true ? invariant(false, 'A fragment spread is found when traversing the AST, ' + 'make sure you are passing the codegen IR') : undefined : undefined;
|
7734 | }
|
7735 | }
|
7736 | };
|
7737 | return visitor;
|
7738 | } // Dedupe the generated type of module selections to reduce file size
|
7739 |
|
7740 |
|
7741 | function visitRawResposneModuleImport(schema, node, state) {
|
7742 | var selections = node.selections,
|
7743 | key = node.name;
|
7744 | var moduleSelections = selections.filter( // $FlowFixMe selections have already been transformed
|
7745 | function (sel) {
|
7746 | return sel.length && sel[0].schemaName === 'js';
|
7747 | }).map(function (arr) {
|
7748 | return arr[0];
|
7749 | });
|
7750 |
|
7751 | if (!state.matchFields.has(key)) {
|
7752 | var ast = selectionsToRawResponseBabel(schema,
|
7753 | /* $FlowFixMe: selections have already been transformed */
|
7754 | node.selections.filter(function (sel) {
|
7755 | return sel.length > 1 || sel[0].schemaName !== 'js';
|
7756 | }), state, null);
|
7757 | state.matchFields.set(key, ast);
|
7758 | }
|
7759 |
|
7760 | return [].concat((0, _toConsumableArray2["default"])(moduleSelections), [{
|
7761 | key: key,
|
7762 | kind: 'ModuleImport',
|
7763 | documentName: node.documentName
|
7764 | }]);
|
7765 | }
|
7766 |
|
7767 | function selectionsToMap(selections, appendType) {
|
7768 | var map = new Map();
|
7769 | selections.forEach(function (selection) {
|
7770 | var key = appendType && selection.concreteType ? "".concat(selection.key, "::").concat(selection.concreteType) : selection.key;
|
7771 | var previousSel = map.get(key);
|
7772 | map.set(key, previousSel ? mergeSelection(previousSel, selection) : selection);
|
7773 | });
|
7774 | return map;
|
7775 | }
|
7776 |
|
7777 | function flattenArray(arrayOfArrays) {
|
7778 | var result = [];
|
7779 | arrayOfArrays.forEach(function (array) {
|
7780 | result.push.apply(result, (0, _toConsumableArray2["default"])(array));
|
7781 | });
|
7782 | return result;
|
7783 | }
|
7784 |
|
7785 | function generateInputObjectTypes(state) {
|
7786 | return Object.keys(state.generatedInputObjectTypes).map(function (typeIdentifier) {
|
7787 | var inputObjectType = state.generatedInputObjectTypes[typeIdentifier];
|
7788 | !(typeof inputObjectType !== 'string') ? true ? invariant(false, 'RelayCompilerFlowGenerator: Expected input object type to have been' + ' defined before calling `generateInputObjectTypes`') : undefined : void 0;
|
7789 | return exportType(typeIdentifier, inputObjectType);
|
7790 | });
|
7791 | }
|
7792 |
|
7793 | function generateInputVariablesType(schema, node, state) {
|
7794 | return exportType("".concat(node.name, "Variables"), exactObjectTypeAnnotation(node.argumentDefinitions.map(function (arg) {
|
7795 | var property = t.objectTypeProperty(t.identifier(arg.name), transformInputType(schema, arg.type, state));
|
7796 |
|
7797 | if (!schema.isNonNull(arg.type)) {
|
7798 | property.optional = true;
|
7799 | }
|
7800 |
|
7801 | return property;
|
7802 | })));
|
7803 | }
|
7804 |
|
7805 | function groupRefs(props) {
|
7806 | var result = [];
|
7807 | var refs = [];
|
7808 | props.forEach(function (prop) {
|
7809 | if (prop.ref) {
|
7810 | refs.push(prop.ref);
|
7811 | } else {
|
7812 | result.push(prop);
|
7813 | }
|
7814 | });
|
7815 |
|
7816 | if (refs.length > 0) {
|
7817 | var value = intersectionTypeAnnotation(refs.map(function (ref) {
|
7818 | return t.genericTypeAnnotation(t.identifier(getOldFragmentTypeName(ref)));
|
7819 | }));
|
7820 | result.push({
|
7821 | key: '$fragmentRefs',
|
7822 | conditional: false,
|
7823 | value: value
|
7824 | });
|
7825 | }
|
7826 |
|
7827 | return result;
|
7828 | }
|
7829 |
|
7830 | function getFragmentImports(state) {
|
7831 | var imports = [];
|
7832 |
|
7833 | if (state.usedFragments.size > 0) {
|
7834 | var usedFragments = Array.from(state.usedFragments).sort();
|
7835 | var _iteratorNormalCompletion4 = true;
|
7836 | var _didIteratorError4 = false;
|
7837 | var _iteratorError4 = undefined;
|
7838 |
|
7839 | try {
|
7840 | for (var _iterator4 = usedFragments[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
7841 | var usedFragment = _step4.value;
|
7842 | var fragmentTypeName = getOldFragmentTypeName(usedFragment);
|
7843 |
|
7844 | if (!state.generatedFragments.has(usedFragment)) {
|
7845 | if (state.useHaste && state.existingFragmentNames.has(usedFragment)) {
|
7846 | // TODO(T22653277) support non-haste environments when importing
|
7847 | // fragments
|
7848 | imports.push(importTypes([fragmentTypeName], usedFragment + '.graphql'));
|
7849 | } else if (state.useSingleArtifactDirectory && state.existingFragmentNames.has(usedFragment)) {
|
7850 | imports.push(importTypes([fragmentTypeName], './' + usedFragment + '.graphql'));
|
7851 | } else {
|
7852 | imports.push(anyTypeAlias(fragmentTypeName));
|
7853 | }
|
7854 | }
|
7855 | }
|
7856 | } catch (err) {
|
7857 | _didIteratorError4 = true;
|
7858 | _iteratorError4 = err;
|
7859 | } finally {
|
7860 | try {
|
7861 | if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
|
7862 | _iterator4["return"]();
|
7863 | }
|
7864 | } finally {
|
7865 | if (_didIteratorError4) {
|
7866 | throw _iteratorError4;
|
7867 | }
|
7868 | }
|
7869 | }
|
7870 | }
|
7871 |
|
7872 | return imports;
|
7873 | }
|
7874 |
|
7875 | function getEnumDefinitions(schema, _ref3) {
|
7876 | var enumsHasteModule = _ref3.enumsHasteModule,
|
7877 | usedEnums = _ref3.usedEnums,
|
7878 | noFutureProofEnums = _ref3.noFutureProofEnums;
|
7879 | var enumNames = Object.keys(usedEnums).sort();
|
7880 |
|
7881 | if (enumNames.length === 0) {
|
7882 | return [];
|
7883 | }
|
7884 |
|
7885 | if (typeof enumsHasteModule === 'string') {
|
7886 | return [importTypes(enumNames, enumsHasteModule)];
|
7887 | }
|
7888 |
|
7889 | if (typeof enumsHasteModule === 'function') {
|
7890 | return enumNames.map(function (enumName) {
|
7891 | return importTypes([enumName], enumsHasteModule(enumName));
|
7892 | });
|
7893 | }
|
7894 |
|
7895 | return enumNames.map(function (name) {
|
7896 | var values = [].concat(schema.getEnumValues(usedEnums[name]));
|
7897 | values.sort();
|
7898 |
|
7899 | if (!noFutureProofEnums) {
|
7900 | values.push('%future added value');
|
7901 | }
|
7902 |
|
7903 | return exportType(name, t.unionTypeAnnotation(values.map(function (value) {
|
7904 | return t.stringLiteralTypeAnnotation(value);
|
7905 | })));
|
7906 | });
|
7907 | } // If it's a @refetchable fragment, we generate the $fragmentRef in generated
|
7908 | // query, and import it in the fragment to avoid circular dependencies
|
7909 |
|
7910 |
|
7911 | function getRefetchableQueryParentFragmentName(state, metadata) {
|
7912 | if (!(metadata === null || metadata === void 0 ? void 0 : metadata.isRefetchableQuery) || !state.useHaste && !state.useSingleArtifactDirectory) {
|
7913 | return null;
|
7914 | }
|
7915 |
|
7916 | var derivedFrom = metadata === null || metadata === void 0 ? void 0 : metadata.derivedFrom;
|
7917 |
|
7918 | if (derivedFrom != null && typeof derivedFrom === 'string') {
|
7919 | return derivedFrom;
|
7920 | }
|
7921 |
|
7922 | return null;
|
7923 | }
|
7924 |
|
7925 | function getRefetchableQueryPath(state, directives) {
|
7926 | var _directives$find;
|
7927 |
|
7928 | var refetchableQuery;
|
7929 |
|
7930 | if (!state.useHaste && !state.useSingleArtifactDirectory) {
|
7931 | return;
|
7932 | }
|
7933 |
|
7934 | var refetchableArgs = (_directives$find = directives.find(function (d) {
|
7935 | return d.name === 'refetchable';
|
7936 | })) === null || _directives$find === void 0 ? void 0 : _directives$find.args;
|
7937 |
|
7938 | if (!refetchableArgs) {
|
7939 | return;
|
7940 | }
|
7941 |
|
7942 | var argument = refetchableArgs.find(function (arg) {
|
7943 | return arg.kind === 'Argument' && arg.name === 'queryName';
|
7944 | });
|
7945 |
|
7946 | if (argument && argument.value && argument.value.kind === 'Literal' && typeof argument.value.value === 'string') {
|
7947 | refetchableQuery = argument.value.value;
|
7948 |
|
7949 | if (!state.useHaste) {
|
7950 | refetchableQuery = './' + refetchableQuery;
|
7951 | }
|
7952 |
|
7953 | refetchableQuery += '.graphql';
|
7954 | }
|
7955 |
|
7956 | return refetchableQuery;
|
7957 | }
|
7958 |
|
7959 | function generateFragmentRefsForRefetchable(name) {
|
7960 | var oldFragmentTypeName = getOldFragmentTypeName(name);
|
7961 | var newFragmentTypeName = getNewFragmentTypeName(name);
|
7962 | return [declareExportOpaqueType(oldFragmentTypeName, 'FragmentReference'), declareExportOpaqueType(newFragmentTypeName, oldFragmentTypeName)];
|
7963 | }
|
7964 |
|
7965 | function getFragmentTypes(name, refetchableQueryPath) {
|
7966 | var oldFragmentTypeName = getOldFragmentTypeName(name);
|
7967 | var newFragmentTypeName = getNewFragmentTypeName(name);
|
7968 |
|
7969 | if (refetchableQueryPath) {
|
7970 | return [importTypes([oldFragmentTypeName, newFragmentTypeName], refetchableQueryPath), exportTypes([oldFragmentTypeName, newFragmentTypeName])];
|
7971 | }
|
7972 |
|
7973 | return [declareExportOpaqueType(oldFragmentTypeName, 'FragmentReference'), declareExportOpaqueType(newFragmentTypeName, oldFragmentTypeName)];
|
7974 | }
|
7975 |
|
7976 | function getOldFragmentTypeName(name) {
|
7977 | return "".concat(name, "$ref");
|
7978 | }
|
7979 |
|
7980 | function getNewFragmentTypeName(name) {
|
7981 | return "".concat(name, "$fragmentType");
|
7982 | }
|
7983 |
|
7984 | function getRefTypeName(name) {
|
7985 | return "".concat(name, "$key");
|
7986 | }
|
7987 |
|
7988 | function getDataTypeName(name) {
|
7989 | return "".concat(name, "$data");
|
7990 | }
|
7991 |
|
7992 | var FLOW_TRANSFORMS = [RelayDirectiveTransform.transform, MaskTransform.transform, ConnectionFieldTransform.transform, MatchTransform.transform, FlattenTransform.transformWithOptions({}), RefetchableFragmentTransform.transform];
|
7993 | var DIRECTIVE_NAME = 'raw_response_type';
|
7994 | module.exports = {
|
7995 | generate: Profiler.instrument(generate, 'RelayFlowGenerator.generate'),
|
7996 | transforms: FLOW_TRANSFORMS,
|
7997 | SCHEMA_EXTENSION: "directive @".concat(DIRECTIVE_NAME, " on QUERY | MUTATION | SUBSCRIPTION")
|
7998 | };
|
7999 |
|
8000 | /***/ }),
|
8001 | /* 45 */
|
8002 | /***/ (function(module, exports, __webpack_require__) {
|
8003 |
|
8004 | "use strict";
|
8005 | /**
|
8006 | * Copyright (c) Facebook, Inc. and its affiliates.
|
8007 | *
|
8008 | * This source code is licensed under the MIT license found in the
|
8009 | * LICENSE file in the root directory of this source tree.
|
8010 | *
|
8011 | *
|
8012 | * @format
|
8013 | */
|
8014 |
|
8015 |
|
8016 | var invariant = __webpack_require__(4);
|
8017 |
|
8018 | var t = __webpack_require__(22);
|
8019 |
|
8020 | /**
|
8021 | * type NAME = any;
|
8022 | */
|
8023 | function anyTypeAlias(name) {
|
8024 | return t.typeAlias(t.identifier(name), null, t.anyTypeAnnotation());
|
8025 | }
|
8026 | /**
|
8027 | * {|
|
8028 | * PROPS
|
8029 | * |}
|
8030 | */
|
8031 |
|
8032 |
|
8033 | function exactObjectTypeAnnotation(props) {
|
8034 | var typeAnnotation = t.objectTypeAnnotation(props);
|
8035 | typeAnnotation.exact = true;
|
8036 | return typeAnnotation;
|
8037 | }
|
8038 | /**
|
8039 | * export type NAME = TYPE
|
8040 | */
|
8041 |
|
8042 |
|
8043 | function exportType(name, type) {
|
8044 | return t.exportNamedDeclaration(t.typeAlias(t.identifier(name), null, type), [], null);
|
8045 | }
|
8046 | /**
|
8047 | * export type {A, B, C}
|
8048 | */
|
8049 |
|
8050 |
|
8051 | function exportTypes(names) {
|
8052 | var res = t.exportNamedDeclaration(null, names.map(function (name) {
|
8053 | return t.exportSpecifier(t.identifier(name), t.identifier(name));
|
8054 | }), null);
|
8055 | res.exportKind = 'type';
|
8056 | return res;
|
8057 | }
|
8058 | /**
|
8059 | * declare export type NAME = VALUE
|
8060 | */
|
8061 |
|
8062 |
|
8063 | function declareExportOpaqueType(name, value) {
|
8064 | return t.declareExportDeclaration(t.declareOpaqueType(t.identifier(name), null, t.genericTypeAnnotation(t.identifier(value))));
|
8065 | }
|
8066 | /**
|
8067 | * import type {NAMES[0], NAMES[1], ...} from 'MODULE';
|
8068 | */
|
8069 |
|
8070 |
|
8071 | function importTypes(names, module) {
|
8072 | var importDeclaration = t.importDeclaration(names.map(function (name) {
|
8073 | return t.importSpecifier(t.identifier(name), t.identifier(name));
|
8074 | }), t.stringLiteral(module));
|
8075 | importDeclaration.importKind = 'type';
|
8076 | return importDeclaration;
|
8077 | }
|
8078 | /**
|
8079 | * Create an intersection type if needed.
|
8080 | *
|
8081 | * TYPES[0] & TYPES[1] & ...
|
8082 | */
|
8083 |
|
8084 |
|
8085 | function intersectionTypeAnnotation(types) {
|
8086 | !(types.length > 0) ? true ? invariant(false, 'RelayFlowBabelFactories: cannot create an intersection of 0 types') : undefined : void 0;
|
8087 | return types.length === 1 ? types[0] : t.intersectionTypeAnnotation(types);
|
8088 | }
|
8089 |
|
8090 | function lineComments() {
|
8091 | for (var _len = arguments.length, lines = new Array(_len), _key = 0; _key < _len; _key++) {
|
8092 | lines[_key] = arguments[_key];
|
8093 | }
|
8094 |
|
8095 | return lines.map(function (line) {
|
8096 | return {
|
8097 | type: 'CommentLine',
|
8098 | value: ' ' + line
|
8099 | };
|
8100 | });
|
8101 | }
|
8102 | /**
|
8103 | * $ReadOnlyArray<TYPE>
|
8104 | */
|
8105 |
|
8106 |
|
8107 | function readOnlyArrayOfType(thing) {
|
8108 | return t.genericTypeAnnotation(t.identifier('$ReadOnlyArray'), t.typeParameterInstantiation([thing]));
|
8109 | }
|
8110 | /**
|
8111 | * +KEY: VALUE
|
8112 | */
|
8113 |
|
8114 |
|
8115 | function readOnlyObjectTypeProperty(key, value) {
|
8116 | var prop = t.objectTypeProperty(t.identifier(key), value);
|
8117 | prop.variance = t.variance('plus');
|
8118 | return prop;
|
8119 | }
|
8120 |
|
8121 | function stringLiteralTypeAnnotation(value) {
|
8122 | return t.stringLiteralTypeAnnotation(value);
|
8123 | }
|
8124 | /**
|
8125 | * Create a union type if needed.
|
8126 | *
|
8127 | * TYPES[0] | TYPES[1] | ...
|
8128 | */
|
8129 |
|
8130 |
|
8131 | function unionTypeAnnotation(types) {
|
8132 | !(types.length > 0) ? true ? invariant(false, 'RelayFlowBabelFactories: cannot create a union of 0 types') : undefined : void 0;
|
8133 | return types.length === 1 ? types[0] : t.unionTypeAnnotation(types);
|
8134 | }
|
8135 |
|
8136 | module.exports = {
|
8137 | anyTypeAlias: anyTypeAlias,
|
8138 | declareExportOpaqueType: declareExportOpaqueType,
|
8139 | exactObjectTypeAnnotation: exactObjectTypeAnnotation,
|
8140 | exportType: exportType,
|
8141 | exportTypes: exportTypes,
|
8142 | importTypes: importTypes,
|
8143 | intersectionTypeAnnotation: intersectionTypeAnnotation,
|
8144 | lineComments: lineComments,
|
8145 | readOnlyArrayOfType: readOnlyArrayOfType,
|
8146 | readOnlyObjectTypeProperty: readOnlyObjectTypeProperty,
|
8147 | stringLiteralTypeAnnotation: stringLiteralTypeAnnotation,
|
8148 | unionTypeAnnotation: unionTypeAnnotation
|
8149 | };
|
8150 |
|
8151 | /***/ }),
|
8152 | /* 46 */
|
8153 | /***/ (function(module, exports, __webpack_require__) {
|
8154 |
|
8155 | "use strict";
|
8156 | /**
|
8157 | * Copyright (c) Facebook, Inc. and its affiliates.
|
8158 | *
|
8159 | * This source code is licensed under the MIT license found in the
|
8160 | * LICENSE file in the root directory of this source tree.
|
8161 | *
|
8162 | *
|
8163 | * @format
|
8164 | */
|
8165 |
|
8166 |
|
8167 | var invariant = __webpack_require__(4);
|
8168 |
|
8169 | var _require = __webpack_require__(1),
|
8170 | eachWithCombinedError = _require.eachWithCombinedError;
|
8171 |
|
8172 | /**
|
8173 | * @public
|
8174 | *
|
8175 | * Helper for writing AST validators that shares the same logic with
|
8176 | * the transfomer
|
8177 | *
|
8178 | */
|
8179 | function validate(context, visitor, stateInitializer) {
|
8180 | var validator = new Validator(context, visitor);
|
8181 | eachWithCombinedError(context.documents(), function (prevNode) {
|
8182 | if (stateInitializer === undefined) {
|
8183 | validator.visit(prevNode, undefined);
|
8184 | } else {
|
8185 | var _state = stateInitializer(prevNode);
|
8186 |
|
8187 | if (_state != null) {
|
8188 | validator.visit(prevNode, _state);
|
8189 | }
|
8190 | }
|
8191 | });
|
8192 | }
|
8193 | /**
|
8194 | * @internal
|
8195 | */
|
8196 |
|
8197 |
|
8198 | var Validator =
|
8199 | /*#__PURE__*/
|
8200 | function () {
|
8201 | function Validator(context, visitor) {
|
8202 | this._context = context;
|
8203 | this._states = [];
|
8204 | this._visitor = visitor;
|
8205 | }
|
8206 |
|
8207 | var _proto = Validator.prototype;
|
8208 |
|
8209 | _proto.getContext = function getContext() {
|
8210 | return this._context;
|
8211 | };
|
8212 |
|
8213 | _proto.visit = function visit(node, state) {
|
8214 | this._states.push(state);
|
8215 |
|
8216 | this._visit(node);
|
8217 |
|
8218 | this._states.pop();
|
8219 | };
|
8220 |
|
8221 | _proto.traverse = function traverse(node, state) {
|
8222 | this._states.push(state);
|
8223 |
|
8224 | this._traverse(node);
|
8225 |
|
8226 | this._states.pop();
|
8227 | };
|
8228 |
|
8229 | _proto._visit = function _visit(node) {
|
8230 | var nodeVisitor = this._visitor[node.kind];
|
8231 |
|
8232 | if (nodeVisitor) {
|
8233 | // If a handler for the kind is defined, it is responsible for calling
|
8234 | // `traverse` to transform children as necessary.
|
8235 | var _state2 = this._getState();
|
8236 |
|
8237 | nodeVisitor.call(this, node, _state2);
|
8238 | return;
|
8239 | } // Otherwise traverse is called automatically.
|
8240 |
|
8241 |
|
8242 | this._traverse(node);
|
8243 | };
|
8244 |
|
8245 | _proto._traverse = function _traverse(prevNode) {
|
8246 | switch (prevNode.kind) {
|
8247 | case 'Argument':
|
8248 | this._traverseChildren(prevNode, null, ['value']);
|
8249 |
|
8250 | break;
|
8251 |
|
8252 | case 'Literal':
|
8253 | case 'LocalArgumentDefinition':
|
8254 | case 'RootArgumentDefinition':
|
8255 | case 'Variable':
|
8256 | break;
|
8257 |
|
8258 | case 'Defer':
|
8259 | this._traverseChildren(prevNode, ['selections'], ['if']);
|
8260 |
|
8261 | break;
|
8262 |
|
8263 | case 'Stream':
|
8264 | this._traverseChildren(prevNode, ['selections'], ['if', 'initialCount']);
|
8265 |
|
8266 | break;
|
8267 |
|
8268 | case 'ClientExtension':
|
8269 | this._traverseChildren(prevNode, ['selections']);
|
8270 |
|
8271 | break;
|
8272 |
|
8273 | case 'Directive':
|
8274 | this._traverseChildren(prevNode, ['args']);
|
8275 |
|
8276 | break;
|
8277 |
|
8278 | case 'ModuleImport':
|
8279 | this._traverseChildren(prevNode, ['selections']);
|
8280 |
|
8281 | break;
|
8282 |
|
8283 | case 'FragmentSpread':
|
8284 | case 'ScalarField':
|
8285 | this._traverseChildren(prevNode, ['args', 'directives']);
|
8286 |
|
8287 | break;
|
8288 |
|
8289 | case 'InlineDataFragmentSpread':
|
8290 | this._traverseChildren(prevNode, ['selections']);
|
8291 |
|
8292 | break;
|
8293 |
|
8294 | case 'ConnectionField':
|
8295 | case 'LinkedField':
|
8296 | this._traverseChildren(prevNode, ['args', 'directives', 'selections']);
|
8297 |
|
8298 | break;
|
8299 |
|
8300 | case 'Connection':
|
8301 | this._traverseChildren(prevNode, ['args', 'selections']);
|
8302 |
|
8303 | break;
|
8304 |
|
8305 | case 'Condition':
|
8306 | this._traverseChildren(prevNode, ['directives', 'selections'], ['condition']);
|
8307 |
|
8308 | break;
|
8309 |
|
8310 | case 'InlineFragment':
|
8311 | this._traverseChildren(prevNode, ['directives', 'selections']);
|
8312 |
|
8313 | break;
|
8314 |
|
8315 | case 'Fragment':
|
8316 | case 'Root':
|
8317 | this._traverseChildren(prevNode, ['argumentDefinitions', 'directives', 'selections']);
|
8318 |
|
8319 | break;
|
8320 |
|
8321 | case 'Request':
|
8322 | this._traverseChildren(prevNode, null, ['fragment', 'root']);
|
8323 |
|
8324 | break;
|
8325 |
|
8326 | case 'SplitOperation':
|
8327 | this._traverseChildren(prevNode, ['selections']);
|
8328 |
|
8329 | break;
|
8330 |
|
8331 | default:
|
8332 | prevNode;
|
8333 | true ? true ? invariant(false, 'GraphQLIRValidator: Unknown kind `%s`.', prevNode.kind) : undefined : undefined;
|
8334 | }
|
8335 | };
|
8336 |
|
8337 | _proto._traverseChildren = function _traverseChildren(prevNode, pluralKeys, singularKeys) {
|
8338 | var _this = this;
|
8339 |
|
8340 | pluralKeys && pluralKeys.forEach(function (key) {
|
8341 | var prevItems = prevNode[key];
|
8342 |
|
8343 | if (!prevItems) {
|
8344 | return;
|
8345 | }
|
8346 |
|
8347 | !Array.isArray(prevItems) ? true ? invariant(false, 'GraphQLIRValidator: Expected data for `%s` to be an array, got `%s`.', key, prevItems) : undefined : void 0;
|
8348 | prevItems.forEach(function (prevItem) {
|
8349 | return _this._visit(prevItem);
|
8350 | });
|
8351 | });
|
8352 | singularKeys && singularKeys.forEach(function (key) {
|
8353 | var prevItem = prevNode[key];
|
8354 |
|
8355 | if (!prevItem) {
|
8356 | return;
|
8357 | }
|
8358 |
|
8359 | _this._visit(prevItem);
|
8360 | });
|
8361 | };
|
8362 |
|
8363 | _proto._getState = function _getState() {
|
8364 | !this._states.length ? true ? invariant(false, 'GraphQLIRValidator: Expected a current state to be set but found none. ' + 'This is usually the result of mismatched number of pushState()/popState() ' + 'calls.') : undefined : void 0;
|
8365 | return this._states[this._states.length - 1];
|
8366 | };
|
8367 |
|
8368 | return Validator;
|
8369 | }();
|
8370 |
|
8371 | module.exports = {
|
8372 | validate: validate
|
8373 | };
|
8374 |
|
8375 | /***/ }),
|
8376 | /* 47 */
|
8377 | /***/ (function(module, exports) {
|
8378 |
|
8379 | module.exports = require("util");
|
8380 |
|
8381 | /***/ }),
|
8382 | /* 48 */
|
8383 | /***/ (function(module, exports, __webpack_require__) {
|
8384 |
|
8385 | "use strict";
|
8386 | /**
|
8387 | * Copyright (c) Facebook, Inc. and its affiliates.
|
8388 | *
|
8389 | * This source code is licensed under the MIT license found in the
|
8390 | * LICENSE file in the root directory of this source tree.
|
8391 | *
|
8392 | *
|
8393 | * @format
|
8394 | */
|
8395 |
|
8396 |
|
8397 | var yargs = __webpack_require__(49);
|
8398 |
|
8399 | var _require = __webpack_require__(50),
|
8400 | main = _require.main;
|
8401 |
|
8402 | var RelayConfig;
|
8403 |
|
8404 | try {
|
8405 | // eslint-disable-next-line no-eval
|
8406 | RelayConfig = eval('require')('relay-config'); // eslint-disable-next-line lint/no-unused-catch-bindings
|
8407 | } catch (_) {}
|
8408 |
|
8409 | var options = {
|
8410 | schema: {
|
8411 | describe: 'Path to schema.graphql or schema.json',
|
8412 | demandOption: true,
|
8413 | type: 'string',
|
8414 | array: false
|
8415 | },
|
8416 | src: {
|
8417 | describe: 'Root directory of application code',
|
8418 | demandOption: true,
|
8419 | type: 'string',
|
8420 | array: false
|
8421 | },
|
8422 | include: {
|
8423 | describe: 'Directories to include under src',
|
8424 | type: 'string',
|
8425 | array: true,
|
8426 | "default": ['**']
|
8427 | },
|
8428 | exclude: {
|
8429 | describe: 'Directories to ignore under src',
|
8430 | type: 'string',
|
8431 | array: true,
|
8432 | "default": ['**/node_modules/**', '**/__mocks__/**', '**/__generated__/**']
|
8433 | },
|
8434 | extensions: {
|
8435 | array: true,
|
8436 | describe: 'File extensions to compile (defaults to extensions provided by the ' + 'language plugin)',
|
8437 | type: 'string'
|
8438 | },
|
8439 | verbose: {
|
8440 | describe: 'More verbose logging',
|
8441 | type: 'boolean',
|
8442 | "default": false
|
8443 | },
|
8444 | quiet: {
|
8445 | describe: 'No output to stdout',
|
8446 | type: 'boolean',
|
8447 | "default": false
|
8448 | },
|
8449 | watchman: {
|
8450 | describe: 'Use watchman when not in watch mode',
|
8451 | type: 'boolean',
|
8452 | "default": true
|
8453 | },
|
8454 | watch: {
|
8455 | describe: 'If specified, watches files and regenerates on changes',
|
8456 | type: 'boolean',
|
8457 | "default": false
|
8458 | },
|
8459 | validate: {
|
8460 | describe: 'Looks for pending changes and exits with non-zero code instead of ' + 'writing to disk',
|
8461 | type: 'boolean',
|
8462 | "default": false
|
8463 | },
|
8464 | persistFunction: {
|
8465 | describe: 'An async function (or path to a module exporting this function) which will persist the query text and return the id.',
|
8466 | demandOption: false,
|
8467 | type: 'string',
|
8468 | array: false
|
8469 | },
|
8470 | persistOutput: {
|
8471 | describe: 'A path to a .json file where persisted query metadata should be saved. Will use the default implementation (md5 hash) if `persistFunction` is not passed.',
|
8472 | demandOption: false,
|
8473 | type: 'string',
|
8474 | array: false
|
8475 | },
|
8476 | noFutureProofEnums: {
|
8477 | describe: 'This option controls whether or not a catch-all entry is added to enum type definitions ' + 'for values that may be added in the future. Enabling this means you will have to update ' + 'your application whenever the GraphQL server schema adds new enum values to prevent it ' + 'from breaking.',
|
8478 | type: 'boolean',
|
8479 | "default": false
|
8480 | },
|
8481 | language: {
|
8482 | describe: 'The name of the language plugin used for input files and artifacts',
|
8483 | demandOption: false,
|
8484 | type: 'string',
|
8485 | array: false,
|
8486 | "default": 'javascript'
|
8487 | },
|
8488 | artifactDirectory: {
|
8489 | describe: 'A specific directory to output all artifacts to. When enabling this ' + 'the babel plugin needs `artifactDirectory` set as well.',
|
8490 | demandOption: false,
|
8491 | type: 'string',
|
8492 | array: false
|
8493 | },
|
8494 | customScalars: {
|
8495 | describe: 'Mappings from custom scalars in your schema to built-in GraphQL ' + 'types, for type emission purposes. (Uses yargs dot-notation, e.g. ' + '--customScalars.URL=String)',
|
8496 | type: 'object'
|
8497 | }
|
8498 | }; // Load external config
|
8499 |
|
8500 | var config = RelayConfig && RelayConfig.loadConfig(); // Parse CLI args
|
8501 |
|
8502 | var argv = yargs.usage('Create Relay generated files\n\n' + '$0 --schema <path> --src <path> [--watch]') // $FlowFixMe - TODO @alloy (OSS): Fix non-existent 'object' type for parsing customScalars config
|
8503 | .options(options) // Apply externally loaded config through the yargs API so that we can leverage yargs' defaults and have them show up
|
8504 | // in the help banner.
|
8505 | .config(config).help().argv; // Start the application
|
8506 |
|
8507 | main(argv)["catch"](function (error) {
|
8508 | console.error(String(error.stack || error));
|
8509 | process.exit(1);
|
8510 | });
|
8511 |
|
8512 | /***/ }),
|
8513 | /* 49 */
|
8514 | /***/ (function(module, exports) {
|
8515 |
|
8516 | module.exports = require("yargs");
|
8517 |
|
8518 | /***/ }),
|
8519 | /* 50 */
|
8520 | /***/ (function(module, exports, __webpack_require__) {
|
8521 |
|
8522 | "use strict";
|
8523 | /**
|
8524 | * Copyright (c) Facebook, Inc. and its affiliates.
|
8525 | *
|
8526 | * This source code is licensed under the MIT license found in the
|
8527 | * LICENSE file in the root directory of this source tree.
|
8528 | *
|
8529 | *
|
8530 | * @format
|
8531 | */
|
8532 |
|
8533 |
|
8534 | var _interopRequireDefault = __webpack_require__(0);
|
8535 |
|
8536 | var _asyncToGenerator = __webpack_require__(10);
|
8537 |
|
8538 | var _defineProperty2 = _interopRequireDefault(__webpack_require__(23));
|
8539 |
|
8540 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
8541 |
|
8542 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
8543 |
|
8544 | var CodegenRunner = __webpack_require__(51);
|
8545 |
|
8546 | var ConsoleReporter = __webpack_require__(58);
|
8547 |
|
8548 | var DotGraphQLParser = __webpack_require__(60);
|
8549 |
|
8550 | var RelayFileWriter = __webpack_require__(61);
|
8551 |
|
8552 | var RelayIRTransforms = __webpack_require__(72);
|
8553 |
|
8554 | var RelayLanguagePluginJavaScript = __webpack_require__(104);
|
8555 |
|
8556 | var RelaySourceModuleParser = __webpack_require__(108);
|
8557 |
|
8558 | var WatchmanClient = __webpack_require__(18);
|
8559 |
|
8560 | var crypto = __webpack_require__(12);
|
8561 |
|
8562 | var fs = __webpack_require__(13);
|
8563 |
|
8564 | var invariant = __webpack_require__(4);
|
8565 |
|
8566 | var path = __webpack_require__(8);
|
8567 |
|
8568 | var _require = __webpack_require__(7),
|
8569 | buildClientSchema = _require.buildClientSchema,
|
8570 | Source = _require.Source,
|
8571 | printSchema = _require.printSchema;
|
8572 |
|
8573 | var commonTransforms = RelayIRTransforms.commonTransforms,
|
8574 | codegenTransforms = RelayIRTransforms.codegenTransforms,
|
8575 | fragmentTransforms = RelayIRTransforms.fragmentTransforms,
|
8576 | printTransforms = RelayIRTransforms.printTransforms,
|
8577 | queryTransforms = RelayIRTransforms.queryTransforms,
|
8578 | schemaExtensions = RelayIRTransforms.schemaExtensions;
|
8579 |
|
8580 | function buildWatchExpression(config) {
|
8581 | return ['allof', ['type', 'f'], ['anyof'].concat((0, _toConsumableArray2["default"])(config.extensions.map(function (ext) {
|
8582 | return ['suffix', ext];
|
8583 | }))), ['anyof'].concat((0, _toConsumableArray2["default"])(config.include.map(function (include) {
|
8584 | return ['match', include, 'wholename'];
|
8585 | })))].concat((0, _toConsumableArray2["default"])(config.exclude.map(function (exclude) {
|
8586 | return ['not', ['match', exclude, 'wholename']];
|
8587 | })));
|
8588 | }
|
8589 |
|
8590 | function getFilepathsFromGlob(baseDir, config) {
|
8591 | var extensions = config.extensions,
|
8592 | include = config.include,
|
8593 | exclude = config.exclude;
|
8594 | var patterns = include.map(function (inc) {
|
8595 | return "".concat(inc, "/*.+(").concat(extensions.join('|'), ")");
|
8596 | });
|
8597 |
|
8598 | var glob = __webpack_require__(113);
|
8599 |
|
8600 | return glob.sync(patterns, {
|
8601 | cwd: baseDir,
|
8602 | ignore: exclude
|
8603 | });
|
8604 | }
|
8605 |
|
8606 | /**
|
8607 | * Unless the requested plugin is the builtin `javascript` one, import a
|
8608 | * language plugin as either a CommonJS or ES2015 module.
|
8609 | *
|
8610 | * When importing, first check if it’s a path to an existing file, otherwise
|
8611 | * assume it’s a package and prepend the plugin namespace prefix.
|
8612 | *
|
8613 | * Make sure to always use Node's `require` function, which otherwise would get
|
8614 | * replaced with `__webpack_require__` when bundled using webpack, by using
|
8615 | * `eval` to get it at runtime.
|
8616 | */
|
8617 | function getLanguagePlugin(language) {
|
8618 | if (language === 'javascript') {
|
8619 | return RelayLanguagePluginJavaScript();
|
8620 | } else {
|
8621 | var languagePlugin;
|
8622 |
|
8623 | if (typeof language === 'string') {
|
8624 | var pluginPath = path.resolve(process.cwd(), language);
|
8625 | var requirePath = fs.existsSync(pluginPath) ? pluginPath : "relay-compiler-language-".concat(language);
|
8626 |
|
8627 | try {
|
8628 | // eslint-disable-next-line no-eval
|
8629 | languagePlugin = eval('require')(requirePath);
|
8630 |
|
8631 | if (languagePlugin["default"]) {
|
8632 | languagePlugin = languagePlugin["default"];
|
8633 | }
|
8634 | } catch (err) {
|
8635 | var e = new Error("Unable to load language plugin ".concat(requirePath, ": ").concat(err.message));
|
8636 | e.stack = err.stack;
|
8637 | throw e;
|
8638 | }
|
8639 | } else {
|
8640 | languagePlugin = language;
|
8641 | }
|
8642 |
|
8643 | if (languagePlugin["default"] != null) {
|
8644 | // $FlowFixMe - Flow no longer considers statics of functions as any
|
8645 | languagePlugin = languagePlugin["default"];
|
8646 | }
|
8647 |
|
8648 | if (typeof languagePlugin === 'function') {
|
8649 | // $FlowFixMe
|
8650 | return languagePlugin();
|
8651 | } else {
|
8652 | throw new Error('Expected plugin to be a initializer function.');
|
8653 | }
|
8654 | }
|
8655 | }
|
8656 |
|
8657 | function getPersistQueryFunction(config) {
|
8658 | var configValue = config.persistFunction;
|
8659 |
|
8660 | if (configValue == null) {
|
8661 | return null;
|
8662 | } else if (typeof configValue === 'string') {
|
8663 | try {
|
8664 | // eslint-disable-next-line no-eval
|
8665 | var persistFunction = eval('require')(path.resolve(process.cwd(), configValue));
|
8666 |
|
8667 | if (persistFunction["default"]) {
|
8668 | return persistFunction["default"];
|
8669 | }
|
8670 |
|
8671 | return persistFunction;
|
8672 | } catch (err) {
|
8673 | var e = new Error("Unable to load persistFunction ".concat(configValue, ": ").concat(err.message));
|
8674 | e.stack = err.stack;
|
8675 | throw e;
|
8676 | }
|
8677 | } else if (typeof configValue === 'function') {
|
8678 | return configValue;
|
8679 | } else {
|
8680 | throw new Error('Expected persistFunction to be a path string or a function.');
|
8681 | }
|
8682 | }
|
8683 |
|
8684 | function main(_x) {
|
8685 | return _main.apply(this, arguments);
|
8686 | }
|
8687 |
|
8688 | function _main() {
|
8689 | _main = _asyncToGenerator(function* (defaultConfig) {
|
8690 | if (defaultConfig.verbose && defaultConfig.quiet) {
|
8691 | throw new Error("I can't be quiet and verbose at the same time");
|
8692 | }
|
8693 |
|
8694 | var config = getPathBasedConfig(defaultConfig);
|
8695 | config = yield getWatchConfig(config); // Use function from module.exports to be able to mock it for tests
|
8696 |
|
8697 | var codegenRunner = module.exports.getCodegenRunner(config);
|
8698 | var result = config.watch ? yield codegenRunner.watchAll() : yield codegenRunner.compileAll();
|
8699 |
|
8700 | if (result === 'ERROR') {
|
8701 | process.exit(100);
|
8702 | }
|
8703 |
|
8704 | if (config.validate && result !== 'NO_CHANGES') {
|
8705 | process.exit(101);
|
8706 | }
|
8707 | });
|
8708 | return _main.apply(this, arguments);
|
8709 | }
|
8710 |
|
8711 | function getPathBasedConfig(config) {
|
8712 | var schema = path.resolve(process.cwd(), config.schema);
|
8713 |
|
8714 | if (!fs.existsSync(schema)) {
|
8715 | throw new Error("--schema path does not exist: ".concat(schema));
|
8716 | }
|
8717 |
|
8718 | var src = path.resolve(process.cwd(), config.src);
|
8719 |
|
8720 | if (!fs.existsSync(src)) {
|
8721 | throw new Error("--src path does not exist: ".concat(src));
|
8722 | }
|
8723 |
|
8724 | var persistOutput = config.persistOutput;
|
8725 |
|
8726 | if (typeof persistOutput === 'string') {
|
8727 | persistOutput = path.resolve(process.cwd(), persistOutput);
|
8728 | var persistOutputDir = path.dirname(persistOutput);
|
8729 |
|
8730 | if (!fs.existsSync(persistOutputDir)) {
|
8731 | throw new Error("--persistOutput path does not exist: ".concat(persistOutput));
|
8732 | }
|
8733 | }
|
8734 |
|
8735 | return (0, _objectSpread2["default"])({}, config, {
|
8736 | schema: schema,
|
8737 | src: src,
|
8738 | persistOutput: persistOutput
|
8739 | });
|
8740 | }
|
8741 |
|
8742 | function getWatchConfig(_x2) {
|
8743 | return _getWatchConfig.apply(this, arguments);
|
8744 | }
|
8745 |
|
8746 | function _getWatchConfig() {
|
8747 | _getWatchConfig = _asyncToGenerator(function* (config) {
|
8748 | var watchman = config.watchman && (yield WatchmanClient.isAvailable());
|
8749 |
|
8750 | if (config.watch) {
|
8751 | if (!watchman) {
|
8752 | throw new Error('Watchman is required to watch for changes.');
|
8753 | }
|
8754 |
|
8755 | if (!module.exports.hasWatchmanRootFile(config.src)) {
|
8756 | throw new Error("\n--watch requires that the src directory have a valid watchman \"root\" file.\n\nRoot files can include:\n- A .git/ Git folder\n- A .hg/ Mercurial folder\n- A .watchmanconfig file\n\nEnsure that one such file exists in ".concat(config.src, " or its parents.\n ").trim());
|
8757 | }
|
8758 | } else if (watchman && !config.validate) {
|
8759 | // eslint-disable-next-line no-console
|
8760 | console.log('HINT: pass --watch to keep watching for changes.');
|
8761 | }
|
8762 |
|
8763 | return (0, _objectSpread2["default"])({}, config, {
|
8764 | watchman: watchman
|
8765 | });
|
8766 | });
|
8767 | return _getWatchConfig.apply(this, arguments);
|
8768 | }
|
8769 |
|
8770 | function getCodegenRunner(config) {
|
8771 | var _artifactDirectory, _parserConfigs;
|
8772 |
|
8773 | var reporter = new ConsoleReporter({
|
8774 | verbose: config.verbose,
|
8775 | quiet: config.quiet
|
8776 | });
|
8777 | var schema = getSchemaSource(config.schema);
|
8778 | var languagePlugin = getLanguagePlugin(config.language);
|
8779 | var persistQueryFunction = getPersistQueryFunction(config);
|
8780 | var inputExtensions = config.extensions || languagePlugin.inputExtensions;
|
8781 | var outputExtension = languagePlugin.outputExtension;
|
8782 | var sourceParserName = inputExtensions.join('/');
|
8783 | var sourceWriterName = outputExtension;
|
8784 | var sourceModuleParser = RelaySourceModuleParser(languagePlugin.findGraphQLTags);
|
8785 | var providedArtifactDirectory = config.artifactDirectory;
|
8786 | var artifactDirectory = providedArtifactDirectory != null ? path.resolve(process.cwd(), providedArtifactDirectory) : null;
|
8787 | var generatedDirectoryName = (_artifactDirectory = artifactDirectory) !== null && _artifactDirectory !== void 0 ? _artifactDirectory : '__generated__';
|
8788 | var sourceSearchOptions = {
|
8789 | extensions: inputExtensions,
|
8790 | include: config.include,
|
8791 | exclude: ['**/*.graphql.*'].concat((0, _toConsumableArray2["default"])(config.exclude))
|
8792 | };
|
8793 | var graphqlSearchOptions = {
|
8794 | extensions: ['graphql'],
|
8795 | include: config.include,
|
8796 | exclude: [path.relative(config.src, config.schema)].concat(config.exclude)
|
8797 | };
|
8798 | var parserConfigs = (_parserConfigs = {}, (0, _defineProperty2["default"])(_parserConfigs, sourceParserName, {
|
8799 | baseDir: config.src,
|
8800 | getFileFilter: sourceModuleParser.getFileFilter,
|
8801 | getParser: sourceModuleParser.getParser,
|
8802 | getSchemaSource: function getSchemaSource() {
|
8803 | return schema;
|
8804 | },
|
8805 | schemaExtensions: schemaExtensions,
|
8806 | watchmanExpression: config.watchman ? buildWatchExpression(sourceSearchOptions) : null,
|
8807 | filepaths: config.watchman ? null : getFilepathsFromGlob(config.src, sourceSearchOptions)
|
8808 | }), (0, _defineProperty2["default"])(_parserConfigs, "graphql", {
|
8809 | baseDir: config.src,
|
8810 | getParser: DotGraphQLParser.getParser,
|
8811 | getSchemaSource: function getSchemaSource() {
|
8812 | return schema;
|
8813 | },
|
8814 | schemaExtensions: schemaExtensions,
|
8815 | watchmanExpression: config.watchman ? buildWatchExpression(graphqlSearchOptions) : null,
|
8816 | filepaths: config.watchman ? null : getFilepathsFromGlob(config.src, graphqlSearchOptions)
|
8817 | }), _parserConfigs);
|
8818 | var writerConfigs = (0, _defineProperty2["default"])({}, sourceWriterName, {
|
8819 | writeFiles: getRelayFileWriter(config.src, languagePlugin, config.noFutureProofEnums, artifactDirectory, config.persistOutput, config.customScalars, persistQueryFunction),
|
8820 | isGeneratedFile: function isGeneratedFile(filePath) {
|
8821 | return filePath.endsWith('.graphql.' + outputExtension) && filePath.includes(generatedDirectoryName);
|
8822 | },
|
8823 | parser: sourceParserName,
|
8824 | baseParsers: ['graphql']
|
8825 | });
|
8826 | var codegenRunner = new CodegenRunner({
|
8827 | reporter: reporter,
|
8828 | parserConfigs: parserConfigs,
|
8829 | writerConfigs: writerConfigs,
|
8830 | onlyValidate: config.validate,
|
8831 | // TODO: allow passing in a flag or detect?
|
8832 | sourceControl: null
|
8833 | });
|
8834 | return codegenRunner;
|
8835 | }
|
8836 |
|
8837 | function defaultPersistFunction(text) {
|
8838 | var hasher = crypto.createHash('md5');
|
8839 | hasher.update(text);
|
8840 | var id = hasher.digest('hex');
|
8841 | return Promise.resolve(id);
|
8842 | }
|
8843 |
|
8844 | function getRelayFileWriter(baseDir, languagePlugin, noFutureProofEnums, outputDir, persistedQueryPath, customScalars, persistFunction) {
|
8845 | return (
|
8846 | /*#__PURE__*/
|
8847 | function () {
|
8848 | var _ref2 = _asyncToGenerator(function* (_ref) {
|
8849 | var onlyValidate = _ref.onlyValidate,
|
8850 | schema = _ref.schema,
|
8851 | documents = _ref.documents,
|
8852 | baseDocuments = _ref.baseDocuments,
|
8853 | sourceControl = _ref.sourceControl,
|
8854 | reporter = _ref.reporter;
|
8855 | var persistQuery;
|
8856 | var queryMap;
|
8857 |
|
8858 | if (persistFunction != null || persistedQueryPath != null) {
|
8859 | queryMap = new Map();
|
8860 | var persistImplmentation = persistFunction || defaultPersistFunction;
|
8861 |
|
8862 | persistQuery =
|
8863 | /*#__PURE__*/
|
8864 | function () {
|
8865 | var _persistQuery = _asyncToGenerator(function* (text) {
|
8866 | var id = yield persistImplmentation(text);
|
8867 | !(typeof id === 'string') ? true ? invariant(false, 'Expected persist function to return a string, got `%s`.', id) : undefined : void 0;
|
8868 | queryMap.set(id, text);
|
8869 | return id;
|
8870 | });
|
8871 |
|
8872 | function persistQuery(_x4) {
|
8873 | return _persistQuery.apply(this, arguments);
|
8874 | }
|
8875 |
|
8876 | return persistQuery;
|
8877 | }();
|
8878 | }
|
8879 |
|
8880 | var results = yield RelayFileWriter.writeAll({
|
8881 | config: {
|
8882 | baseDir: baseDir,
|
8883 | compilerTransforms: {
|
8884 | commonTransforms: commonTransforms,
|
8885 | codegenTransforms: codegenTransforms,
|
8886 | fragmentTransforms: fragmentTransforms,
|
8887 | printTransforms: printTransforms,
|
8888 | queryTransforms: queryTransforms
|
8889 | },
|
8890 | customScalars: customScalars || {},
|
8891 | formatModule: languagePlugin.formatModule,
|
8892 | optionalInputFieldsForFlow: [],
|
8893 | schemaExtensions: schemaExtensions,
|
8894 | useHaste: false,
|
8895 | noFutureProofEnums: noFutureProofEnums,
|
8896 | extension: languagePlugin.outputExtension,
|
8897 | typeGenerator: languagePlugin.typeGenerator,
|
8898 | outputDir: outputDir,
|
8899 | persistQuery: persistQuery
|
8900 | },
|
8901 | onlyValidate: onlyValidate,
|
8902 | schema: schema,
|
8903 | baseDocuments: baseDocuments,
|
8904 | documents: documents,
|
8905 | reporter: reporter,
|
8906 | sourceControl: sourceControl
|
8907 | });
|
8908 |
|
8909 | if (queryMap != null && persistedQueryPath != null) {
|
8910 | var object = {};
|
8911 |
|
8912 | if (fs.existsSync(persistedQueryPath)) {
|
8913 | try {
|
8914 | var prevText = fs.readFileSync(persistedQueryPath, 'utf8');
|
8915 | var prevData = JSON.parse(prevText);
|
8916 |
|
8917 | if (prevData != null && typeof prevData === 'object') {
|
8918 | object = prevData;
|
8919 | } else {
|
8920 | console.error("Invalid data in persisted query file '".concat(persistedQueryPath, "', expected an object."));
|
8921 | }
|
8922 | } catch (error) {
|
8923 | console.error(error);
|
8924 | }
|
8925 | }
|
8926 |
|
8927 | var _iteratorNormalCompletion = true;
|
8928 | var _didIteratorError = false;
|
8929 | var _iteratorError = undefined;
|
8930 |
|
8931 | try {
|
8932 | for (var _iterator = queryMap.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
8933 | var _step$value = _step.value,
|
8934 | id = _step$value[0],
|
8935 | _text = _step$value[1];
|
8936 | object[id] = _text;
|
8937 | }
|
8938 | } catch (err) {
|
8939 | _didIteratorError = true;
|
8940 | _iteratorError = err;
|
8941 | } finally {
|
8942 | try {
|
8943 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
8944 | _iterator["return"]();
|
8945 | }
|
8946 | } finally {
|
8947 | if (_didIteratorError) {
|
8948 | throw _iteratorError;
|
8949 | }
|
8950 | }
|
8951 | }
|
8952 |
|
8953 | var data = JSON.stringify(object, null, 2);
|
8954 | fs.writeFileSync(persistedQueryPath, data, 'utf8');
|
8955 | }
|
8956 |
|
8957 | return results;
|
8958 | });
|
8959 |
|
8960 | return function (_x3) {
|
8961 | return _ref2.apply(this, arguments);
|
8962 | };
|
8963 | }()
|
8964 | );
|
8965 | }
|
8966 |
|
8967 | function getSchemaSource(schemaPath) {
|
8968 | var source = fs.readFileSync(schemaPath, 'utf8');
|
8969 |
|
8970 | if (path.extname(schemaPath) === '.json') {
|
8971 | source = printSchema(buildClientSchema(JSON.parse(source).data));
|
8972 | }
|
8973 |
|
8974 | source = "\n directive @include(if: Boolean) on FRAGMENT_SPREAD | FIELD | INLINE_FRAGMENT\n directive @skip(if: Boolean) on FRAGMENT_SPREAD | FIELD | INLINE_FRAGMENT\n\n ".concat(source, "\n ");
|
8975 | return new Source(source, schemaPath);
|
8976 | } // Ensure that a watchman "root" file exists in the given directory
|
8977 | // or a parent so that it can be watched
|
8978 |
|
8979 |
|
8980 | var WATCHMAN_ROOT_FILES = ['.git', '.hg', '.watchmanconfig'];
|
8981 |
|
8982 | function hasWatchmanRootFile(testPath) {
|
8983 | while (path.dirname(testPath) !== testPath) {
|
8984 | if (WATCHMAN_ROOT_FILES.some(function (file) {
|
8985 | return fs.existsSync(path.join(testPath, file));
|
8986 | })) {
|
8987 | return true;
|
8988 | }
|
8989 |
|
8990 | testPath = path.dirname(testPath);
|
8991 | }
|
8992 |
|
8993 | return false;
|
8994 | }
|
8995 |
|
8996 | module.exports = {
|
8997 | getCodegenRunner: getCodegenRunner,
|
8998 | getLanguagePlugin: getLanguagePlugin,
|
8999 | getWatchConfig: getWatchConfig,
|
9000 | hasWatchmanRootFile: hasWatchmanRootFile,
|
9001 | main: main
|
9002 | };
|
9003 |
|
9004 | /***/ }),
|
9005 | /* 51 */
|
9006 | /***/ (function(module, exports, __webpack_require__) {
|
9007 |
|
9008 | "use strict";
|
9009 | /**
|
9010 | * Copyright (c) Facebook, Inc. and its affiliates.
|
9011 | *
|
9012 | * This source code is licensed under the MIT license found in the
|
9013 | * LICENSE file in the root directory of this source tree.
|
9014 | *
|
9015 | *
|
9016 | * @format
|
9017 | */
|
9018 |
|
9019 |
|
9020 | var _interopRequireDefault = __webpack_require__(0);
|
9021 |
|
9022 | var _asyncToGenerator = __webpack_require__(10);
|
9023 |
|
9024 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
9025 |
|
9026 | var CodegenDirectory = __webpack_require__(24);
|
9027 |
|
9028 | var CodegenWatcher = __webpack_require__(52);
|
9029 |
|
9030 | var GraphQLWatchmanClient = __webpack_require__(18);
|
9031 |
|
9032 | var Profiler = __webpack_require__(6);
|
9033 |
|
9034 | var invariant = __webpack_require__(4);
|
9035 |
|
9036 | var path = __webpack_require__(8);
|
9037 |
|
9038 | var _require = __webpack_require__(55),
|
9039 | createSchema = _require.create; // $FlowFixMe - importing immutable, which is untyped (and flow is sad about it)
|
9040 |
|
9041 |
|
9042 | var _require2 = __webpack_require__(14),
|
9043 | ImmutableMap = _require2.Map;
|
9044 |
|
9045 | var CodegenRunner =
|
9046 | /*#__PURE__*/
|
9047 | function () {
|
9048 | // parser => writers that are affected by it
|
9049 | function CodegenRunner(options) {
|
9050 | var _this = this;
|
9051 |
|
9052 | this.parsers = {};
|
9053 | this.parserConfigs = options.parserConfigs;
|
9054 | this.writerConfigs = options.writerConfigs;
|
9055 | this.onlyValidate = options.onlyValidate;
|
9056 | this.onComplete = options.onComplete;
|
9057 | this._reporter = options.reporter;
|
9058 | this._sourceControl = options.sourceControl;
|
9059 | this.parserWriters = {};
|
9060 |
|
9061 | for (var _parser in options.parserConfigs) {
|
9062 | this.parserWriters[_parser] = new Set();
|
9063 | }
|
9064 |
|
9065 | var _loop = function _loop(_writer) {
|
9066 | var config = options.writerConfigs[_writer];
|
9067 | config.baseParsers && config.baseParsers.forEach(function (parser) {
|
9068 | return _this.parserWriters[parser].add(_writer);
|
9069 | });
|
9070 |
|
9071 | _this.parserWriters[config.parser].add(_writer);
|
9072 | };
|
9073 |
|
9074 | for (var _writer in options.writerConfigs) {
|
9075 | _loop(_writer);
|
9076 | }
|
9077 | }
|
9078 |
|
9079 | var _proto = CodegenRunner.prototype;
|
9080 |
|
9081 | _proto.compileAll =
|
9082 | /*#__PURE__*/
|
9083 | function () {
|
9084 | var _compileAll = _asyncToGenerator(function* () {
|
9085 | // reset the parsers
|
9086 | this.parsers = {};
|
9087 |
|
9088 | for (var parserName in this.parserConfigs) {
|
9089 | try {
|
9090 | yield this.parseEverything(parserName);
|
9091 | } catch (e) {
|
9092 | this._reporter.reportError('CodegenRunner.compileAll', e);
|
9093 |
|
9094 | return 'ERROR';
|
9095 | }
|
9096 | }
|
9097 |
|
9098 | var hasChanges = false;
|
9099 |
|
9100 | for (var writerName in this.writerConfigs) {
|
9101 | var result = yield this.write(writerName);
|
9102 |
|
9103 | if (result === 'ERROR') {
|
9104 | return 'ERROR';
|
9105 | }
|
9106 |
|
9107 | if (result === 'HAS_CHANGES') {
|
9108 | hasChanges = true;
|
9109 | }
|
9110 | }
|
9111 |
|
9112 | return hasChanges ? 'HAS_CHANGES' : 'NO_CHANGES';
|
9113 | });
|
9114 |
|
9115 | function compileAll() {
|
9116 | return _compileAll.apply(this, arguments);
|
9117 | }
|
9118 |
|
9119 | return compileAll;
|
9120 | }();
|
9121 |
|
9122 | _proto.compile =
|
9123 | /*#__PURE__*/
|
9124 | function () {
|
9125 | var _compile = _asyncToGenerator(function* (writerName) {
|
9126 | var _this2 = this;
|
9127 |
|
9128 | var writerConfig = this.writerConfigs[writerName];
|
9129 | var parsers = [writerConfig.parser];
|
9130 |
|
9131 | if (writerConfig.baseParsers) {
|
9132 | writerConfig.baseParsers.forEach(function (parser) {
|
9133 | return parsers.push(parser);
|
9134 | });
|
9135 | } // Don't bother resetting the parsers
|
9136 |
|
9137 |
|
9138 | yield Profiler.asyncContext('CodegenRunner:parseEverything', function () {
|
9139 | return Promise.all(parsers.map(function (parser) {
|
9140 | return _this2.parseEverything(parser);
|
9141 | }));
|
9142 | });
|
9143 | return yield this.write(writerName);
|
9144 | });
|
9145 |
|
9146 | function compile(_x) {
|
9147 | return _compile.apply(this, arguments);
|
9148 | }
|
9149 |
|
9150 | return compile;
|
9151 | }();
|
9152 |
|
9153 | _proto.getDirtyWriters = function getDirtyWriters(filePaths) {
|
9154 | var _this3 = this;
|
9155 |
|
9156 | return Profiler.asyncContext('CodegenRunner:getDirtyWriters',
|
9157 | /*#__PURE__*/
|
9158 | _asyncToGenerator(function* () {
|
9159 | var dirtyWriters = new Set(); // Check if any files are in the output
|
9160 |
|
9161 | for (var configName in _this3.writerConfigs) {
|
9162 | var config = _this3.writerConfigs[configName];
|
9163 | var _iteratorNormalCompletion = true;
|
9164 | var _didIteratorError = false;
|
9165 | var _iteratorError = undefined;
|
9166 |
|
9167 | try {
|
9168 | for (var _iterator = filePaths[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
9169 | var _filePath = _step.value;
|
9170 |
|
9171 | if (config.isGeneratedFile(_filePath)) {
|
9172 | dirtyWriters.add(configName);
|
9173 | }
|
9174 | }
|
9175 | } catch (err) {
|
9176 | _didIteratorError = true;
|
9177 | _iteratorError = err;
|
9178 | } finally {
|
9179 | try {
|
9180 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
9181 | _iterator["return"]();
|
9182 | }
|
9183 | } finally {
|
9184 | if (_didIteratorError) {
|
9185 | throw _iteratorError;
|
9186 | }
|
9187 | }
|
9188 | }
|
9189 | } // Check for files in the input
|
9190 |
|
9191 |
|
9192 | yield Promise.all(Object.keys(_this3.parserConfigs).map(function (parserConfigName) {
|
9193 | return Profiler.waitFor('Watchman:query',
|
9194 | /*#__PURE__*/
|
9195 | _asyncToGenerator(function* () {
|
9196 | var client = new GraphQLWatchmanClient();
|
9197 | var config = _this3.parserConfigs[parserConfigName];
|
9198 | var dirs = yield client.watchProject(config.baseDir);
|
9199 | var relativeFilePaths = filePaths.map(function (filePath) {
|
9200 | return path.relative(config.baseDir, filePath);
|
9201 | });
|
9202 | var query = {
|
9203 | expression: ['allof', config.watchmanExpression, ['name', relativeFilePaths, 'wholename']],
|
9204 | fields: ['exists'],
|
9205 | relative_root: dirs.relativePath
|
9206 | };
|
9207 | var result = yield client.command('query', dirs.root, query);
|
9208 | client.end();
|
9209 |
|
9210 | if (result.files.length > 0) {
|
9211 | _this3.parserWriters[parserConfigName].forEach(function (writerName) {
|
9212 | return dirtyWriters.add(writerName);
|
9213 | });
|
9214 | }
|
9215 | }));
|
9216 | }));
|
9217 | return dirtyWriters;
|
9218 | }));
|
9219 | };
|
9220 |
|
9221 | _proto.parseEverything =
|
9222 | /*#__PURE__*/
|
9223 | function () {
|
9224 | var _parseEverything = _asyncToGenerator(function* (parserName) {
|
9225 | if (this.parsers[parserName]) {
|
9226 | // no need to parse
|
9227 | return;
|
9228 | }
|
9229 |
|
9230 | var parserConfig = this.parserConfigs[parserName];
|
9231 | this.parsers[parserName] = parserConfig.getParser(parserConfig.baseDir);
|
9232 | var filter = parserConfig.getFileFilter ? parserConfig.getFileFilter(parserConfig.baseDir) : anyFileFilter;
|
9233 |
|
9234 | if (parserConfig.filepaths && parserConfig.watchmanExpression) {
|
9235 | throw new Error('Provide either `watchmanExpression` or `filepaths` but not both.');
|
9236 | }
|
9237 |
|
9238 | var files;
|
9239 |
|
9240 | if (parserConfig.watchmanExpression) {
|
9241 | files = yield CodegenWatcher.queryFiles(parserConfig.baseDir, parserConfig.watchmanExpression, filter);
|
9242 | } else if (parserConfig.filepaths) {
|
9243 | files = yield CodegenWatcher.queryFilepaths(parserConfig.baseDir, parserConfig.filepaths, filter);
|
9244 | } else {
|
9245 | throw new Error('Either `watchmanExpression` or `filepaths` is required to query files');
|
9246 | }
|
9247 |
|
9248 | this.parseFileChanges(parserName, files);
|
9249 | });
|
9250 |
|
9251 | function parseEverything(_x2) {
|
9252 | return _parseEverything.apply(this, arguments);
|
9253 | }
|
9254 |
|
9255 | return parseEverything;
|
9256 | }();
|
9257 |
|
9258 | _proto.parseFileChanges = function parseFileChanges(parserName, files) {
|
9259 | var _this4 = this;
|
9260 |
|
9261 | return Profiler.run('CodegenRunner.parseFileChanges', function () {
|
9262 | var parser = _this4.parsers[parserName]; // this maybe should be await parser.parseFiles(files);
|
9263 |
|
9264 | parser.parseFiles(files);
|
9265 | });
|
9266 | } // We cannot do incremental writes right now.
|
9267 | // When we can, this could be writeChanges(writerName, parserName, parsedDefinitions)
|
9268 | ;
|
9269 |
|
9270 | _proto.write = function write(writerName) {
|
9271 | var _this5 = this;
|
9272 |
|
9273 | return Profiler.asyncContext('CodegenRunner.write',
|
9274 | /*#__PURE__*/
|
9275 | _asyncToGenerator(function* () {
|
9276 | try {
|
9277 | _this5._reporter.reportMessage("\nWriting ".concat(writerName));
|
9278 |
|
9279 | var _this5$writerConfigs$ = _this5.writerConfigs[writerName],
|
9280 | writeFiles = _this5$writerConfigs$.writeFiles,
|
9281 | _parser2 = _this5$writerConfigs$.parser,
|
9282 | baseParsers = _this5$writerConfigs$.baseParsers,
|
9283 | isGeneratedFile = _this5$writerConfigs$.isGeneratedFile;
|
9284 | var baseDocuments = ImmutableMap();
|
9285 |
|
9286 | if (baseParsers) {
|
9287 | baseParsers.forEach(function (baseParserName) {
|
9288 | !(_this5.parsers[baseParserName] != null) ? true ? invariant(false, 'Trying to access an uncompiled base parser config: %s', baseParserName) : undefined : void 0;
|
9289 | baseDocuments = baseDocuments.merge(_this5.parsers[baseParserName].documents());
|
9290 | });
|
9291 | }
|
9292 |
|
9293 | var _this5$parserConfigs$ = _this5.parserConfigs[_parser2],
|
9294 | _baseDir = _this5$parserConfigs$.baseDir,
|
9295 | generatedDirectoriesWatchmanExpression = _this5$parserConfigs$.generatedDirectoriesWatchmanExpression;
|
9296 | var generatedDirectories = [];
|
9297 |
|
9298 | if (generatedDirectoriesWatchmanExpression) {
|
9299 | var relativePaths = yield CodegenWatcher.queryDirectories(_baseDir, generatedDirectoriesWatchmanExpression);
|
9300 | generatedDirectories = relativePaths.map(function (x) {
|
9301 | return path.join(_baseDir, x);
|
9302 | });
|
9303 | } // always create a new writer: we have to write everything anyways
|
9304 |
|
9305 |
|
9306 | var documents = _this5.parsers[_parser2].documents();
|
9307 |
|
9308 | var schema = Profiler.run('getSchema', function () {
|
9309 | return createSchema(_this5.parserConfigs[_parser2].getSchemaSource(), baseDocuments.toArray(), _this5.parserConfigs[_parser2].schemaExtensions);
|
9310 | });
|
9311 | var outputDirectories = yield writeFiles({
|
9312 | onlyValidate: _this5.onlyValidate,
|
9313 | schema: schema,
|
9314 | documents: documents,
|
9315 | baseDocuments: baseDocuments,
|
9316 | generatedDirectories: generatedDirectories,
|
9317 | sourceControl: _this5._sourceControl,
|
9318 | reporter: _this5._reporter
|
9319 | });
|
9320 | var _iteratorNormalCompletion2 = true;
|
9321 | var _didIteratorError2 = false;
|
9322 | var _iteratorError2 = undefined;
|
9323 |
|
9324 | try {
|
9325 | for (var _iterator2 = outputDirectories.values()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
9326 | var dir = _step2.value;
|
9327 | var all = [].concat((0, _toConsumableArray2["default"])(dir.changes.created), (0, _toConsumableArray2["default"])(dir.changes.updated), (0, _toConsumableArray2["default"])(dir.changes.deleted), (0, _toConsumableArray2["default"])(dir.changes.unchanged));
|
9328 | var _iteratorNormalCompletion3 = true;
|
9329 | var _didIteratorError3 = false;
|
9330 | var _iteratorError3 = undefined;
|
9331 |
|
9332 | try {
|
9333 | for (var _iterator3 = all[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
9334 | var filename = _step3.value;
|
9335 |
|
9336 | var _filePath2 = dir.getPath(filename);
|
9337 |
|
9338 | !isGeneratedFile(_filePath2) ? true ? invariant(false, 'CodegenRunner: %s returned false for isGeneratedFile, ' + 'but was in generated directory', _filePath2) : undefined : void 0;
|
9339 | }
|
9340 | } catch (err) {
|
9341 | _didIteratorError3 = true;
|
9342 | _iteratorError3 = err;
|
9343 | } finally {
|
9344 | try {
|
9345 | if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
|
9346 | _iterator3["return"]();
|
9347 | }
|
9348 | } finally {
|
9349 | if (_didIteratorError3) {
|
9350 | throw _iteratorError3;
|
9351 | }
|
9352 | }
|
9353 | }
|
9354 | }
|
9355 | } catch (err) {
|
9356 | _didIteratorError2 = true;
|
9357 | _iteratorError2 = err;
|
9358 | } finally {
|
9359 | try {
|
9360 | if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
9361 | _iterator2["return"]();
|
9362 | }
|
9363 | } finally {
|
9364 | if (_didIteratorError2) {
|
9365 | throw _iteratorError2;
|
9366 | }
|
9367 | }
|
9368 | }
|
9369 |
|
9370 | var onCompleteCallback = _this5.onComplete;
|
9371 |
|
9372 | if (onCompleteCallback != null) {
|
9373 | onCompleteCallback(Array.from(outputDirectories.values()));
|
9374 | }
|
9375 |
|
9376 | var combinedChanges = CodegenDirectory.combineChanges(Array.from(outputDirectories.values()));
|
9377 |
|
9378 | _this5._reporter.reportMessage(CodegenDirectory.formatChanges(combinedChanges, {
|
9379 | onlyValidate: _this5.onlyValidate
|
9380 | }));
|
9381 |
|
9382 | return CodegenDirectory.hasChanges(combinedChanges) ? 'HAS_CHANGES' : 'NO_CHANGES';
|
9383 | } catch (e) {
|
9384 | _this5._reporter.reportError('CodegenRunner.write', e);
|
9385 |
|
9386 | return 'ERROR';
|
9387 | }
|
9388 | }));
|
9389 | };
|
9390 |
|
9391 | _proto.watchAll =
|
9392 | /*#__PURE__*/
|
9393 | function () {
|
9394 | var _watchAll = _asyncToGenerator(function* () {
|
9395 | // get everything set up for watching
|
9396 | yield this.compileAll();
|
9397 |
|
9398 | for (var parserName in this.parserConfigs) {
|
9399 | yield this.watch(parserName);
|
9400 | }
|
9401 | });
|
9402 |
|
9403 | function watchAll() {
|
9404 | return _watchAll.apply(this, arguments);
|
9405 | }
|
9406 |
|
9407 | return watchAll;
|
9408 | }();
|
9409 |
|
9410 | _proto.watch =
|
9411 | /*#__PURE__*/
|
9412 | function () {
|
9413 | var _watch = _asyncToGenerator(function* (parserName) {
|
9414 | var _this6 = this;
|
9415 |
|
9416 | var parserConfig = this.parserConfigs[parserName];
|
9417 |
|
9418 | if (!parserConfig.watchmanExpression) {
|
9419 | throw new Error('`watchmanExpression` is required to watch files');
|
9420 | } // watchCompile starts with a full set of files as the changes
|
9421 | // But as we need to set everything up due to potential parser dependencies,
|
9422 | // we should prevent the first watch callback from doing anything.
|
9423 |
|
9424 |
|
9425 | var firstChange = true;
|
9426 | yield CodegenWatcher.watchCompile(parserConfig.baseDir, parserConfig.watchmanExpression, parserConfig.getFileFilter ? parserConfig.getFileFilter(parserConfig.baseDir) : anyFileFilter,
|
9427 | /*#__PURE__*/
|
9428 | function () {
|
9429 | var _ref4 = _asyncToGenerator(function* (files) {
|
9430 | !(_this6.parsers[parserName] != null) ? true ? invariant(false, 'Trying to watch an uncompiled parser config: %s', parserName) : undefined : void 0;
|
9431 |
|
9432 | if (firstChange) {
|
9433 | firstChange = false;
|
9434 | return;
|
9435 | }
|
9436 |
|
9437 | var dependentWriters = [];
|
9438 |
|
9439 | _this6.parserWriters[parserName].forEach(function (writer) {
|
9440 | return dependentWriters.push(writer);
|
9441 | });
|
9442 |
|
9443 | try {
|
9444 | if (!_this6.parsers[parserName]) {
|
9445 | // have to load the parser and make sure all of its dependents are set
|
9446 | yield _this6.parseEverything(parserName);
|
9447 | } else {
|
9448 | _this6.parseFileChanges(parserName, files);
|
9449 | }
|
9450 |
|
9451 | yield Promise.all(dependentWriters.map(function (writer) {
|
9452 | return _this6.write(writer);
|
9453 | }));
|
9454 | } catch (error) {
|
9455 | _this6._reporter.reportError('CodegenRunner.watch', error);
|
9456 | }
|
9457 |
|
9458 | _this6._reporter.reportMessage("Watching for changes to ".concat(parserName, "..."));
|
9459 | });
|
9460 |
|
9461 | return function (_x4) {
|
9462 | return _ref4.apply(this, arguments);
|
9463 | };
|
9464 | }());
|
9465 |
|
9466 | this._reporter.reportMessage("Watching for changes to ".concat(parserName, "..."));
|
9467 | });
|
9468 |
|
9469 | function watch(_x3) {
|
9470 | return _watch.apply(this, arguments);
|
9471 | }
|
9472 |
|
9473 | return watch;
|
9474 | }();
|
9475 |
|
9476 | return CodegenRunner;
|
9477 | }();
|
9478 |
|
9479 | function anyFileFilter(file) {
|
9480 | return true;
|
9481 | }
|
9482 |
|
9483 | module.exports = CodegenRunner;
|
9484 |
|
9485 | /***/ }),
|
9486 | /* 52 */
|
9487 | /***/ (function(module, exports, __webpack_require__) {
|
9488 |
|
9489 | "use strict";
|
9490 | /**
|
9491 | * Copyright (c) Facebook, Inc. and its affiliates.
|
9492 | *
|
9493 | * This source code is licensed under the MIT license found in the
|
9494 | * LICENSE file in the root directory of this source tree.
|
9495 | *
|
9496 | *
|
9497 | * @format
|
9498 | */
|
9499 |
|
9500 |
|
9501 | var _asyncToGenerator = __webpack_require__(10);
|
9502 |
|
9503 | var GraphQLWatchmanClient = __webpack_require__(18);
|
9504 |
|
9505 | var Profiler = __webpack_require__(6);
|
9506 |
|
9507 | var crypto = __webpack_require__(12);
|
9508 |
|
9509 | var fs = __webpack_require__(13);
|
9510 |
|
9511 | var path = __webpack_require__(8);
|
9512 |
|
9513 | var SUBSCRIPTION_NAME = 'graphql-codegen';
|
9514 | var QUERY_RETRIES = 3;
|
9515 |
|
9516 | function queryFiles(_x, _x2, _x3) {
|
9517 | return _queryFiles.apply(this, arguments);
|
9518 | }
|
9519 |
|
9520 | function _queryFiles() {
|
9521 | _queryFiles = _asyncToGenerator(function* (baseDir, expression, filter) {
|
9522 | return yield Profiler.waitFor('Watchman:query',
|
9523 | /*#__PURE__*/
|
9524 | _asyncToGenerator(function* () {
|
9525 | var client = new GraphQLWatchmanClient(QUERY_RETRIES);
|
9526 |
|
9527 | var _ref = yield Promise.all([client.watchProject(baseDir), getFields(client)]),
|
9528 | watchResp = _ref[0],
|
9529 | fields = _ref[1];
|
9530 |
|
9531 | var resp = yield client.command('query', watchResp.root, {
|
9532 | expression: expression,
|
9533 | fields: fields,
|
9534 | relative_root: watchResp.relativePath
|
9535 | });
|
9536 | client.end();
|
9537 | return updateFiles(new Set(), baseDir, filter, resp.files);
|
9538 | }));
|
9539 | });
|
9540 | return _queryFiles.apply(this, arguments);
|
9541 | }
|
9542 |
|
9543 | function queryDirectories(_x4, _x5) {
|
9544 | return _queryDirectories.apply(this, arguments);
|
9545 | }
|
9546 |
|
9547 | function _queryDirectories() {
|
9548 | _queryDirectories = _asyncToGenerator(function* (baseDir, expression) {
|
9549 | return yield Profiler.waitFor('Watchman:query',
|
9550 | /*#__PURE__*/
|
9551 | _asyncToGenerator(function* () {
|
9552 | var client = new GraphQLWatchmanClient();
|
9553 | var watchResp = yield client.watchProject(baseDir);
|
9554 | var resp = yield client.command('query', watchResp.root, {
|
9555 | expression: expression,
|
9556 | fields: ['name'],
|
9557 | relative_root: watchResp.relativePath
|
9558 | });
|
9559 | client.end();
|
9560 | return resp.files;
|
9561 | }));
|
9562 | });
|
9563 | return _queryDirectories.apply(this, arguments);
|
9564 | }
|
9565 |
|
9566 | function getFields(_x6) {
|
9567 | return _getFields.apply(this, arguments);
|
9568 | } // For use when not using Watchman.
|
9569 |
|
9570 |
|
9571 | function _getFields() {
|
9572 | _getFields = _asyncToGenerator(function* (client) {
|
9573 | var fields = ['name', 'exists'];
|
9574 |
|
9575 | if (yield client.hasCapability('field-content.sha1hex')) {
|
9576 | fields.push('content.sha1hex');
|
9577 | }
|
9578 |
|
9579 | return fields;
|
9580 | });
|
9581 | return _getFields.apply(this, arguments);
|
9582 | }
|
9583 |
|
9584 | function queryFilepaths(_x7, _x8, _x9) {
|
9585 | return _queryFilepaths.apply(this, arguments);
|
9586 | }
|
9587 | /**
|
9588 | * Provides a simplified API to the watchman API.
|
9589 | * Given some base directory and a list of subdirectories it calls the callback
|
9590 | * with watchman change events on file changes.
|
9591 | */
|
9592 |
|
9593 |
|
9594 | function _queryFilepaths() {
|
9595 | _queryFilepaths = _asyncToGenerator(function* (baseDir, filepaths, filter) {
|
9596 | // Construct WatchmanChange objects as an intermediate step before
|
9597 | // calling updateFiles to produce file content.
|
9598 | var files = filepaths.map(function (filepath) {
|
9599 | return {
|
9600 | name: filepath,
|
9601 | exists: true,
|
9602 | 'content.sha1hex': null
|
9603 | };
|
9604 | });
|
9605 | return updateFiles(new Set(), baseDir, filter, files);
|
9606 | });
|
9607 | return _queryFilepaths.apply(this, arguments);
|
9608 | }
|
9609 |
|
9610 | function watch(_x10, _x11, _x12) {
|
9611 | return _watch.apply(this, arguments);
|
9612 | }
|
9613 |
|
9614 | function _watch() {
|
9615 | _watch = _asyncToGenerator(function* (baseDir, expression, callback) {
|
9616 | return yield Profiler.waitFor('Watchman:subscribe',
|
9617 | /*#__PURE__*/
|
9618 | _asyncToGenerator(function* () {
|
9619 | var client = new GraphQLWatchmanClient();
|
9620 | var watchResp = yield client.watchProject(baseDir);
|
9621 | yield makeSubscription(client, watchResp.root, watchResp.relativePath, expression, callback);
|
9622 | }));
|
9623 | });
|
9624 | return _watch.apply(this, arguments);
|
9625 | }
|
9626 |
|
9627 | function makeSubscription(_x13, _x14, _x15, _x16, _x17) {
|
9628 | return _makeSubscription.apply(this, arguments);
|
9629 | }
|
9630 | /**
|
9631 | * Further simplifies `watch` and calls the callback on every change with a
|
9632 | * full list of files that match the conditions.
|
9633 | */
|
9634 |
|
9635 |
|
9636 | function _makeSubscription() {
|
9637 | _makeSubscription = _asyncToGenerator(function* (client, root, relativePath, expression, callback) {
|
9638 | client.on('subscription', function (resp) {
|
9639 | if (resp.subscription === SUBSCRIPTION_NAME) {
|
9640 | callback(resp);
|
9641 | }
|
9642 | });
|
9643 | var fields = yield getFields(client);
|
9644 | yield client.command('subscribe', root, SUBSCRIPTION_NAME, {
|
9645 | expression: expression,
|
9646 | fields: fields,
|
9647 | relative_root: relativePath
|
9648 | });
|
9649 | });
|
9650 | return _makeSubscription.apply(this, arguments);
|
9651 | }
|
9652 |
|
9653 | function watchFiles(_x18, _x19, _x20, _x21) {
|
9654 | return _watchFiles.apply(this, arguments);
|
9655 | }
|
9656 | /**
|
9657 | * Similar to watchFiles, but takes an async function. The `compile` function
|
9658 | * is awaited and not called in parallel. If multiple changes are triggered
|
9659 | * before a compile finishes, the latest version is called after the compile
|
9660 | * finished.
|
9661 | *
|
9662 | * TODO: Consider changing from a Promise to abortable, so we can abort mid
|
9663 | * compilation.
|
9664 | */
|
9665 |
|
9666 |
|
9667 | function _watchFiles() {
|
9668 | _watchFiles = _asyncToGenerator(function* (baseDir, expression, filter, callback) {
|
9669 | var files = new Set();
|
9670 | yield watch(baseDir, expression, function (changes) {
|
9671 | if (!changes.files) {
|
9672 | // Watchmen fires a change without files when a watchman state changes,
|
9673 | // for example during an hg update.
|
9674 | return;
|
9675 | }
|
9676 |
|
9677 | files = updateFiles(files, baseDir, filter, changes.files);
|
9678 | callback(files);
|
9679 | });
|
9680 | });
|
9681 | return _watchFiles.apply(this, arguments);
|
9682 | }
|
9683 |
|
9684 | function watchCompile(_x22, _x23, _x24, _x25) {
|
9685 | return _watchCompile.apply(this, arguments);
|
9686 | }
|
9687 |
|
9688 | function _watchCompile() {
|
9689 | _watchCompile = _asyncToGenerator(function* (baseDir, expression, filter, compile) {
|
9690 | var compiling = false;
|
9691 | var needsCompiling = false;
|
9692 | var latestFiles = null;
|
9693 | watchFiles(baseDir, expression, filter,
|
9694 | /*#__PURE__*/
|
9695 | function () {
|
9696 | var _ref6 = _asyncToGenerator(function* (files) {
|
9697 | needsCompiling = true;
|
9698 | latestFiles = files;
|
9699 |
|
9700 | if (compiling) {
|
9701 | return;
|
9702 | }
|
9703 |
|
9704 | compiling = true;
|
9705 |
|
9706 | while (needsCompiling) {
|
9707 | needsCompiling = false;
|
9708 | yield compile(latestFiles);
|
9709 | }
|
9710 |
|
9711 | compiling = false;
|
9712 | });
|
9713 |
|
9714 | return function (_x26) {
|
9715 | return _ref6.apply(this, arguments);
|
9716 | };
|
9717 | }());
|
9718 | });
|
9719 | return _watchCompile.apply(this, arguments);
|
9720 | }
|
9721 |
|
9722 | function updateFiles(files, baseDir, filter, fileChanges) {
|
9723 | var fileMap = new Map();
|
9724 | files.forEach(function (file) {
|
9725 | file.exists && fileMap.set(file.relPath, file);
|
9726 | });
|
9727 | fileChanges.forEach(function (_ref2) {
|
9728 | var name = _ref2.name,
|
9729 | exists = _ref2.exists,
|
9730 | hash = _ref2['content.sha1hex'];
|
9731 | var shouldRemove = !exists;
|
9732 |
|
9733 | if (!shouldRemove) {
|
9734 | var _file = {
|
9735 | exists: true,
|
9736 | relPath: name,
|
9737 | hash: hash || hashFile(path.join(baseDir, name))
|
9738 | };
|
9739 |
|
9740 | if (filter(_file)) {
|
9741 | fileMap.set(name, _file);
|
9742 | } else {
|
9743 | shouldRemove = true;
|
9744 | }
|
9745 | }
|
9746 |
|
9747 | shouldRemove && fileMap.set(name, {
|
9748 | exists: false,
|
9749 | relPath: name
|
9750 | });
|
9751 | });
|
9752 | return new Set(fileMap.values());
|
9753 | }
|
9754 |
|
9755 | function hashFile(filename) {
|
9756 | var content = fs.readFileSync(filename);
|
9757 | return crypto.createHash('sha1').update(content).digest('hex');
|
9758 | }
|
9759 |
|
9760 | module.exports = {
|
9761 | queryDirectories: queryDirectories,
|
9762 | queryFiles: queryFiles,
|
9763 | queryFilepaths: queryFilepaths,
|
9764 | watch: watch,
|
9765 | watchFiles: watchFiles,
|
9766 | watchCompile: watchCompile
|
9767 | };
|
9768 |
|
9769 | /***/ }),
|
9770 | /* 53 */
|
9771 | /***/ (function(module, exports) {
|
9772 |
|
9773 | module.exports = require("child_process");
|
9774 |
|
9775 | /***/ }),
|
9776 | /* 54 */
|
9777 | /***/ (function(module, exports) {
|
9778 |
|
9779 | module.exports = require("fb-watchman");
|
9780 |
|
9781 | /***/ }),
|
9782 | /* 55 */
|
9783 | /***/ (function(module, exports, __webpack_require__) {
|
9784 |
|
9785 | "use strict";
|
9786 | /**
|
9787 | * Copyright (c) Facebook, Inc. and its affiliates.
|
9788 | *
|
9789 | * This source code is licensed under the MIT license found in the
|
9790 | * LICENSE file in the root directory of this source tree.
|
9791 | *
|
9792 | *
|
9793 | * @format
|
9794 | * @emails oncall+relay
|
9795 | */
|
9796 |
|
9797 |
|
9798 | var _interopRequireDefault = __webpack_require__(0);
|
9799 |
|
9800 | var _inheritsLoose2 = _interopRequireDefault(__webpack_require__(56));
|
9801 |
|
9802 | var ASTConvert = __webpack_require__(25);
|
9803 |
|
9804 | var nullthrows = __webpack_require__(57);
|
9805 |
|
9806 | var _require = __webpack_require__(1),
|
9807 | createCompilerError = _require.createCompilerError;
|
9808 |
|
9809 | var _require2 = __webpack_require__(7),
|
9810 | GraphQLEnumType = _require2.GraphQLEnumType,
|
9811 | GraphQLInputObjectType = _require2.GraphQLInputObjectType,
|
9812 | GraphQLInterfaceType = _require2.GraphQLInterfaceType,
|
9813 | GraphQLObjectType = _require2.GraphQLObjectType,
|
9814 | GraphQLScalarType = _require2.GraphQLScalarType,
|
9815 | GraphQLSchema = _require2.GraphQLSchema,
|
9816 | GraphQLUnionType = _require2.GraphQLUnionType,
|
9817 | buildASTSchema = _require2.buildASTSchema,
|
9818 | extendSchema = _require2.extendSchema,
|
9819 | parse = _require2.parse,
|
9820 | parseType = _require2.parseType,
|
9821 | print = _require2.print;
|
9822 |
|
9823 | /**
|
9824 | * @private
|
9825 | */
|
9826 | var Type =
|
9827 | /*#__PURE__*/
|
9828 | function () {
|
9829 | function Type(name) {
|
9830 | this.name = name;
|
9831 | }
|
9832 |
|
9833 | var _proto = Type.prototype;
|
9834 |
|
9835 | _proto.toString = function toString() {
|
9836 | return this.name;
|
9837 | };
|
9838 |
|
9839 | _proto.toJSON = function toJSON() {
|
9840 | return String(this);
|
9841 | };
|
9842 |
|
9843 | return Type;
|
9844 | }();
|
9845 | /**
|
9846 | * @private
|
9847 | */
|
9848 |
|
9849 |
|
9850 | var ScalarType =
|
9851 | /*#__PURE__*/
|
9852 | function (_Type) {
|
9853 | (0, _inheritsLoose2["default"])(ScalarType, _Type);
|
9854 |
|
9855 | function ScalarType() {
|
9856 | return _Type.apply(this, arguments) || this;
|
9857 | }
|
9858 |
|
9859 | return ScalarType;
|
9860 | }(Type);
|
9861 | /**
|
9862 | * @private
|
9863 | */
|
9864 |
|
9865 |
|
9866 | var EnumType =
|
9867 | /*#__PURE__*/
|
9868 | function (_Type2) {
|
9869 | (0, _inheritsLoose2["default"])(EnumType, _Type2);
|
9870 |
|
9871 | function EnumType() {
|
9872 | return _Type2.apply(this, arguments) || this;
|
9873 | }
|
9874 |
|
9875 | return EnumType;
|
9876 | }(Type);
|
9877 | /**
|
9878 | * @private
|
9879 | */
|
9880 |
|
9881 |
|
9882 | var UnionType =
|
9883 | /*#__PURE__*/
|
9884 | function (_Type3) {
|
9885 | (0, _inheritsLoose2["default"])(UnionType, _Type3);
|
9886 |
|
9887 | function UnionType() {
|
9888 | return _Type3.apply(this, arguments) || this;
|
9889 | }
|
9890 |
|
9891 | return UnionType;
|
9892 | }(Type);
|
9893 | /**
|
9894 | * @private
|
9895 | */
|
9896 |
|
9897 |
|
9898 | var ObjectType =
|
9899 | /*#__PURE__*/
|
9900 | function (_Type4) {
|
9901 | (0, _inheritsLoose2["default"])(ObjectType, _Type4);
|
9902 |
|
9903 | function ObjectType() {
|
9904 | return _Type4.apply(this, arguments) || this;
|
9905 | }
|
9906 |
|
9907 | return ObjectType;
|
9908 | }(Type);
|
9909 | /**
|
9910 | * @private
|
9911 | */
|
9912 |
|
9913 |
|
9914 | var InputObjectType =
|
9915 | /*#__PURE__*/
|
9916 | function (_Type5) {
|
9917 | (0, _inheritsLoose2["default"])(InputObjectType, _Type5);
|
9918 |
|
9919 | function InputObjectType() {
|
9920 | return _Type5.apply(this, arguments) || this;
|
9921 | }
|
9922 |
|
9923 | return InputObjectType;
|
9924 | }(Type);
|
9925 | /**
|
9926 | * @private
|
9927 | */
|
9928 |
|
9929 |
|
9930 | var InterfaceType =
|
9931 | /*#__PURE__*/
|
9932 | function (_Type6) {
|
9933 | (0, _inheritsLoose2["default"])(InterfaceType, _Type6);
|
9934 |
|
9935 | function InterfaceType() {
|
9936 | return _Type6.apply(this, arguments) || this;
|
9937 | }
|
9938 |
|
9939 | return InterfaceType;
|
9940 | }(Type);
|
9941 | /**
|
9942 | * @private
|
9943 | */
|
9944 |
|
9945 |
|
9946 | var List =
|
9947 | /*#__PURE__*/
|
9948 | function () {
|
9949 | function List(type) {
|
9950 | this.ofType = type;
|
9951 | this._typeString = "[".concat(String(this.ofType), "]");
|
9952 | }
|
9953 |
|
9954 | var _proto2 = List.prototype;
|
9955 |
|
9956 | _proto2.toString = function toString() {
|
9957 | return this._typeString;
|
9958 | };
|
9959 |
|
9960 | _proto2.toJSON = function toJSON() {
|
9961 | return this.toString();
|
9962 | };
|
9963 |
|
9964 | return List;
|
9965 | }();
|
9966 | /**
|
9967 | * @private
|
9968 | */
|
9969 |
|
9970 |
|
9971 | var NonNull =
|
9972 | /*#__PURE__*/
|
9973 | function () {
|
9974 | function NonNull(type) {
|
9975 | this.ofType = type;
|
9976 | this._typeString = "".concat(String(this.ofType), "!");
|
9977 | }
|
9978 |
|
9979 | var _proto3 = NonNull.prototype;
|
9980 |
|
9981 | _proto3.toString = function toString() {
|
9982 | return this._typeString;
|
9983 | };
|
9984 |
|
9985 | _proto3.toJSON = function toJSON() {
|
9986 | return this.toString();
|
9987 | };
|
9988 |
|
9989 | return NonNull;
|
9990 | }();
|
9991 | /**
|
9992 | * @private
|
9993 | */
|
9994 |
|
9995 |
|
9996 | var Field = function Field(schema, name, type, belongsTo, argDefs) {
|
9997 | this.name = name;
|
9998 | this.type = type;
|
9999 | this.belongsTo = belongsTo;
|
10000 | this.args = new Map(argDefs.map(function (arg) {
|
10001 | var _arg$astNode;
|
10002 |
|
10003 | return [arg.name, {
|
10004 | name: arg.name,
|
10005 | type: schema.assertInputType(schema.expectTypeFromAST(nullthrows((_arg$astNode = arg.astNode) === null || _arg$astNode === void 0 ? void 0 : _arg$astNode.type))),
|
10006 | defaultValue: arg.defaultValue
|
10007 | }];
|
10008 | }));
|
10009 | };
|
10010 | /**
|
10011 | * @private
|
10012 | */
|
10013 |
|
10014 |
|
10015 | function unwrap(type) {
|
10016 | if (type instanceof NonNull || type instanceof List) {
|
10017 | return unwrap(type.ofType);
|
10018 | }
|
10019 |
|
10020 | return type;
|
10021 | }
|
10022 | /**
|
10023 | * @private
|
10024 | */
|
10025 |
|
10026 |
|
10027 | function hasConcreteTypeThatImplements(schema, type, interfaceType) {
|
10028 | return _isAbstractType(type) && getConcreteTypes(schema, type).some(function (concreteType) {
|
10029 | return schema.implementsInterface(schema.assertCompositeType(concreteType), interfaceType);
|
10030 | });
|
10031 | }
|
10032 | /**
|
10033 | * @private
|
10034 | */
|
10035 |
|
10036 |
|
10037 | function getConcreteTypes(schema, type) {
|
10038 | var concreteTypes = new Set();
|
10039 | schema.getPossibleTypes(type).forEach(function (possibleType) {
|
10040 | if (_isObject(possibleType)) {
|
10041 | concreteTypes.add(possibleType);
|
10042 | }
|
10043 | });
|
10044 | return Array.from(concreteTypes);
|
10045 | }
|
10046 |
|
10047 | var TYPENAME_FIELD = '__typename';
|
10048 | var CLIENT_ID_FIELD = '__id';
|
10049 |
|
10050 | function _isScalar(type) {
|
10051 | return type instanceof ScalarType;
|
10052 | }
|
10053 |
|
10054 | function _isObject(type) {
|
10055 | return type instanceof ObjectType;
|
10056 | }
|
10057 |
|
10058 | function _isEnum(type) {
|
10059 | return type instanceof EnumType;
|
10060 | }
|
10061 |
|
10062 | function _isUnion(type) {
|
10063 | return type instanceof UnionType;
|
10064 | }
|
10065 |
|
10066 | function _isInputObject(type) {
|
10067 | return type instanceof InputObjectType;
|
10068 | }
|
10069 |
|
10070 | function _isInterface(type) {
|
10071 | return type instanceof InterfaceType;
|
10072 | }
|
10073 |
|
10074 | function _isWrapper(type) {
|
10075 | return type instanceof List || type instanceof NonNull;
|
10076 | }
|
10077 |
|
10078 | function isBaseType(type) {
|
10079 | return type instanceof ScalarType || type instanceof ObjectType || type instanceof EnumType || type instanceof UnionType || type instanceof InputObjectType || type instanceof InterfaceType;
|
10080 | }
|
10081 |
|
10082 | function _isAbstractType(type) {
|
10083 | return type instanceof UnionType || type instanceof InterfaceType;
|
10084 | }
|
10085 |
|
10086 | function _isCompositeType(type) {
|
10087 | return type instanceof ObjectType || type instanceof UnionType || type instanceof InterfaceType;
|
10088 | }
|
10089 |
|
10090 | function _isInputType(type) {
|
10091 | return type instanceof InputObjectType || type instanceof ScalarType || type instanceof EnumType;
|
10092 | }
|
10093 |
|
10094 | var Schema =
|
10095 | /*#__PURE__*/
|
10096 | function () {
|
10097 | /**
|
10098 | * @private
|
10099 | */
|
10100 | function Schema(baseSchema, extendedSchema, typeMap, fieldsMap, typeNameMap, clientIdMap, possibleTypesMap, directivesMap, QUERY_TYPE_KEY, MUTATION_TYPE_KEY, SUBSCRIPTION_TYPE_KEY) {
|
10101 | var _this = this;
|
10102 |
|
10103 | var _directivesMap;
|
10104 |
|
10105 | this.QUERY_TYPE_KEY = QUERY_TYPE_KEY;
|
10106 | this.MUTATION_TYPE_KEY = MUTATION_TYPE_KEY;
|
10107 | this.SUBSCRIPTION_TYPE_KEY = SUBSCRIPTION_TYPE_KEY;
|
10108 | this._baseSchema = baseSchema;
|
10109 | this._extendedSchema = extendedSchema;
|
10110 | this._typeMap = typeMap;
|
10111 | this._fieldsMap = fieldsMap;
|
10112 | this._typeNameMap = typeNameMap;
|
10113 | this._clientIdMap = clientIdMap;
|
10114 | this._possibleTypesMap = possibleTypesMap;
|
10115 | this._directivesMap = (_directivesMap = directivesMap) !== null && _directivesMap !== void 0 ? _directivesMap : new Map(this._extendedSchema.getDirectives().map(function (directive) {
|
10116 | return [directive.name, {
|
10117 | clientOnlyDirective: _this._baseSchema.getDirective(directive.name) == null,
|
10118 | name: directive.name,
|
10119 | locations: directive.locations,
|
10120 | args: directive.args.map(function (arg) {
|
10121 | return {
|
10122 | name: arg.name,
|
10123 | type: _this.assertInputType(arg.astNode ? _this.expectTypeFromAST(arg.astNode.type) : _this.expectTypeFromString(String(arg.type))),
|
10124 | defaultValue: arg.defaultValue
|
10125 | };
|
10126 | })
|
10127 | }];
|
10128 | }));
|
10129 | }
|
10130 |
|
10131 | var _proto4 = Schema.prototype;
|
10132 |
|
10133 | _proto4.getTypeFromAST = function getTypeFromAST(typeNode) {
|
10134 | if (typeNode.kind === 'NonNullType') {
|
10135 | var innerType = this.getTypeFromAST(typeNode.type);
|
10136 |
|
10137 | if (!innerType) {
|
10138 | return;
|
10139 | }
|
10140 |
|
10141 | if (innerType instanceof NonNull) {
|
10142 | throw createCompilerError('Unable to wrap non-nullable type with non-null wrapper.');
|
10143 | }
|
10144 |
|
10145 | var cacheKey = "".concat(this.getTypeString(innerType), "!");
|
10146 |
|
10147 | var type = this._typeMap.get(cacheKey);
|
10148 |
|
10149 | if (type) {
|
10150 | return type;
|
10151 | }
|
10152 |
|
10153 | type = new NonNull(innerType);
|
10154 |
|
10155 | this._typeMap.set(cacheKey, type);
|
10156 |
|
10157 | return type;
|
10158 | } else if (typeNode.kind === 'ListType') {
|
10159 | var _innerType = this.getTypeFromAST(typeNode.type);
|
10160 |
|
10161 | if (!_innerType) {
|
10162 | return;
|
10163 | }
|
10164 |
|
10165 | var _cacheKey = "[".concat(this.getTypeString(_innerType), "]");
|
10166 |
|
10167 | var _type = this._typeMap.get(_cacheKey);
|
10168 |
|
10169 | if (_type) {
|
10170 | return _type;
|
10171 | }
|
10172 |
|
10173 | _type = new List(_innerType);
|
10174 |
|
10175 | this._typeMap.set(_cacheKey, _type);
|
10176 |
|
10177 | return _type;
|
10178 | } else {
|
10179 | var name = typeNode.name.value;
|
10180 |
|
10181 | var _type2 = this._typeMap.get(name);
|
10182 |
|
10183 | if (_type2) {
|
10184 | return _type2;
|
10185 | }
|
10186 |
|
10187 | var graphQLType = this._extendedSchema.getType(name);
|
10188 |
|
10189 | if (!graphQLType) {
|
10190 | return;
|
10191 | }
|
10192 |
|
10193 | var TypeClass = Type;
|
10194 |
|
10195 | if (graphQLType instanceof GraphQLScalarType) {
|
10196 | TypeClass = ScalarType;
|
10197 | } else if (graphQLType instanceof GraphQLInputObjectType) {
|
10198 | TypeClass = InputObjectType;
|
10199 | } else if (graphQLType instanceof GraphQLEnumType) {
|
10200 | TypeClass = EnumType;
|
10201 | } else if (graphQLType instanceof GraphQLUnionType) {
|
10202 | TypeClass = UnionType;
|
10203 | } else if (graphQLType instanceof GraphQLInterfaceType) {
|
10204 | TypeClass = InterfaceType;
|
10205 | } else if (graphQLType instanceof GraphQLObjectType) {
|
10206 | TypeClass = ObjectType;
|
10207 | } else {
|
10208 | throw createCompilerError("Unknown GraphQL type: ".concat(graphQLType));
|
10209 | }
|
10210 |
|
10211 | _type2 = new TypeClass(name);
|
10212 |
|
10213 | this._typeMap.set(name, _type2);
|
10214 |
|
10215 | return _type2;
|
10216 | }
|
10217 | };
|
10218 |
|
10219 | _proto4._getRawType = function _getRawType(typeName) {
|
10220 | var type = this._typeMap.get(typeName);
|
10221 |
|
10222 | if (type) {
|
10223 | return type;
|
10224 | }
|
10225 |
|
10226 | if (typeof typeName === 'string') {
|
10227 | return this.getTypeFromAST(parseType(typeName));
|
10228 | } else {
|
10229 | var graphQLType;
|
10230 |
|
10231 | if (typeName === this.QUERY_TYPE_KEY) {
|
10232 | graphQLType = this._baseSchema.getQueryType();
|
10233 | } else if (typeName === this.MUTATION_TYPE_KEY) {
|
10234 | graphQLType = this._baseSchema.getMutationType();
|
10235 | } else if (typeName === this.SUBSCRIPTION_TYPE_KEY) {
|
10236 | graphQLType = this._baseSchema.getSubscriptionType();
|
10237 | }
|
10238 |
|
10239 | if (graphQLType) {
|
10240 | var operationType = new ObjectType(graphQLType.name);
|
10241 |
|
10242 | this._typeMap.set(typeName, operationType);
|
10243 |
|
10244 | this._typeMap.set(graphQLType.name, operationType);
|
10245 |
|
10246 | return operationType;
|
10247 | }
|
10248 | }
|
10249 | };
|
10250 |
|
10251 | _proto4.getTypeFromString = function getTypeFromString(typeName) {
|
10252 | return this._getRawType(typeName);
|
10253 | };
|
10254 |
|
10255 | _proto4.expectTypeFromString = function expectTypeFromString(typeName) {
|
10256 | var type = this.getTypeFromString(typeName);
|
10257 |
|
10258 | if (type == null) {
|
10259 | throw createCompilerError("Unknown type: '".concat(typeName, "'."));
|
10260 | }
|
10261 |
|
10262 | return type;
|
10263 | };
|
10264 |
|
10265 | _proto4.expectTypeFromAST = function expectTypeFromAST(ast) {
|
10266 | var type = this.getTypeFromAST(ast);
|
10267 |
|
10268 | if (type == null) {
|
10269 | throw createCompilerError("Unknown type: '".concat(print(ast), "'."), null, [ast]);
|
10270 | }
|
10271 |
|
10272 | return type;
|
10273 | };
|
10274 |
|
10275 | _proto4.getNonNullType = function getNonNullType(type) {
|
10276 | if (type instanceof NonNull) {
|
10277 | return type;
|
10278 | }
|
10279 |
|
10280 | var cacheKey = "".concat(String(type), "!");
|
10281 |
|
10282 | var nonNullType = this._typeMap.get(cacheKey);
|
10283 |
|
10284 | if (nonNullType) {
|
10285 | return nonNullType;
|
10286 | }
|
10287 |
|
10288 | nonNullType = new NonNull(type);
|
10289 |
|
10290 | this._typeMap.set(cacheKey, nonNullType);
|
10291 |
|
10292 | return nonNullType;
|
10293 | };
|
10294 |
|
10295 | _proto4.getRawType = function getRawType(type) {
|
10296 | return unwrap(type);
|
10297 | };
|
10298 |
|
10299 | _proto4.getNullableType = function getNullableType(type) {
|
10300 | if (type instanceof NonNull) {
|
10301 | return type.ofType;
|
10302 | }
|
10303 |
|
10304 | return type;
|
10305 | };
|
10306 |
|
10307 | _proto4.getListItemType = function getListItemType(type) {
|
10308 | if (type instanceof List) {
|
10309 | return type.ofType;
|
10310 | }
|
10311 |
|
10312 | return type;
|
10313 | };
|
10314 |
|
10315 | _proto4.areEqualTypes = function areEqualTypes(typeA, typeB) {
|
10316 | if (typeA === typeB) {
|
10317 | return true;
|
10318 | }
|
10319 |
|
10320 | if (typeA instanceof NonNull && typeB instanceof NonNull) {
|
10321 | return this.areEqualTypes(typeA.ofType, typeB.ofType);
|
10322 | }
|
10323 |
|
10324 | if (typeA instanceof List && typeB instanceof List) {
|
10325 | return this.areEqualTypes(typeA.ofType, typeB.ofType);
|
10326 | }
|
10327 |
|
10328 | if (isBaseType(typeA) && isBaseType(typeB)) {
|
10329 | return typeA.name === typeB.name;
|
10330 | }
|
10331 |
|
10332 | return false;
|
10333 | }
|
10334 | /**
|
10335 | * Determine if the given type may implement the named type:
|
10336 | * - it is the named type
|
10337 | * - it implements the named interface
|
10338 | * - it is an abstract type and *some* of its concrete types may
|
10339 | * implement the named type
|
10340 | */
|
10341 | ;
|
10342 |
|
10343 | _proto4.mayImplement = function mayImplement(type, interfaceType) {
|
10344 | return this.areEqualTypes(type, interfaceType) || this.implementsInterface(type, interfaceType) || this.isAbstractType(type) && hasConcreteTypeThatImplements(this, type, interfaceType);
|
10345 | };
|
10346 |
|
10347 | _proto4.implementsInterface = function implementsInterface(type, interfaceType) {
|
10348 | var _this2 = this;
|
10349 |
|
10350 | return this.getInterfaces(type).some(function (typeInterface) {
|
10351 | return _this2.areEqualTypes(typeInterface, interfaceType);
|
10352 | });
|
10353 | };
|
10354 |
|
10355 | _proto4.canHaveSelections = function canHaveSelections(type) {
|
10356 | return this.isObject(type) || this.isInterface(type);
|
10357 | };
|
10358 |
|
10359 | _proto4.getTypeString = function getTypeString(type) {
|
10360 | return type.toString();
|
10361 | };
|
10362 |
|
10363 | _proto4.isTypeSubTypeOf = function isTypeSubTypeOf(maybeSubType, superType) {
|
10364 | // Equivalent type is a valid subtype
|
10365 | if (maybeSubType === superType) {
|
10366 | return true;
|
10367 | } // If superType is non-null, maybeSubType must also be non-null.
|
10368 |
|
10369 |
|
10370 | if (superType instanceof NonNull) {
|
10371 | if (maybeSubType instanceof NonNull) {
|
10372 | return this.isTypeSubTypeOf(maybeSubType.ofType, superType.ofType);
|
10373 | }
|
10374 |
|
10375 | return false;
|
10376 | }
|
10377 |
|
10378 | if (maybeSubType instanceof NonNull) {
|
10379 | // If superType is nullable, maybeSubType may be non-null or nullable.
|
10380 | return this.isTypeSubTypeOf(maybeSubType.ofType, superType);
|
10381 | } // If superType type is a list, maybeSubType type must also be a list.
|
10382 |
|
10383 |
|
10384 | if (superType instanceof List) {
|
10385 | if (maybeSubType instanceof List) {
|
10386 | return this.isTypeSubTypeOf(maybeSubType.ofType, superType.ofType);
|
10387 | }
|
10388 |
|
10389 | return false;
|
10390 | }
|
10391 |
|
10392 | if (maybeSubType instanceof List) {
|
10393 | // If superType is not a list, maybeSubType must also be not a list.
|
10394 | return false;
|
10395 | } // If superType type is an abstract type, maybeSubType type may be a currently
|
10396 | // possible object type.
|
10397 |
|
10398 |
|
10399 | if (this.isAbstractType(superType) && this.isObject(maybeSubType) && this.isPossibleType(this.assertAbstractType(superType), this.assertObjectType(maybeSubType))) {
|
10400 | return true;
|
10401 | } // Otherwise, maybeSubType is not a valid subtype of the superType.
|
10402 |
|
10403 |
|
10404 | return false;
|
10405 | }
|
10406 | /**
|
10407 | * Provided two composite types, determine if they "overlap". Two composite
|
10408 | * types overlap when the Sets of possible concrete types for each intersect.
|
10409 | *
|
10410 | * This is often used to determine if a fragment of a given type could possibly
|
10411 | * be visited in a context of another type.
|
10412 | *
|
10413 | * This function is commutative.
|
10414 | */
|
10415 | ;
|
10416 |
|
10417 | _proto4.doTypesOverlap = function doTypesOverlap(typeA, typeB) {
|
10418 | var _this3 = this;
|
10419 |
|
10420 | // Equivalent types overlap
|
10421 | if (typeA === typeB) {
|
10422 | return true;
|
10423 | }
|
10424 |
|
10425 | if (_isAbstractType(typeA)) {
|
10426 | if (_isAbstractType(typeB)) {
|
10427 | // If both types are abstract, then determine if there is any intersection
|
10428 | // between possible concrete types of each.
|
10429 | return Array.from(this.getPossibleTypes(typeA)).some(function (type) {
|
10430 | if (_isObject(type)) {
|
10431 | return _this3.isPossibleType(typeB, type);
|
10432 | }
|
10433 | });
|
10434 | } // Determine if the latter type is a possible concrete type of the former.
|
10435 |
|
10436 |
|
10437 | return this.isPossibleType(typeA, typeB);
|
10438 | }
|
10439 |
|
10440 | if (_isAbstractType(typeB)) {
|
10441 | // Determine if the former type is a possible concrete type of the latter.
|
10442 | return this.isPossibleType(typeB, typeA);
|
10443 | } // Otherwise the types do not overlap.
|
10444 |
|
10445 |
|
10446 | return false;
|
10447 | };
|
10448 |
|
10449 | _proto4.isPossibleType = function isPossibleType(superType, maybeSubType) {
|
10450 | return this._getPossibleTypeSet(superType).has(maybeSubType);
|
10451 | };
|
10452 |
|
10453 | _proto4.assertScalarFieldType = function assertScalarFieldType(type) {
|
10454 | // Scalar type fields can be wrappers / or can be scalars/enums
|
10455 | if (_isWrapper(type) && !_isScalar(unwrap(type)) && !_isEnum(unwrap(type)) || !_isWrapper(type) && !_isScalar(type) && !_isEnum(type)) {
|
10456 | throw createCompilerError("Expected ".concat(String(type), " to be a Scalar or Enum type."));
|
10457 | }
|
10458 |
|
10459 | return type;
|
10460 | };
|
10461 |
|
10462 | _proto4.assertLinkedFieldType = function assertLinkedFieldType(type) {
|
10463 | // Linked Field types can be wrappers / or can be composite types
|
10464 | if (_isWrapper(type) && !_isCompositeType(unwrap(type)) || !_isWrapper(type) && !_isCompositeType(type)) {
|
10465 | throw createCompilerError("Expected ".concat(String(type), " to be a Object, Interface or a Union Type."));
|
10466 | }
|
10467 |
|
10468 | return type;
|
10469 | };
|
10470 |
|
10471 | _proto4.assertInputType = function assertInputType(type) {
|
10472 | // Input type fields can be wrappers / or can be scalars/enums
|
10473 | if (_isWrapper(type) && !_isInputType(unwrap(type)) || !_isWrapper(type) && !_isInputType(type)) {
|
10474 | throw createCompilerError("Expected ".concat(String(type), " to be a Input, Scalar or Enum type."));
|
10475 | }
|
10476 |
|
10477 | return type;
|
10478 | };
|
10479 |
|
10480 | _proto4.asCompositeType = function asCompositeType(type) {
|
10481 | if (_isCompositeType(type)) {
|
10482 | return type;
|
10483 | }
|
10484 | };
|
10485 |
|
10486 | _proto4.asInputType = function asInputType(type) {
|
10487 | if (_isWrapper(type) && _isInputType(unwrap(type)) || !_isWrapper(type) && _isInputType(type)) {
|
10488 | return type;
|
10489 | }
|
10490 | };
|
10491 |
|
10492 | _proto4.asScalarFieldType = function asScalarFieldType(type) {
|
10493 | if (_isScalar(type) || _isEnum(type)) {
|
10494 | return type;
|
10495 | }
|
10496 | };
|
10497 |
|
10498 | _proto4.assertScalarType = function assertScalarType(type) {
|
10499 | if (!_isScalar(type)) {
|
10500 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a scalar type."));
|
10501 | }
|
10502 |
|
10503 | return type;
|
10504 | };
|
10505 |
|
10506 | _proto4.assertObjectType = function assertObjectType(type) {
|
10507 | if (!_isObject(type)) {
|
10508 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be an object type."));
|
10509 | }
|
10510 |
|
10511 | return type;
|
10512 | };
|
10513 |
|
10514 | _proto4.assertInputObjectType = function assertInputObjectType(type) {
|
10515 | if (!_isInputObject(type)) {
|
10516 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be an input type."));
|
10517 | }
|
10518 |
|
10519 | return type;
|
10520 | };
|
10521 |
|
10522 | _proto4.assertInterfaceType = function assertInterfaceType(type) {
|
10523 | if (!_isInterface(type)) {
|
10524 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be an interface type."));
|
10525 | }
|
10526 |
|
10527 | return type;
|
10528 | };
|
10529 |
|
10530 | _proto4.assertCompositeType = function assertCompositeType(type) {
|
10531 | if (!_isCompositeType(type)) {
|
10532 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a composite type."));
|
10533 | }
|
10534 |
|
10535 | return type;
|
10536 | };
|
10537 |
|
10538 | _proto4.assertAbstractType = function assertAbstractType(type) {
|
10539 | if (!_isAbstractType(type)) {
|
10540 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be an abstract type."));
|
10541 | }
|
10542 |
|
10543 | return type;
|
10544 | };
|
10545 |
|
10546 | _proto4.assertLeafType = function assertLeafType(type) {
|
10547 | if (!this.isLeafType(type)) {
|
10548 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a leaf type."));
|
10549 | }
|
10550 |
|
10551 | return type;
|
10552 | };
|
10553 |
|
10554 | _proto4.assertUnionType = function assertUnionType(type) {
|
10555 | if (!_isUnion(type)) {
|
10556 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a union type."));
|
10557 | }
|
10558 |
|
10559 | return type;
|
10560 | };
|
10561 |
|
10562 | _proto4.assertEnumType = function assertEnumType(type) {
|
10563 | if (!_isEnum(type)) {
|
10564 | throw createCompilerError("Expected ".concat(String(type), " to be an enum type."));
|
10565 | }
|
10566 |
|
10567 | return type;
|
10568 | };
|
10569 |
|
10570 | _proto4.assertIntType = function assertIntType(type) {
|
10571 | if (!_isScalar(type) || !this.isInt(type)) {
|
10572 | throw createCompilerError("Expected ".concat(String(type), " to be an 'Int' type."));
|
10573 | }
|
10574 |
|
10575 | return type;
|
10576 | };
|
10577 |
|
10578 | _proto4.assertFloatType = function assertFloatType(type) {
|
10579 | if (!_isScalar(type) || !this.isFloat(type)) {
|
10580 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a 'Float' type."));
|
10581 | }
|
10582 |
|
10583 | return type;
|
10584 | };
|
10585 |
|
10586 | _proto4.assertBooleanType = function assertBooleanType(type) {
|
10587 | if (!_isScalar(type) || !this.isBoolean(type)) {
|
10588 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a 'Boolean' type."));
|
10589 | }
|
10590 |
|
10591 | return type;
|
10592 | };
|
10593 |
|
10594 | _proto4.assertStringType = function assertStringType(type) {
|
10595 | if (!_isScalar(type) || !this.isString(type)) {
|
10596 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be a 'String' type."));
|
10597 | }
|
10598 |
|
10599 | return type;
|
10600 | };
|
10601 |
|
10602 | _proto4.assertIdType = function assertIdType(type) {
|
10603 | if (!_isScalar(type) || !this.isId(type)) {
|
10604 | throw createCompilerError("Expected ".concat(this.getTypeString(type), " to be an ID type."));
|
10605 | }
|
10606 |
|
10607 | return type;
|
10608 | };
|
10609 |
|
10610 | _proto4.expectBooleanType = function expectBooleanType() {
|
10611 | return this.assertScalarType(this.expectTypeFromString('Boolean'));
|
10612 | };
|
10613 |
|
10614 | _proto4.expectIntType = function expectIntType() {
|
10615 | return this.assertScalarType(this.expectTypeFromString('Int'));
|
10616 | };
|
10617 |
|
10618 | _proto4.expectFloatType = function expectFloatType() {
|
10619 | return this.assertScalarType(this.expectTypeFromString('Float'));
|
10620 | };
|
10621 |
|
10622 | _proto4.expectStringType = function expectStringType() {
|
10623 | return this.assertScalarType(this.expectTypeFromString('String'));
|
10624 | };
|
10625 |
|
10626 | _proto4.expectIdType = function expectIdType() {
|
10627 | return this.assertScalarType(this.expectTypeFromString('ID'));
|
10628 | };
|
10629 |
|
10630 | _proto4.getQueryType = function getQueryType() {
|
10631 | var queryType = this._getRawType(this.QUERY_TYPE_KEY);
|
10632 |
|
10633 | if (queryType && _isObject(queryType)) {
|
10634 | return queryType;
|
10635 | }
|
10636 | };
|
10637 |
|
10638 | _proto4.getMutationType = function getMutationType() {
|
10639 | var mutationType = this._getRawType(this.MUTATION_TYPE_KEY);
|
10640 |
|
10641 | if (mutationType && _isObject(mutationType)) {
|
10642 | return mutationType;
|
10643 | }
|
10644 | };
|
10645 |
|
10646 | _proto4.getSubscriptionType = function getSubscriptionType() {
|
10647 | var subscriptionType = this._getRawType(this.SUBSCRIPTION_TYPE_KEY);
|
10648 |
|
10649 | if (subscriptionType && _isObject(subscriptionType)) {
|
10650 | return subscriptionType;
|
10651 | }
|
10652 | };
|
10653 |
|
10654 | _proto4.expectQueryType = function expectQueryType() {
|
10655 | var queryType = this.getQueryType();
|
10656 |
|
10657 | if (queryType == null) {
|
10658 | throw createCompilerError('Query type is not defined on the Schema');
|
10659 | }
|
10660 |
|
10661 | return queryType;
|
10662 | };
|
10663 |
|
10664 | _proto4.expectMutationType = function expectMutationType() {
|
10665 | var mutationType = this.getMutationType();
|
10666 |
|
10667 | if (mutationType == null) {
|
10668 | throw createCompilerError('Mutation type is not defined the Schema');
|
10669 | }
|
10670 |
|
10671 | return mutationType;
|
10672 | };
|
10673 |
|
10674 | _proto4.expectSubscriptionType = function expectSubscriptionType() {
|
10675 | var subscriptionType = this.getSubscriptionType();
|
10676 |
|
10677 | if (subscriptionType == null) {
|
10678 | throw createCompilerError('Subscription type is not defined the Schema');
|
10679 | }
|
10680 |
|
10681 | return subscriptionType;
|
10682 | };
|
10683 |
|
10684 | _proto4.isNonNull = function isNonNull(type) {
|
10685 | return type instanceof NonNull;
|
10686 | };
|
10687 |
|
10688 | _proto4.isList = function isList(type) {
|
10689 | return type instanceof List;
|
10690 | };
|
10691 |
|
10692 | _proto4.isWrapper = function isWrapper(type) {
|
10693 | return _isWrapper(type);
|
10694 | };
|
10695 |
|
10696 | _proto4.isScalar = function isScalar(type) {
|
10697 | return _isScalar(type);
|
10698 | };
|
10699 |
|
10700 | _proto4.isObject = function isObject(type) {
|
10701 | return _isObject(type);
|
10702 | };
|
10703 |
|
10704 | _proto4.isEnum = function isEnum(type) {
|
10705 | return _isEnum(type);
|
10706 | };
|
10707 |
|
10708 | _proto4.isUnion = function isUnion(type) {
|
10709 | return _isUnion(type);
|
10710 | };
|
10711 |
|
10712 | _proto4.isInputObject = function isInputObject(type) {
|
10713 | return _isInputObject(type);
|
10714 | };
|
10715 |
|
10716 | _proto4.isInterface = function isInterface(type) {
|
10717 | return _isInterface(type);
|
10718 | };
|
10719 |
|
10720 | _proto4.isInputType = function isInputType(type) {
|
10721 | // Wrappers can be input types (so it's save to check unwrapped type here)
|
10722 | return _isInputType(type) || _isWrapper(type) && _isInputType(unwrap(type));
|
10723 | };
|
10724 |
|
10725 | _proto4.isCompositeType = function isCompositeType(type) {
|
10726 | return _isCompositeType(type);
|
10727 | };
|
10728 |
|
10729 | _proto4.isAbstractType = function isAbstractType(type) {
|
10730 | return _isAbstractType(type);
|
10731 | };
|
10732 |
|
10733 | _proto4.isLeafType = function isLeafType(type) {
|
10734 | return this.isScalar(type) || this.isEnum(type);
|
10735 | };
|
10736 |
|
10737 | _proto4.isId = function isId(type) {
|
10738 | if (type instanceof ScalarType) {
|
10739 | return type.name === 'ID';
|
10740 | }
|
10741 |
|
10742 | return false;
|
10743 | };
|
10744 |
|
10745 | _proto4.isInt = function isInt(type) {
|
10746 | if (type instanceof ScalarType) {
|
10747 | return type.name === 'Int';
|
10748 | }
|
10749 |
|
10750 | return false;
|
10751 | };
|
10752 |
|
10753 | _proto4.isFloat = function isFloat(type) {
|
10754 | if (type instanceof ScalarType) {
|
10755 | return type.name === 'Float';
|
10756 | }
|
10757 |
|
10758 | return false;
|
10759 | };
|
10760 |
|
10761 | _proto4.isBoolean = function isBoolean(type) {
|
10762 | if (type instanceof ScalarType) {
|
10763 | return type.name === 'Boolean';
|
10764 | }
|
10765 |
|
10766 | return false;
|
10767 | };
|
10768 |
|
10769 | _proto4.isString = function isString(type) {
|
10770 | if (type instanceof ScalarType) {
|
10771 | return type.name === 'String';
|
10772 | }
|
10773 |
|
10774 | return false;
|
10775 | };
|
10776 |
|
10777 | _proto4.hasField = function hasField(type, fieldName) {
|
10778 | var canHaveTypename = this.isObject(type) || this.isAbstractType(type); // Special case for __typename field
|
10779 |
|
10780 | if (canHaveTypename && (fieldName === TYPENAME_FIELD || fieldName === CLIENT_ID_FIELD)) {
|
10781 | return true;
|
10782 | }
|
10783 |
|
10784 | var name = type.name;
|
10785 |
|
10786 | var gqlType = this._extendedSchema.getType(name);
|
10787 |
|
10788 | if (gqlType instanceof GraphQLObjectType || gqlType instanceof GraphQLInterfaceType || gqlType instanceof GraphQLInputObjectType) {
|
10789 | return gqlType.getFields()[fieldName] != null;
|
10790 | }
|
10791 |
|
10792 | throw createCompilerError('hasField(): Expected a concrete type or interface, ' + "got type ".concat(type.name));
|
10793 | };
|
10794 |
|
10795 | _proto4.hasId = function hasId(type) {
|
10796 | if (!this.hasField(type, 'id')) {
|
10797 | return false;
|
10798 | }
|
10799 |
|
10800 | var idField = this.expectField(type, 'id');
|
10801 | return this.areEqualTypes(this.getNullableType(this.getFieldType(idField)), this.expectIdType());
|
10802 | };
|
10803 |
|
10804 | _proto4.getFields = function getFields(type) {
|
10805 | var fieldsMap = this._getFieldsMap(type);
|
10806 |
|
10807 | return Array.from(fieldsMap.values());
|
10808 | };
|
10809 |
|
10810 | _proto4._getFieldsMap = function _getFieldsMap(type) {
|
10811 | var _this4 = this;
|
10812 |
|
10813 | var cachedMap = this._fieldsMap.get(type);
|
10814 |
|
10815 | if (cachedMap != null) {
|
10816 | return cachedMap;
|
10817 | }
|
10818 |
|
10819 | var fieldsMap = new Map();
|
10820 | var name = type.name;
|
10821 |
|
10822 | var gqlType = this._extendedSchema.getType(name);
|
10823 |
|
10824 | if (gqlType instanceof GraphQLObjectType || gqlType instanceof GraphQLInterfaceType) {
|
10825 | var typeFields = gqlType.getFields();
|
10826 | var fieldNames = Object.keys(typeFields);
|
10827 | fieldNames.forEach(function (fieldName) {
|
10828 | var field = typeFields[fieldName];
|
10829 |
|
10830 | if (field == null) {
|
10831 | return;
|
10832 | }
|
10833 |
|
10834 | var fieldType = field.astNode ? _this4.expectTypeFromAST(field.astNode.type) : _this4.expectTypeFromString(String(field.type));
|
10835 | fieldsMap.set(fieldName, new Field(_this4, fieldName, fieldType, _this4.assertCompositeType(type), field.args));
|
10836 | });
|
10837 | } else if (gqlType instanceof GraphQLInputObjectType) {
|
10838 | var _typeFields = gqlType.getFields();
|
10839 |
|
10840 | var _fieldNames = Object.keys(_typeFields);
|
10841 |
|
10842 | _fieldNames.forEach(function (fieldName) {
|
10843 | var field = _typeFields[fieldName];
|
10844 |
|
10845 | if (field == null) {
|
10846 | return;
|
10847 | }
|
10848 |
|
10849 | var fieldType = field.astNode ? _this4.expectTypeFromAST(field.astNode.type) : _this4.expectTypeFromString(String(field.type));
|
10850 | fieldsMap.set(fieldName, new Field(_this4, fieldName, fieldType, type, []));
|
10851 | });
|
10852 | }
|
10853 |
|
10854 | this._fieldsMap.set(type, fieldsMap);
|
10855 |
|
10856 | return fieldsMap;
|
10857 | };
|
10858 |
|
10859 | _proto4.getFieldByName = function getFieldByName(type, fieldName) {
|
10860 | if (!this.hasField(type, fieldName)) {
|
10861 | return;
|
10862 | } // A "special" case for __typename and __id fields - which should
|
10863 | // not be in the list of type fields, but should be fine to select
|
10864 |
|
10865 |
|
10866 | if (fieldName === TYPENAME_FIELD) {
|
10867 | var typename = this._typeNameMap.get(type);
|
10868 |
|
10869 | if (!typename) {
|
10870 | typename = new Field(this, TYPENAME_FIELD, this.getNonNullType(this.expectStringType()), type, []);
|
10871 |
|
10872 | this._typeNameMap.set(type, typename);
|
10873 | }
|
10874 |
|
10875 | return typename;
|
10876 | }
|
10877 |
|
10878 | if (fieldName === CLIENT_ID_FIELD) {
|
10879 | var clientId = this._clientIdMap.get(type);
|
10880 |
|
10881 | if (!clientId) {
|
10882 | clientId = new Field(this, CLIENT_ID_FIELD, this.getNonNullType(this.expectIdType()), type, []);
|
10883 |
|
10884 | this._clientIdMap.set(type, clientId);
|
10885 | }
|
10886 |
|
10887 | return clientId;
|
10888 | }
|
10889 |
|
10890 | if (_isUnion(type)) {
|
10891 | throw createCompilerError("Unexpected union type '".concat(this.getTypeString(type), "' in the 'getFieldByName(...)'. Expected type with fields"));
|
10892 | }
|
10893 |
|
10894 | var fieldsMap = this._getFieldsMap(type);
|
10895 |
|
10896 | return fieldsMap.get(fieldName);
|
10897 | };
|
10898 |
|
10899 | _proto4.expectField = function expectField(type, fieldName) {
|
10900 | var field = this.getFieldByName(type, fieldName);
|
10901 |
|
10902 | if (!field) {
|
10903 | throw createCompilerError("Unknown field '".concat(fieldName, "' on type '").concat(this.getTypeString(type), "'."));
|
10904 | }
|
10905 |
|
10906 | return field;
|
10907 | };
|
10908 |
|
10909 | _proto4.getFieldConfig = function getFieldConfig(field) {
|
10910 | return {
|
10911 | type: field.type,
|
10912 | args: Array.from(field.args.values())
|
10913 | };
|
10914 | };
|
10915 |
|
10916 | _proto4.getFieldName = function getFieldName(field) {
|
10917 | return field.name;
|
10918 | };
|
10919 |
|
10920 | _proto4.getFieldType = function getFieldType(field) {
|
10921 | return field.type;
|
10922 | };
|
10923 |
|
10924 | _proto4.getFieldParentType = function getFieldParentType(field) {
|
10925 | return field.belongsTo;
|
10926 | };
|
10927 |
|
10928 | _proto4.getFieldArgs = function getFieldArgs(field) {
|
10929 | return Array.from(field.args.values());
|
10930 | };
|
10931 |
|
10932 | _proto4.getFieldArgByName = function getFieldArgByName(field, argName) {
|
10933 | return field.args.get(argName);
|
10934 | };
|
10935 |
|
10936 | _proto4.getEnumValues = function getEnumValues(type) {
|
10937 | var gqlType = this._extendedSchema.getType(type.name);
|
10938 |
|
10939 | if (gqlType instanceof GraphQLEnumType) {
|
10940 | return gqlType.getValues().map(function (_ref) {
|
10941 | var value = _ref.value;
|
10942 | return String(value);
|
10943 | });
|
10944 | }
|
10945 |
|
10946 | throw createCompilerError("Expected '".concat(type.name, "' to be an enum."));
|
10947 | };
|
10948 |
|
10949 | _proto4.getUnionTypes = function getUnionTypes(type) {
|
10950 | var _this5 = this;
|
10951 |
|
10952 | var gqlType = this._extendedSchema.getType(type.name);
|
10953 |
|
10954 | if (gqlType instanceof GraphQLUnionType) {
|
10955 | return gqlType.getTypes().map(function (typeFromUnion) {
|
10956 | return _this5.expectTypeFromString(typeFromUnion.name);
|
10957 | });
|
10958 | }
|
10959 |
|
10960 | throw createCompilerError("Unable to get union types for type '".concat(this.getTypeString(type), "'."));
|
10961 | };
|
10962 |
|
10963 | _proto4.getInterfaces = function getInterfaces(type) {
|
10964 | var _this6 = this;
|
10965 |
|
10966 | var gqlType = this._extendedSchema.getType(type.name);
|
10967 |
|
10968 | if (gqlType instanceof GraphQLObjectType) {
|
10969 | return gqlType.getInterfaces().map(function (typeInterface) {
|
10970 | return _this6.expectTypeFromString(typeInterface.name);
|
10971 | });
|
10972 | }
|
10973 |
|
10974 | return [];
|
10975 | };
|
10976 |
|
10977 | _proto4._getPossibleTypeSet = function _getPossibleTypeSet(type) {
|
10978 | var _this7 = this;
|
10979 |
|
10980 | var possibleTypes = this._possibleTypesMap.get(type);
|
10981 |
|
10982 | if (!possibleTypes) {
|
10983 | var gqlType = this._extendedSchema.getType(type.name);
|
10984 |
|
10985 | if (gqlType instanceof GraphQLUnionType || gqlType instanceof GraphQLInterfaceType) {
|
10986 | possibleTypes = new Set(this._extendedSchema.getPossibleTypes(gqlType).map(function (possibleType) {
|
10987 | return _this7.assertObjectType(_this7.expectTypeFromString(possibleType.name));
|
10988 | }));
|
10989 |
|
10990 | this._possibleTypesMap.set(type, possibleTypes);
|
10991 | } else {
|
10992 | throw createCompilerError("Expected \"".concat(this.getTypeString(type), "\" to be an Abstract type."));
|
10993 | }
|
10994 | }
|
10995 |
|
10996 | return possibleTypes;
|
10997 | };
|
10998 |
|
10999 | _proto4.getPossibleTypes = function getPossibleTypes(type) {
|
11000 | return this._getPossibleTypeSet(type);
|
11001 | };
|
11002 |
|
11003 | _proto4.parseLiteral = function parseLiteral(type, valueNode) {
|
11004 | var gqlType = this._extendedSchema.getType(type.name);
|
11005 |
|
11006 | if (gqlType instanceof GraphQLEnumType || gqlType instanceof GraphQLScalarType) {
|
11007 | return gqlType.parseLiteral(valueNode);
|
11008 | }
|
11009 |
|
11010 | throw createCompilerError("parseLiteral(...) is used with invalid type: ".concat(this.getTypeString(type), "."));
|
11011 | };
|
11012 |
|
11013 | _proto4.parseValue = function parseValue(type, value) {
|
11014 | var gqlType = this._extendedSchema.getType(type.name);
|
11015 |
|
11016 | if (gqlType instanceof GraphQLEnumType || gqlType instanceof GraphQLScalarType) {
|
11017 | return gqlType.parseValue(value);
|
11018 | }
|
11019 |
|
11020 | throw createCompilerError("parseValue(...) is used with invalid type: ".concat(this.getTypeString(type), "."));
|
11021 | };
|
11022 |
|
11023 | _proto4.serialize = function serialize(type, value) {
|
11024 | var gqlType = this._extendedSchema.getType(type.name);
|
11025 |
|
11026 | if (gqlType instanceof GraphQLEnumType || gqlType instanceof GraphQLScalarType) {
|
11027 | return gqlType.serialize(value);
|
11028 | }
|
11029 |
|
11030 | throw createCompilerError("parseValue(...) is used with invalid type: ".concat(this.getTypeString(type), "."));
|
11031 | };
|
11032 |
|
11033 | _proto4.getDirectives = function getDirectives() {
|
11034 | return Array.from(this._directivesMap.values());
|
11035 | };
|
11036 |
|
11037 | _proto4.getDirective = function getDirective(directiveName) {
|
11038 | return this._directivesMap.get(directiveName);
|
11039 | };
|
11040 |
|
11041 | _proto4.isServerType = function isServerType(type) {
|
11042 | var name = this.getTypeString(type);
|
11043 | return this._baseSchema.getType(name) != null;
|
11044 | };
|
11045 |
|
11046 | _proto4.isServerField = function isServerField(field) {
|
11047 | var fieldName = field.name; // Allow metadata fields and fields defined on classic "fat" interfaces
|
11048 |
|
11049 | if (['__typename'].includes(fieldName)) {
|
11050 | return true;
|
11051 | }
|
11052 |
|
11053 | var fieldRawTypeName = this.getTypeString(unwrap(field.type));
|
11054 | var fieldParentTypeName = this.getTypeString(unwrap(field.belongsTo)); // Field type is client-only
|
11055 |
|
11056 | if (!this._baseSchema.getType(fieldRawTypeName)) {
|
11057 | return false;
|
11058 | }
|
11059 |
|
11060 | var serverType = this._baseSchema.getType(fieldParentTypeName); // Parent type is client-only
|
11061 |
|
11062 |
|
11063 | if (serverType == null) {
|
11064 | return false;
|
11065 | } else {
|
11066 | if (serverType instanceof GraphQLObjectType || serverType instanceof GraphQLInterfaceType || serverType instanceof GraphQLInputObjectType) {
|
11067 | // Field is not available in the server schema
|
11068 | if (!serverType.getFields()[fieldName]) {
|
11069 | return false;
|
11070 | }
|
11071 | } else {
|
11072 | return false;
|
11073 | }
|
11074 | }
|
11075 |
|
11076 | return true;
|
11077 | };
|
11078 |
|
11079 | _proto4.isServerDirective = function isServerDirective(directiveName) {
|
11080 | var directive = this._directivesMap.get(directiveName);
|
11081 |
|
11082 | return (directive === null || directive === void 0 ? void 0 : directive.clientOnlyDirective) === false;
|
11083 | };
|
11084 |
|
11085 | _proto4.isServerDefinedField = function isServerDefinedField(type, field) {
|
11086 | return this.isAbstractType(type) && field.directives.some(function (_ref2) {
|
11087 | var name = _ref2.name;
|
11088 | return name === 'fixme_fat_interface';
|
11089 | }) || this.hasField(type, field.name) && this.isServerField(this.expectField(type, field.name));
|
11090 | };
|
11091 |
|
11092 | _proto4.isClientDefinedField = function isClientDefinedField(type, field) {
|
11093 | return !this.isServerDefinedField(type, field);
|
11094 | }
|
11095 | /**
|
11096 | * The only consumer of this is RelayParser.parse(...)
|
11097 | * We should either refactor RelayParser.parse(...) to not-rely on the `
|
11098 | * extendSchema` method. Or actually implement it here.
|
11099 | */
|
11100 | ;
|
11101 |
|
11102 | _proto4.DEPRECATED__extend = function DEPRECATED__extend(document) {
|
11103 | var extendedSchema = extendSchema(this._extendedSchema, document, {
|
11104 | assumeValid: true
|
11105 | });
|
11106 | return new Schema(this._baseSchema, extendedSchema, this._typeMap, this._fieldsMap, this._typeNameMap, this._clientIdMap, this._possibleTypesMap, this._directivesMap, this.QUERY_TYPE_KEY, this.MUTATION_TYPE_KEY, this.SUBSCRIPTION_TYPE_KEY);
|
11107 | };
|
11108 |
|
11109 | return Schema;
|
11110 | }();
|
11111 |
|
11112 | var localGraphQLSchemaCache = new Map();
|
11113 |
|
11114 | function DEPRECATED__buildGraphQLSchema(source) {
|
11115 | var schema = localGraphQLSchemaCache.get(source);
|
11116 |
|
11117 | if (schema != null) {
|
11118 | return schema;
|
11119 | }
|
11120 |
|
11121 | try {
|
11122 | schema = buildASTSchema(parse(source), {
|
11123 | assumeValid: true
|
11124 | });
|
11125 | localGraphQLSchemaCache.set(source, schema);
|
11126 | return schema;
|
11127 | } catch (error) {
|
11128 | throw Object.assign(error, {
|
11129 | message: "Caught an error \"".concat(error.message, "\" while loading and parsing schema file: ").concat(source.name, ". Please make sure that schema is valid.")
|
11130 | });
|
11131 | }
|
11132 | }
|
11133 | /**
|
11134 | * We need this in order to make unit-test works
|
11135 | * In most of the unit-tests the schema is created from the instance of the
|
11136 | * GraphQLSchema.
|
11137 | */
|
11138 |
|
11139 |
|
11140 | function DEPRECATED__create(baseSchema, extendedSchema) {
|
11141 | var _extendedSchema;
|
11142 |
|
11143 | return new Schema(baseSchema, (_extendedSchema = extendedSchema) !== null && _extendedSchema !== void 0 ? _extendedSchema : baseSchema, new Map(), new Map(), new Map(), new Map(), new Map(), null, Symbol('Query'), Symbol('Mutation'), Symbol('Subsription'));
|
11144 | }
|
11145 |
|
11146 | function create(baseSchema, schemaExtensionDocuments, schemaExtensions) {
|
11147 | var _schemaExtensions, _schemaExtensionDocum;
|
11148 |
|
11149 | var schema = DEPRECATED__buildGraphQLSchema(baseSchema);
|
11150 | var transformedSchema = ASTConvert.transformASTSchema(schema, (_schemaExtensions = schemaExtensions) !== null && _schemaExtensions !== void 0 ? _schemaExtensions : []);
|
11151 | var extendedSchema = ASTConvert.extendASTSchema(transformedSchema, (_schemaExtensionDocum = schemaExtensionDocuments) !== null && _schemaExtensionDocum !== void 0 ? _schemaExtensionDocum : []);
|
11152 | return new Schema(schema, extendedSchema, new Map(), new Map(), new Map(), new Map(), new Map(), null, Symbol('Query'), Symbol('Mutation'), Symbol('Subsription'));
|
11153 | }
|
11154 |
|
11155 | module.exports = {
|
11156 | DEPRECATED__buildGraphQLSchema: DEPRECATED__buildGraphQLSchema,
|
11157 | DEPRECATED__create: DEPRECATED__create,
|
11158 | create: create
|
11159 | };
|
11160 |
|
11161 | /***/ }),
|
11162 | /* 56 */
|
11163 | /***/ (function(module, exports) {
|
11164 |
|
11165 | module.exports = require("@babel/runtime/helpers/inheritsLoose");
|
11166 |
|
11167 | /***/ }),
|
11168 | /* 57 */
|
11169 | /***/ (function(module, exports, __webpack_require__) {
|
11170 |
|
11171 | "use strict";
|
11172 | /**
|
11173 | * Copyright (c) Facebook, Inc. and its affiliates.
|
11174 | *
|
11175 | * This source code is licensed under the MIT license found in the
|
11176 | * LICENSE file in the root directory of this source tree.
|
11177 | *
|
11178 | *
|
11179 | * @format
|
11180 | */
|
11181 |
|
11182 |
|
11183 | function nullthrows(x) {
|
11184 | var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Got unexpected null or undefined';
|
11185 |
|
11186 | if (x == null) {
|
11187 | throw new Error(message);
|
11188 | }
|
11189 |
|
11190 | return x;
|
11191 | }
|
11192 |
|
11193 | module.exports = nullthrows;
|
11194 |
|
11195 | /***/ }),
|
11196 | /* 58 */
|
11197 | /***/ (function(module, exports, __webpack_require__) {
|
11198 |
|
11199 | "use strict";
|
11200 | /**
|
11201 | * Copyright (c) Facebook, Inc. and its affiliates.
|
11202 | *
|
11203 | * This source code is licensed under the MIT license found in the
|
11204 | * LICENSE file in the root directory of this source tree.
|
11205 | *
|
11206 | *
|
11207 | * @format
|
11208 | */
|
11209 |
|
11210 |
|
11211 | var chalk = __webpack_require__(59);
|
11212 |
|
11213 | function getMemoryUsageString() {
|
11214 | return chalk.blue(Math.round(process.memoryUsage().heapUsed / 1024 / 1024) + 'Mb');
|
11215 | }
|
11216 |
|
11217 | var ConsoleReporter =
|
11218 | /*#__PURE__*/
|
11219 | function () {
|
11220 | function ConsoleReporter(options) {
|
11221 | this._verbose = options.verbose;
|
11222 | this._quiet = options.quiet;
|
11223 | }
|
11224 |
|
11225 | var _proto = ConsoleReporter.prototype;
|
11226 |
|
11227 | _proto.reportMessage = function reportMessage(message) {
|
11228 | if (!this._quiet) {
|
11229 | process.stdout.write(message + '\n');
|
11230 | }
|
11231 | };
|
11232 |
|
11233 | _proto.reportTime = function reportTime(name, ms) {
|
11234 | if (this._verbose && !this._quiet) {
|
11235 | var time = ms === 0 ? chalk.gray(' <1ms') : ms < 1000 ? chalk.blue(leftPad(5, ms + 'ms')) : chalk.red(Math.floor(ms / 10) / 100 + 's');
|
11236 | process.stdout.write(' ' + time + ' ' + chalk.gray(name) + ' [' + getMemoryUsageString() + ']\n');
|
11237 | }
|
11238 | };
|
11239 |
|
11240 | _proto.reportError = function reportError(caughtLocation, error) {
|
11241 | if (!this._quiet) {
|
11242 | process.stdout.write(chalk.red('ERROR:\n' + error.message + '\n'));
|
11243 |
|
11244 | if (this._verbose) {
|
11245 | var frames = error.stack.match(/^ {4}at .*$/gm);
|
11246 |
|
11247 | if (frames) {
|
11248 | process.stdout.write(chalk.gray('From: ' + caughtLocation + '\n' + frames.join('\n') + '\n'));
|
11249 | }
|
11250 | }
|
11251 | }
|
11252 | };
|
11253 |
|
11254 | return ConsoleReporter;
|
11255 | }();
|
11256 |
|
11257 | function leftPad(len, str) {
|
11258 | return new Array(len - str.length + 1).join(' ') + str;
|
11259 | }
|
11260 |
|
11261 | module.exports = ConsoleReporter;
|
11262 |
|
11263 | /***/ }),
|
11264 | /* 59 */
|
11265 | /***/ (function(module, exports) {
|
11266 |
|
11267 | module.exports = require("chalk");
|
11268 |
|
11269 | /***/ }),
|
11270 | /* 60 */
|
11271 | /***/ (function(module, exports, __webpack_require__) {
|
11272 |
|
11273 | "use strict";
|
11274 | /**
|
11275 | * Copyright (c) Facebook, Inc. and its affiliates.
|
11276 | *
|
11277 | * This source code is licensed under the MIT license found in the
|
11278 | * LICENSE file in the root directory of this source tree.
|
11279 | *
|
11280 | *
|
11281 | * @format
|
11282 | */
|
11283 |
|
11284 |
|
11285 | var ASTCache = __webpack_require__(26);
|
11286 |
|
11287 | var fs = __webpack_require__(13);
|
11288 |
|
11289 | var path = __webpack_require__(8);
|
11290 |
|
11291 | var _require = __webpack_require__(7),
|
11292 | parse = _require.parse,
|
11293 | Source = _require.Source;
|
11294 |
|
11295 | function parseFile(baseDir, file) {
|
11296 | var text = fs.readFileSync(path.join(baseDir, file.relPath), 'utf8');
|
11297 | return parse(new Source(text, file.relPath), {
|
11298 | experimentalFragmentVariables: true
|
11299 | });
|
11300 | }
|
11301 |
|
11302 | function getParser(baseDir) {
|
11303 | return new ASTCache({
|
11304 | baseDir: baseDir,
|
11305 | parse: parseFile
|
11306 | });
|
11307 | }
|
11308 |
|
11309 | module.exports = {
|
11310 | parseFile: parseFile,
|
11311 | getParser: getParser
|
11312 | };
|
11313 |
|
11314 | /***/ }),
|
11315 | /* 61 */
|
11316 | /***/ (function(module, exports, __webpack_require__) {
|
11317 |
|
11318 | "use strict";
|
11319 | /**
|
11320 | * Copyright (c) Facebook, Inc. and its affiliates.
|
11321 | *
|
11322 | * This source code is licensed under the MIT license found in the
|
11323 | * LICENSE file in the root directory of this source tree.
|
11324 | *
|
11325 | *
|
11326 | * @format
|
11327 | */
|
11328 |
|
11329 |
|
11330 | var _interopRequireDefault = __webpack_require__(0);
|
11331 |
|
11332 | var _asyncToGenerator = __webpack_require__(10);
|
11333 |
|
11334 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
11335 |
|
11336 | var ASTConvert = __webpack_require__(25);
|
11337 |
|
11338 | var CodegenDirectory = __webpack_require__(24);
|
11339 |
|
11340 | var CompilerContext = __webpack_require__(19);
|
11341 |
|
11342 | var Profiler = __webpack_require__(6);
|
11343 |
|
11344 | var RelayParser = __webpack_require__(27);
|
11345 |
|
11346 | var compileRelayArtifacts = __webpack_require__(63);
|
11347 |
|
11348 | var crypto = __webpack_require__(12);
|
11349 |
|
11350 | var graphql = __webpack_require__(7);
|
11351 |
|
11352 | var invariant = __webpack_require__(4);
|
11353 |
|
11354 | var nullthrows = __webpack_require__(20);
|
11355 |
|
11356 | var path = __webpack_require__(8);
|
11357 |
|
11358 | var writeRelayGeneratedFile = __webpack_require__(68);
|
11359 |
|
11360 | var _require = __webpack_require__(71),
|
11361 | getReaderSourceDefinitionName = _require.getReaderSourceDefinitionName;
|
11362 |
|
11363 | var _require2 = __webpack_require__(11),
|
11364 | isExecutableDefinitionAST = _require2.isExecutableDefinitionAST;
|
11365 |
|
11366 | var _require3 = __webpack_require__(14),
|
11367 | ImmutableMap = _require3.Map;
|
11368 |
|
11369 | function compileAll(_ref) {
|
11370 | var baseDir = _ref.baseDir,
|
11371 | baseDocuments = _ref.baseDocuments,
|
11372 | schema = _ref.schema,
|
11373 | compilerTransforms = _ref.compilerTransforms,
|
11374 | documents = _ref.documents,
|
11375 | reporter = _ref.reporter,
|
11376 | typeGenerator = _ref.typeGenerator;
|
11377 | var definitions = ASTConvert.convertASTDocumentsWithBase(schema, baseDocuments, documents, RelayParser.transform);
|
11378 | var compilerContext = new CompilerContext(schema).addAll(definitions);
|
11379 | var transformedTypeContext = compilerContext.applyTransforms(typeGenerator.transforms, reporter);
|
11380 | var transformedQueryContext = compilerContext.applyTransforms([].concat((0, _toConsumableArray2["default"])(compilerTransforms.commonTransforms), (0, _toConsumableArray2["default"])(compilerTransforms.queryTransforms)), reporter);
|
11381 | var artifacts = compileRelayArtifacts(compilerContext, compilerTransforms, reporter);
|
11382 | return {
|
11383 | artifacts: artifacts,
|
11384 | definitions: definitions,
|
11385 | transformedQueryContext: transformedQueryContext,
|
11386 | transformedTypeContext: transformedTypeContext
|
11387 | };
|
11388 | }
|
11389 |
|
11390 | function writeAll(_ref2) {
|
11391 | var writerConfig = _ref2.config,
|
11392 | onlyValidate = _ref2.onlyValidate,
|
11393 | baseDocuments = _ref2.baseDocuments,
|
11394 | documents = _ref2.documents,
|
11395 | schema = _ref2.schema,
|
11396 | reporter = _ref2.reporter,
|
11397 | sourceControl = _ref2.sourceControl;
|
11398 | return Profiler.asyncContext('RelayFileWriter.writeAll',
|
11399 | /*#__PURE__*/
|
11400 | _asyncToGenerator(function* () {
|
11401 | var _compileAll = compileAll({
|
11402 | schema: schema,
|
11403 | baseDir: writerConfig.baseDir,
|
11404 | baseDocuments: baseDocuments.valueSeq().toArray(),
|
11405 | compilerTransforms: writerConfig.compilerTransforms,
|
11406 | documents: documents.valueSeq().toArray(),
|
11407 | reporter: reporter,
|
11408 | typeGenerator: writerConfig.typeGenerator
|
11409 | }),
|
11410 | artifactsWithBase = _compileAll.artifacts,
|
11411 | definitions = _compileAll.definitions,
|
11412 | transformedTypeContext = _compileAll.transformedTypeContext,
|
11413 | transformedQueryContext = _compileAll.transformedQueryContext; // Build a context from all the documents
|
11414 |
|
11415 |
|
11416 | var baseDefinitionNames = new Set();
|
11417 | baseDocuments.forEach(function (doc) {
|
11418 | doc.definitions.forEach(function (def) {
|
11419 | if (isExecutableDefinitionAST(def) && def.name) {
|
11420 | baseDefinitionNames.add(def.name.value);
|
11421 | }
|
11422 | });
|
11423 | }); // remove nodes that are present in the base or that derive from nodes
|
11424 | // in the base
|
11425 |
|
11426 | var artifacts = artifactsWithBase.filter(function (_ref3) {
|
11427 | var _definition = _ref3[0],
|
11428 | node = _ref3[1];
|
11429 | var sourceName = getReaderSourceDefinitionName(node);
|
11430 | return !baseDefinitionNames.has(sourceName);
|
11431 | });
|
11432 | var artifactMap = new Map(artifacts.map(function (_ref4) {
|
11433 | var _definition = _ref4[0],
|
11434 | node = _ref4[1];
|
11435 | return [node.kind === 'Request' ? node.params.name : node.name, node];
|
11436 | }));
|
11437 | var existingFragmentNames = new Set(definitions.map(function (definition) {
|
11438 | return definition.name;
|
11439 | }));
|
11440 | var definitionsMeta = new Map();
|
11441 |
|
11442 | var getDefinitionMeta = function getDefinitionMeta(definitionName) {
|
11443 | var artifact = nullthrows(artifactMap.get(definitionName));
|
11444 | var sourceName = getReaderSourceDefinitionName(artifact);
|
11445 | var definitionMeta = definitionsMeta.get(sourceName);
|
11446 | !definitionMeta ? true ? invariant(false, 'RelayFileWriter: Could not determine source for definition: `%s`.', definitionName) : undefined : void 0;
|
11447 | return definitionMeta;
|
11448 | };
|
11449 |
|
11450 | documents.forEach(function (doc, filePath) {
|
11451 | doc.definitions.forEach(function (def) {
|
11452 | if (def.name) {
|
11453 | definitionsMeta.set(def.name.value, {
|
11454 | dir: path.join(writerConfig.baseDir, path.dirname(filePath)),
|
11455 | ast: def
|
11456 | });
|
11457 | }
|
11458 | });
|
11459 | }); // TODO(T22651734): improve this to correctly account for fragments that
|
11460 | // have generated flow types.
|
11461 |
|
11462 | baseDefinitionNames.forEach(function (baseDefinitionName) {
|
11463 | existingFragmentNames["delete"](baseDefinitionName);
|
11464 | });
|
11465 | var allOutputDirectories = new Map();
|
11466 |
|
11467 | var addCodegenDir = function addCodegenDir(dirPath) {
|
11468 | var codegenDir = new CodegenDirectory(dirPath, {
|
11469 | onlyValidate: onlyValidate,
|
11470 | filesystem: writerConfig.filesystem
|
11471 | });
|
11472 | allOutputDirectories.set(dirPath, codegenDir);
|
11473 | return codegenDir;
|
11474 | };
|
11475 |
|
11476 | var _iteratorNormalCompletion = true;
|
11477 | var _didIteratorError = false;
|
11478 | var _iteratorError = undefined;
|
11479 |
|
11480 | try {
|
11481 | for (var _iterator = (writerConfig.generatedDirectories || [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
11482 | var existingDirectory = _step.value;
|
11483 | addCodegenDir(existingDirectory);
|
11484 | }
|
11485 | } catch (err) {
|
11486 | _didIteratorError = true;
|
11487 | _iteratorError = err;
|
11488 | } finally {
|
11489 | try {
|
11490 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
11491 | _iterator["return"]();
|
11492 | }
|
11493 | } finally {
|
11494 | if (_didIteratorError) {
|
11495 | throw _iteratorError;
|
11496 | }
|
11497 | }
|
11498 | }
|
11499 |
|
11500 | var configOutputDirectory;
|
11501 |
|
11502 | if (writerConfig.outputDir) {
|
11503 | configOutputDirectory = addCodegenDir(writerConfig.outputDir);
|
11504 | }
|
11505 |
|
11506 | var getGeneratedDirectory = function getGeneratedDirectory(definitionName) {
|
11507 | if (configOutputDirectory) {
|
11508 | return configOutputDirectory;
|
11509 | }
|
11510 |
|
11511 | var generatedPath = path.join(getDefinitionMeta(definitionName).dir, '__generated__');
|
11512 | var cachedDir = allOutputDirectories.get(generatedPath);
|
11513 |
|
11514 | if (!cachedDir) {
|
11515 | cachedDir = addCodegenDir(generatedPath);
|
11516 | }
|
11517 |
|
11518 | return cachedDir;
|
11519 | };
|
11520 |
|
11521 | var formatModule = Profiler.instrument(writerConfig.formatModule, 'RelayFileWriter:formatModule');
|
11522 | var persistQuery = writerConfig.persistQuery ? Profiler.instrumentWait(writerConfig.persistQuery, 'RelayFileWriter:persistQuery') : null;
|
11523 |
|
11524 | try {
|
11525 | yield Promise.all(artifacts.map(
|
11526 | /*#__PURE__*/
|
11527 | function () {
|
11528 | var _ref7 = _asyncToGenerator(function* (_ref5) {
|
11529 | var _writerConfig$repersi;
|
11530 |
|
11531 | var definition = _ref5[0],
|
11532 | node = _ref5[1];
|
11533 | var nodeName = node.kind === 'Request' ? node.params.name : node.name;
|
11534 |
|
11535 | if (baseDefinitionNames.has(nodeName)) {
|
11536 | // don't add definitions that were part of base context
|
11537 | return;
|
11538 | }
|
11539 |
|
11540 | var typeNode = transformedTypeContext.get(nodeName);
|
11541 | var typeText = typeNode ? writerConfig.typeGenerator.generate(schema, typeNode, {
|
11542 | customScalars: writerConfig.customScalars,
|
11543 | enumsHasteModule: writerConfig.enumsHasteModule,
|
11544 | existingFragmentNames: existingFragmentNames,
|
11545 | optionalInputFields: writerConfig.optionalInputFieldsForFlow,
|
11546 | useHaste: writerConfig.useHaste,
|
11547 | useSingleArtifactDirectory: !!writerConfig.outputDir,
|
11548 | noFutureProofEnums: writerConfig.noFutureProofEnums,
|
11549 | normalizationIR: definition.kind === 'Request' ? definition.root : undefined
|
11550 | }) : '';
|
11551 | var sourceHash = Profiler.run('hashGraphQL', function () {
|
11552 | return md5(graphql.print(getDefinitionMeta(nodeName).ast));
|
11553 | });
|
11554 | yield writeRelayGeneratedFile(schema, getGeneratedDirectory(nodeName), definition, node, formatModule, typeText, persistQuery, writerConfig.platform, sourceHash, writerConfig.extension, writerConfig.printModuleDependency, (_writerConfig$repersi = writerConfig.repersist) !== null && _writerConfig$repersi !== void 0 ? _writerConfig$repersi : false);
|
11555 | });
|
11556 |
|
11557 | return function (_x) {
|
11558 | return _ref7.apply(this, arguments);
|
11559 | };
|
11560 | }()));
|
11561 | var generateExtraFiles = writerConfig.generateExtraFiles;
|
11562 |
|
11563 | if (generateExtraFiles) {
|
11564 | Profiler.run('RelayFileWriter:generateExtraFiles', function () {
|
11565 | var configDirectory = writerConfig.outputDir;
|
11566 | generateExtraFiles(function (dir) {
|
11567 | var outputDirectory = dir || configDirectory;
|
11568 | !outputDirectory ? true ? invariant(false, 'RelayFileWriter: cannot generate extra files without specifying ' + 'an outputDir in the config or passing it in.') : undefined : void 0;
|
11569 | var outputDir = allOutputDirectories.get(outputDirectory);
|
11570 |
|
11571 | if (!outputDir) {
|
11572 | outputDir = addCodegenDir(outputDirectory);
|
11573 | }
|
11574 |
|
11575 | return outputDir;
|
11576 | }, transformedQueryContext, getGeneratedDirectory);
|
11577 | });
|
11578 | }
|
11579 |
|
11580 | allOutputDirectories.forEach(function (dir) {
|
11581 | dir.deleteExtraFiles();
|
11582 | });
|
11583 |
|
11584 | if (sourceControl && !onlyValidate) {
|
11585 | yield CodegenDirectory.sourceControlAddRemove(sourceControl, Array.from(allOutputDirectories.values()));
|
11586 | }
|
11587 | } catch (error) {
|
11588 | var details;
|
11589 |
|
11590 | try {
|
11591 | details = JSON.parse(error.message);
|
11592 | } catch (_) {} // eslint-disable-line lint/no-unused-catch-bindings
|
11593 |
|
11594 |
|
11595 | if (details && details.name === 'GraphQL2Exception' && details.message) {
|
11596 | throw new Error('GraphQL error writing modules:\n' + details.message);
|
11597 | }
|
11598 |
|
11599 | throw new Error('Error writing modules:\n' + String(error.stack || error));
|
11600 | }
|
11601 |
|
11602 | return allOutputDirectories;
|
11603 | }));
|
11604 | }
|
11605 |
|
11606 | function md5(x) {
|
11607 | return crypto.createHash('md5').update(x, 'utf8').digest('hex');
|
11608 | }
|
11609 |
|
11610 | module.exports = {
|
11611 | writeAll: writeAll
|
11612 | };
|
11613 |
|
11614 | /***/ }),
|
11615 | /* 62 */
|
11616 | /***/ (function(module, exports, __webpack_require__) {
|
11617 |
|
11618 | "use strict";
|
11619 | /**
|
11620 | * Copyright (c) Facebook, Inc. and its affiliates.
|
11621 | *
|
11622 | * This source code is licensed under the MIT license found in the
|
11623 | * LICENSE file in the root directory of this source tree.
|
11624 | *
|
11625 | *
|
11626 | * @format
|
11627 | */
|
11628 |
|
11629 |
|
11630 | var OR_LIST_MAX_LENGTH = 5;
|
11631 |
|
11632 | var _require = __webpack_require__(1),
|
11633 | createCompilerError = _require.createCompilerError;
|
11634 |
|
11635 | function orList(items) {
|
11636 | if (items.length === 0) {
|
11637 | throw createCompilerError('Expected an array of strings. Got empty array');
|
11638 | }
|
11639 |
|
11640 | if (items.length === 1) {
|
11641 | return items[0];
|
11642 | }
|
11643 |
|
11644 | if (items.length > OR_LIST_MAX_LENGTH) {
|
11645 | return items.slice(0, OR_LIST_MAX_LENGTH).join(', ') + ', ...';
|
11646 | }
|
11647 |
|
11648 | var selected = items.slice();
|
11649 | var lastItem = selected.pop();
|
11650 | return selected.join(', ') + ' or ' + lastItem;
|
11651 | }
|
11652 |
|
11653 | module.exports = orList;
|
11654 |
|
11655 | /***/ }),
|
11656 | /* 63 */
|
11657 | /***/ (function(module, exports, __webpack_require__) {
|
11658 |
|
11659 | "use strict";
|
11660 | /**
|
11661 | * Copyright (c) Facebook, Inc. and its affiliates.
|
11662 | *
|
11663 | * This source code is licensed under the MIT license found in the
|
11664 | * LICENSE file in the root directory of this source tree.
|
11665 | *
|
11666 | *
|
11667 | * @format
|
11668 | */
|
11669 |
|
11670 |
|
11671 | var _interopRequireDefault = __webpack_require__(0);
|
11672 |
|
11673 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
11674 |
|
11675 | var Printer = __webpack_require__(31);
|
11676 |
|
11677 | var Profiler = __webpack_require__(6);
|
11678 |
|
11679 | var RelayCodeGenerator = __webpack_require__(64);
|
11680 |
|
11681 | var filterContextForNode = __webpack_require__(67);
|
11682 |
|
11683 | function createFragmentContext(context, transforms, reporter) {
|
11684 | // The fragment is used for reading data from the normalized store.
|
11685 | return context.applyTransforms([].concat((0, _toConsumableArray2["default"])(transforms.commonTransforms), (0, _toConsumableArray2["default"])(transforms.fragmentTransforms)), reporter);
|
11686 | }
|
11687 |
|
11688 | function createPrintContext(context, transforms, reporter) {
|
11689 | // The unflattened query is used for printing, since flattening creates an
|
11690 | // invalid query.
|
11691 | return context.applyTransforms([].concat((0, _toConsumableArray2["default"])(transforms.commonTransforms), (0, _toConsumableArray2["default"])(transforms.queryTransforms), (0, _toConsumableArray2["default"])(transforms.printTransforms)), reporter);
|
11692 | }
|
11693 |
|
11694 | function createCodeGenContext(context, transforms, reporter) {
|
11695 | // The flattened query is used for codegen in order to reduce the number of
|
11696 | // duplicate fields that must be processed during response normalization.
|
11697 | return context.applyTransforms([].concat((0, _toConsumableArray2["default"])(transforms.commonTransforms), (0, _toConsumableArray2["default"])(transforms.queryTransforms), (0, _toConsumableArray2["default"])(transforms.codegenTransforms)), reporter);
|
11698 | }
|
11699 |
|
11700 | function compile(context, fragmentContext, printContext, codeGenContext) {
|
11701 | var results = [];
|
11702 | var schema = context.getSchema(); // Add everything from codeGenContext, these are the operations as well as
|
11703 | // SplitOperations from @match.
|
11704 |
|
11705 | var _iteratorNormalCompletion = true;
|
11706 | var _didIteratorError = false;
|
11707 | var _iteratorError = undefined;
|
11708 |
|
11709 | try {
|
11710 | for (var _iterator = codeGenContext.documents()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
11711 | var node = _step.value;
|
11712 |
|
11713 | if (node.kind === 'Root') {
|
11714 | var fragment = fragmentContext.getRoot(node.name);
|
11715 | var request = {
|
11716 | kind: 'Request',
|
11717 | fragment: {
|
11718 | kind: 'Fragment',
|
11719 | argumentDefinitions: fragment.argumentDefinitions,
|
11720 | directives: fragment.directives,
|
11721 | loc: {
|
11722 | kind: 'Derived',
|
11723 | source: node.loc
|
11724 | },
|
11725 | metadata: null,
|
11726 | name: fragment.name,
|
11727 | selections: fragment.selections,
|
11728 | type: fragment.type
|
11729 | },
|
11730 | id: null,
|
11731 | loc: node.loc,
|
11732 | metadata: node.metadata || {},
|
11733 | name: fragment.name,
|
11734 | root: node,
|
11735 | text: printOperation(printContext, fragment.name)
|
11736 | };
|
11737 | results.push([request, RelayCodeGenerator.generate(schema, request)]);
|
11738 | } else {
|
11739 | results.push([node, RelayCodeGenerator.generate(schema, node)]);
|
11740 | }
|
11741 | } // Add all the Fragments from the fragmentContext for the reader ASTs.
|
11742 |
|
11743 | } catch (err) {
|
11744 | _didIteratorError = true;
|
11745 | _iteratorError = err;
|
11746 | } finally {
|
11747 | try {
|
11748 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
11749 | _iterator["return"]();
|
11750 | }
|
11751 | } finally {
|
11752 | if (_didIteratorError) {
|
11753 | throw _iteratorError;
|
11754 | }
|
11755 | }
|
11756 | }
|
11757 |
|
11758 | var _iteratorNormalCompletion2 = true;
|
11759 | var _didIteratorError2 = false;
|
11760 | var _iteratorError2 = undefined;
|
11761 |
|
11762 | try {
|
11763 | for (var _iterator2 = fragmentContext.documents()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
11764 | var _node = _step2.value;
|
11765 |
|
11766 | if (_node.kind === 'Fragment') {
|
11767 | results.push([_node, RelayCodeGenerator.generate(schema, _node)]);
|
11768 | }
|
11769 | }
|
11770 | } catch (err) {
|
11771 | _didIteratorError2 = true;
|
11772 | _iteratorError2 = err;
|
11773 | } finally {
|
11774 | try {
|
11775 | if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
11776 | _iterator2["return"]();
|
11777 | }
|
11778 | } finally {
|
11779 | if (_didIteratorError2) {
|
11780 | throw _iteratorError2;
|
11781 | }
|
11782 | }
|
11783 | }
|
11784 |
|
11785 | return results;
|
11786 | }
|
11787 |
|
11788 | var OPERATION_ORDER = {
|
11789 | Root: 0,
|
11790 | SplitOperation: 1,
|
11791 | Fragment: 2
|
11792 | };
|
11793 |
|
11794 | function printOperation(printContext, name) {
|
11795 | var printableRoot = printContext.getRoot(name);
|
11796 | return filterContextForNode(printableRoot, printContext).documents().sort(function (a, b) {
|
11797 | if (a.kind !== b.kind) {
|
11798 | return OPERATION_ORDER[a.kind] - OPERATION_ORDER[b.kind];
|
11799 | }
|
11800 |
|
11801 | return a.name < b.name ? -1 : 1;
|
11802 | }).map(function (doc) {
|
11803 | return Printer.print(printContext.getSchema(), doc);
|
11804 | }).join('\n');
|
11805 | }
|
11806 | /**
|
11807 | * Transforms the provided compiler context
|
11808 | *
|
11809 | * compileRelayArtifacts generates artifacts for Relay's runtime as a result of
|
11810 | * applying a series of transforms. Each kind of artifact is dependent on
|
11811 | * transforms being applied in the following order:
|
11812 | *
|
11813 | * - Fragment Readers: commonTransforms, fragmentTransforms
|
11814 | * - Operation Writers: commonTransforms, queryTransforms, codegenTransforms
|
11815 | * - GraphQL Text: commonTransforms, queryTransforms, printTransforms
|
11816 | *
|
11817 | * The order of the transforms applied for each artifact below is important.
|
11818 | * CompilerContext will memoize applying each transform, so while
|
11819 | * `commonTransforms` appears in each artifacts' application, it will not result
|
11820 | * in repeated work as long as the order remains consistent across each context.
|
11821 | */
|
11822 |
|
11823 |
|
11824 | function compileRelayArtifacts(context, transforms, reporter) {
|
11825 | return Profiler.run('GraphQLCompiler.compile', function () {
|
11826 | var fragmentContext = createFragmentContext(context, transforms, reporter);
|
11827 | var printContext = createPrintContext(context, transforms, reporter);
|
11828 | var codeGenContext = createCodeGenContext(context, transforms, reporter);
|
11829 | return compile(context, fragmentContext, printContext, codeGenContext);
|
11830 | });
|
11831 | }
|
11832 |
|
11833 | module.exports = compileRelayArtifacts;
|
11834 |
|
11835 | /***/ }),
|
11836 | /* 64 */
|
11837 | /***/ (function(module, exports, __webpack_require__) {
|
11838 |
|
11839 | "use strict";
|
11840 | /**
|
11841 | * Copyright (c) Facebook, Inc. and its affiliates.
|
11842 | *
|
11843 | * This source code is licensed under the MIT license found in the
|
11844 | * LICENSE file in the root directory of this source tree.
|
11845 | *
|
11846 | *
|
11847 | * @format
|
11848 | */
|
11849 |
|
11850 |
|
11851 | var NormalizationCodeGenerator = __webpack_require__(65);
|
11852 |
|
11853 | var ReaderCodeGenerator = __webpack_require__(66);
|
11854 |
|
11855 | var _require = __webpack_require__(1),
|
11856 | createCompilerError = _require.createCompilerError;
|
11857 |
|
11858 | function generate(schema, node) {
|
11859 | var _node$metadata;
|
11860 |
|
11861 | switch (node.kind) {
|
11862 | case 'Fragment':
|
11863 | if (((_node$metadata = node.metadata) === null || _node$metadata === void 0 ? void 0 : _node$metadata.inlineData) === true) {
|
11864 | return {
|
11865 | kind: 'InlineDataFragment',
|
11866 | name: node.name
|
11867 | };
|
11868 | }
|
11869 |
|
11870 | return ReaderCodeGenerator.generate(schema, node);
|
11871 |
|
11872 | case 'Request':
|
11873 | return {
|
11874 | kind: 'Request',
|
11875 | fragment: ReaderCodeGenerator.generate(schema, node.fragment),
|
11876 | operation: NormalizationCodeGenerator.generate(schema, node.root),
|
11877 | params: {
|
11878 | operationKind: node.root.operation,
|
11879 | name: node.name,
|
11880 | id: node.id,
|
11881 | text: node.text,
|
11882 | metadata: node.metadata
|
11883 | }
|
11884 | };
|
11885 |
|
11886 | case 'SplitOperation':
|
11887 | return NormalizationCodeGenerator.generate(schema, node);
|
11888 | }
|
11889 |
|
11890 | throw createCompilerError("RelayCodeGenerator: Unknown AST kind '".concat(node.kind, "'."), [node.loc]);
|
11891 | }
|
11892 |
|
11893 | module.exports = {
|
11894 | generate: generate
|
11895 | };
|
11896 |
|
11897 | /***/ }),
|
11898 | /* 65 */
|
11899 | /***/ (function(module, exports, __webpack_require__) {
|
11900 |
|
11901 | "use strict";
|
11902 | /**
|
11903 | * Copyright (c) Facebook, Inc. and its affiliates.
|
11904 | *
|
11905 | * This source code is licensed under the MIT license found in the
|
11906 | * LICENSE file in the root directory of this source tree.
|
11907 | *
|
11908 | *
|
11909 | * @format
|
11910 | */
|
11911 |
|
11912 |
|
11913 | var _interopRequireDefault = __webpack_require__(0);
|
11914 |
|
11915 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
11916 |
|
11917 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
11918 |
|
11919 | var _require = __webpack_require__(1),
|
11920 | createCompilerError = _require.createCompilerError,
|
11921 | createUserError = _require.createUserError;
|
11922 |
|
11923 | var _require2 = __webpack_require__(9),
|
11924 | ConnectionInterface = _require2.ConnectionInterface,
|
11925 | getStorageKey = _require2.getStorageKey,
|
11926 | stableCopy = _require2.stableCopy;
|
11927 |
|
11928 | function generate(schema, node) {
|
11929 | switch (node.kind) {
|
11930 | case 'Root':
|
11931 | return generateRoot(schema, node);
|
11932 |
|
11933 | case 'SplitOperation':
|
11934 | return generateSplitOperation(schema, node);
|
11935 |
|
11936 | default:
|
11937 | throw createCompilerError("NormalizationCodeGenerator: Unsupported AST kind '".concat(node.kind, "'."), [node.loc]);
|
11938 | }
|
11939 | }
|
11940 |
|
11941 | function generateRoot(schema, node) {
|
11942 | return {
|
11943 | kind: 'Operation',
|
11944 | name: node.name,
|
11945 | argumentDefinitions: generateArgumentDefinitions(schema, node.argumentDefinitions),
|
11946 | selections: generateSelections(schema, node.selections)
|
11947 | };
|
11948 | }
|
11949 |
|
11950 | function generateSplitOperation(schema, node) {
|
11951 | return {
|
11952 | kind: 'SplitOperation',
|
11953 | name: node.name,
|
11954 | metadata: node.metadata,
|
11955 | selections: generateSelections(schema, node.selections)
|
11956 | };
|
11957 | }
|
11958 |
|
11959 | function generateSelections(schema, selections) {
|
11960 | var normalizationSelections = [];
|
11961 | selections.forEach(function (selection) {
|
11962 | switch (selection.kind) {
|
11963 | case 'Condition':
|
11964 | normalizationSelections.push(generateCondition(schema, selection));
|
11965 | break;
|
11966 |
|
11967 | case 'ClientExtension':
|
11968 | normalizationSelections.push(generateClientExtension(schema, selection));
|
11969 | break;
|
11970 |
|
11971 | case 'ScalarField':
|
11972 | normalizationSelections.push.apply(normalizationSelections, (0, _toConsumableArray2["default"])(generateScalarField(selection)));
|
11973 | break;
|
11974 |
|
11975 | case 'ModuleImport':
|
11976 | normalizationSelections.push(generateModuleImport(selection));
|
11977 | break;
|
11978 |
|
11979 | case 'InlineFragment':
|
11980 | normalizationSelections.push(generateInlineFragment(schema, selection));
|
11981 | break;
|
11982 |
|
11983 | case 'LinkedField':
|
11984 | normalizationSelections.push.apply(normalizationSelections, (0, _toConsumableArray2["default"])(generateLinkedField(schema, selection)));
|
11985 | break;
|
11986 |
|
11987 | case 'ConnectionField':
|
11988 | normalizationSelections.push.apply(normalizationSelections, (0, _toConsumableArray2["default"])(generateConnectionField(schema, selection)));
|
11989 | break;
|
11990 |
|
11991 | case 'Connection':
|
11992 | normalizationSelections.push(generateConnection(schema, selection));
|
11993 | break;
|
11994 |
|
11995 | case 'Defer':
|
11996 | normalizationSelections.push(generateDefer(schema, selection));
|
11997 | break;
|
11998 |
|
11999 | case 'Stream':
|
12000 | normalizationSelections.push(generateStream(schema, selection));
|
12001 | break;
|
12002 |
|
12003 | case 'InlineDataFragmentSpread':
|
12004 | case 'FragmentSpread':
|
12005 | throw new createCompilerError("NormalizationCodeGenerator: Unexpected IR node ".concat(selection.kind, "."), [selection.loc]);
|
12006 |
|
12007 | default:
|
12008 | selection;
|
12009 | throw new Error();
|
12010 | }
|
12011 | });
|
12012 | return normalizationSelections;
|
12013 | }
|
12014 |
|
12015 | function generateArgumentDefinitions(schema, nodes) {
|
12016 | return nodes.map(function (node) {
|
12017 | return {
|
12018 | kind: 'LocalArgument',
|
12019 | name: node.name,
|
12020 | type: schema.getTypeString(node.type),
|
12021 | defaultValue: node.defaultValue
|
12022 | };
|
12023 | });
|
12024 | }
|
12025 |
|
12026 | function generateClientExtension(schema, node) {
|
12027 | return {
|
12028 | kind: 'ClientExtension',
|
12029 | selections: generateSelections(schema, node.selections)
|
12030 | };
|
12031 | }
|
12032 |
|
12033 | function generateCondition(schema, node) {
|
12034 | if (node.condition.kind !== 'Variable') {
|
12035 | throw createCompilerError("NormalizationCodeGenerator: Expected 'Condition' with static " + 'value to be pruned or inlined', [node.condition.loc]);
|
12036 | }
|
12037 |
|
12038 | return {
|
12039 | kind: 'Condition',
|
12040 | passingValue: node.passingValue,
|
12041 | condition: node.condition.variableName,
|
12042 | selections: generateSelections(schema, node.selections)
|
12043 | };
|
12044 | }
|
12045 |
|
12046 | function generateDefer(schema, node) {
|
12047 | if (!(node["if"] == null || node["if"].kind === 'Variable' || node["if"].kind === 'Literal' && node["if"].value === true)) {
|
12048 | var _ref, _node$if;
|
12049 |
|
12050 | throw createCompilerError('NormalizationCodeGenerator: Expected @defer `if` condition to be ' + 'a variable, unspecified, or the literal `true`.', [(_ref = (_node$if = node["if"]) === null || _node$if === void 0 ? void 0 : _node$if.loc) !== null && _ref !== void 0 ? _ref : node.loc]);
|
12051 | }
|
12052 |
|
12053 | return {
|
12054 | "if": node["if"] != null && node["if"].kind === 'Variable' ? node["if"].variableName : null,
|
12055 | kind: 'Defer',
|
12056 | label: node.label,
|
12057 | metadata: node.metadata,
|
12058 | selections: generateSelections(schema, node.selections)
|
12059 | };
|
12060 | }
|
12061 |
|
12062 | function generateInlineFragment(schema, node) {
|
12063 | return {
|
12064 | kind: 'InlineFragment',
|
12065 | type: schema.getTypeString(node.typeCondition),
|
12066 | selections: generateSelections(schema, node.selections)
|
12067 | };
|
12068 | }
|
12069 |
|
12070 | function generateLinkedField(schema, node) {
|
12071 | // Note: it is important that the arguments of this field be sorted to
|
12072 | // ensure stable generation of storage keys for equivalent arguments
|
12073 | // which may have originally appeared in different orders across an app.
|
12074 | var handles = node.handles && node.handles.map(function (handle) {
|
12075 | var handleNode = {
|
12076 | kind: 'LinkedHandle',
|
12077 | alias: node.alias === node.name ? null : node.alias,
|
12078 | name: node.name,
|
12079 | args: generateArgs(node.args),
|
12080 | handle: handle.name,
|
12081 | key: handle.key,
|
12082 | filters: handle.filters
|
12083 | }; // T45504512: new connection model
|
12084 | // NOTE: this intentionally adds a dynamic key in order to avoid
|
12085 | // triggering updates to existing queries that do not use dynamic
|
12086 | // keys.
|
12087 |
|
12088 | if (handle.dynamicKey != null) {
|
12089 | var dynamicKeyArgName = '__dynamicKey';
|
12090 | handleNode = (0, _objectSpread2["default"])({}, handleNode, {
|
12091 | dynamicKey: {
|
12092 | kind: 'Variable',
|
12093 | name: dynamicKeyArgName,
|
12094 | variableName: handle.dynamicKey.variableName
|
12095 | }
|
12096 | });
|
12097 | }
|
12098 |
|
12099 | return handleNode;
|
12100 | }) || [];
|
12101 | var type = schema.getRawType(node.type);
|
12102 | var field = {
|
12103 | kind: 'LinkedField',
|
12104 | alias: node.alias === node.name ? null : node.alias,
|
12105 | name: node.name,
|
12106 | storageKey: null,
|
12107 | args: generateArgs(node.args),
|
12108 | concreteType: !schema.isAbstractType(type) ? schema.getTypeString(type) : null,
|
12109 | plural: isPlural(schema, node.type),
|
12110 | selections: generateSelections(schema, node.selections)
|
12111 | }; // Precompute storageKey if possible
|
12112 |
|
12113 | var storageKey = getStaticStorageKey(field, node.metadata);
|
12114 |
|
12115 | if (storageKey != null) {
|
12116 | field = (0, _objectSpread2["default"])({}, field, {
|
12117 | storageKey: storageKey
|
12118 | });
|
12119 | }
|
12120 |
|
12121 | return [field].concat(handles);
|
12122 | }
|
12123 |
|
12124 | function generateConnectionField(schema, node) {
|
12125 | return generateLinkedField(schema, {
|
12126 | name: node.name,
|
12127 | alias: node.alias,
|
12128 | loc: node.loc,
|
12129 | directives: node.directives,
|
12130 | metadata: node.metadata,
|
12131 | selections: node.selections,
|
12132 | type: node.type,
|
12133 | handles: null,
|
12134 | connection: false,
|
12135 | // this is only on the linked fields with @conneciton
|
12136 | args: node.args.filter(function (arg) {
|
12137 | return !ConnectionInterface.isConnectionCall({
|
12138 | name: arg.name,
|
12139 | value: null
|
12140 | });
|
12141 | }),
|
12142 | kind: 'LinkedField'
|
12143 | });
|
12144 | }
|
12145 |
|
12146 | function generateConnection(schema, node) {
|
12147 | var _ConnectionInterface$ = ConnectionInterface.get(),
|
12148 | EDGES = _ConnectionInterface$.EDGES,
|
12149 | PAGE_INFO = _ConnectionInterface$.PAGE_INFO;
|
12150 |
|
12151 | var selections = generateSelections(schema, node.selections);
|
12152 | var edges;
|
12153 | var pageInfo;
|
12154 | selections.forEach(function (selection) {
|
12155 | if (selection.kind === 'LinkedField') {
|
12156 | if (selection.name === EDGES) {
|
12157 | edges = selection;
|
12158 | } else if (selection.name === PAGE_INFO) {
|
12159 | pageInfo = selection;
|
12160 | }
|
12161 | } else if (selection.kind === 'Stream') {
|
12162 | selection.selections.forEach(function (subselection) {
|
12163 | if (subselection.kind === 'LinkedField' && subselection.name === EDGES) {
|
12164 | edges = subselection;
|
12165 | }
|
12166 | });
|
12167 | } else if (selection.kind === 'Defer') {
|
12168 | selection.selections.forEach(function (subselection) {
|
12169 | if (subselection.kind === 'LinkedField' && subselection.name === PAGE_INFO) {
|
12170 | pageInfo = subselection;
|
12171 | }
|
12172 | });
|
12173 | }
|
12174 | });
|
12175 |
|
12176 | if (edges == null || pageInfo == null) {
|
12177 | throw createUserError("Invalid connection, expected the '".concat(EDGES, "' and '").concat(PAGE_INFO, "' fields ") + 'to exist.', [node.loc]);
|
12178 | }
|
12179 |
|
12180 | var stream = null;
|
12181 |
|
12182 | if (node.stream != null) {
|
12183 | var _generateArgumentValu;
|
12184 |
|
12185 | var trueLiteral = {
|
12186 | kind: 'Literal',
|
12187 | name: 'if',
|
12188 | value: true
|
12189 | };
|
12190 | stream = {
|
12191 | "if": node.stream["if"] != null ? (_generateArgumentValu = generateArgumentValue('if', node.stream["if"])) !== null && _generateArgumentValu !== void 0 ? _generateArgumentValu : trueLiteral : trueLiteral,
|
12192 | deferLabel: node.stream.deferLabel,
|
12193 | streamLabel: node.stream.streamLabel
|
12194 | };
|
12195 | }
|
12196 |
|
12197 | return {
|
12198 | kind: 'Connection',
|
12199 | label: node.label,
|
12200 | name: node.name,
|
12201 | args: generateArgs(node.args),
|
12202 | edges: edges,
|
12203 | pageInfo: pageInfo,
|
12204 | stream: stream
|
12205 | };
|
12206 | }
|
12207 |
|
12208 | function generateModuleImport(node, key) {
|
12209 | var fragmentName = node.name;
|
12210 | var regExpMatch = fragmentName.match(/^([a-zA-Z][a-zA-Z0-9]*)(?:_([a-zA-Z][_a-zA-Z0-9]*))?$/);
|
12211 |
|
12212 | if (!regExpMatch) {
|
12213 | throw createCompilerError('NormalizationCodeGenerator: @module fragments should be named ' + "'FragmentName_propName', got '".concat(fragmentName, "'."), [node.loc]);
|
12214 | }
|
12215 |
|
12216 | var fragmentPropName = regExpMatch[2];
|
12217 |
|
12218 | if (typeof fragmentPropName !== 'string') {
|
12219 | throw createCompilerError('NormalizationCodeGenerator: @module fragments should be named ' + "'FragmentName_propName', got '".concat(fragmentName, "'."), [node.loc]);
|
12220 | }
|
12221 |
|
12222 | return {
|
12223 | kind: 'ModuleImport',
|
12224 | documentName: node.documentName,
|
12225 | fragmentName: fragmentName,
|
12226 | fragmentPropName: fragmentPropName
|
12227 | };
|
12228 | }
|
12229 |
|
12230 | function generateScalarField(node) {
|
12231 | var _node$metadata;
|
12232 |
|
12233 | if ((_node$metadata = node.metadata) === null || _node$metadata === void 0 ? void 0 : _node$metadata.skipNormalizationNode) {
|
12234 | return [];
|
12235 | } // Note: it is important that the arguments of this field be sorted to
|
12236 | // ensure stable generation of storage keys for equivalent arguments
|
12237 | // which may have originally appeared in different orders across an app.
|
12238 |
|
12239 |
|
12240 | var handles = node.handles && node.handles.map(function (handle) {
|
12241 | if (handle.dynamicKey != null) {
|
12242 | throw createUserError('Dynamic key values are not supported on scalar fields.', [handle.dynamicKey.loc]);
|
12243 | }
|
12244 |
|
12245 | return {
|
12246 | kind: 'ScalarHandle',
|
12247 | alias: node.alias === node.name ? null : node.alias,
|
12248 | name: node.name,
|
12249 | args: generateArgs(node.args),
|
12250 | handle: handle.name,
|
12251 | key: handle.key,
|
12252 | filters: handle.filters
|
12253 | };
|
12254 | }) || [];
|
12255 | var field = {
|
12256 | kind: 'ScalarField',
|
12257 | alias: node.alias === node.name ? null : node.alias,
|
12258 | name: node.name,
|
12259 | args: generateArgs(node.args),
|
12260 | storageKey: null
|
12261 | }; // Precompute storageKey if possible
|
12262 |
|
12263 | var storageKey = getStaticStorageKey(field, node.metadata);
|
12264 |
|
12265 | if (storageKey != null) {
|
12266 | field = (0, _objectSpread2["default"])({}, field, {
|
12267 | storageKey: storageKey
|
12268 | });
|
12269 | }
|
12270 |
|
12271 | return [field].concat(handles);
|
12272 | }
|
12273 |
|
12274 | function generateStream(schema, node) {
|
12275 | if (!(node["if"] == null || node["if"].kind === 'Variable' || node["if"].kind === 'Literal' && node["if"].value === true)) {
|
12276 | var _ref2, _node$if2;
|
12277 |
|
12278 | throw createCompilerError('NormalizationCodeGenerator: Expected @stream `if` condition to be ' + 'a variable, unspecified, or the literal `true`.', [(_ref2 = (_node$if2 = node["if"]) === null || _node$if2 === void 0 ? void 0 : _node$if2.loc) !== null && _ref2 !== void 0 ? _ref2 : node.loc]);
|
12279 | }
|
12280 |
|
12281 | return {
|
12282 | "if": node["if"] != null && node["if"].kind === 'Variable' ? node["if"].variableName : null,
|
12283 | kind: 'Stream',
|
12284 | label: node.label,
|
12285 | metadata: node.metadata,
|
12286 | selections: generateSelections(schema, node.selections)
|
12287 | };
|
12288 | }
|
12289 |
|
12290 | function generateArgumentValue(name, value) {
|
12291 | switch (value.kind) {
|
12292 | case 'Variable':
|
12293 | return {
|
12294 | kind: 'Variable',
|
12295 | name: name,
|
12296 | variableName: value.variableName
|
12297 | };
|
12298 |
|
12299 | case 'Literal':
|
12300 | return value.value === null ? null : {
|
12301 | kind: 'Literal',
|
12302 | name: name,
|
12303 | value: stableCopy(value.value)
|
12304 | };
|
12305 |
|
12306 | default:
|
12307 | throw createUserError('NormalizationCodeGenerator: Complex argument values (Lists or ' + 'InputObjects with nested variables) are not supported.', [value.loc]);
|
12308 | }
|
12309 | }
|
12310 |
|
12311 | function generateArgs(args) {
|
12312 | var concreteArguments = [];
|
12313 | args.forEach(function (arg) {
|
12314 | var concreteArgument = generateArgumentValue(arg.name, arg.value);
|
12315 |
|
12316 | if (concreteArgument !== null) {
|
12317 | concreteArguments.push(concreteArgument);
|
12318 | }
|
12319 | });
|
12320 | return concreteArguments.length === 0 ? null : concreteArguments.sort(nameComparator);
|
12321 | }
|
12322 |
|
12323 | function nameComparator(a, b) {
|
12324 | return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
12325 | }
|
12326 | /**
|
12327 | * Pre-computes storage key if possible and advantageous. Storage keys are
|
12328 | * generated for fields with supplied arguments that are all statically known
|
12329 | * (ie. literals, no variables) at build time.
|
12330 | */
|
12331 |
|
12332 |
|
12333 | function getStaticStorageKey(field, metadata) {
|
12334 | var metadataStorageKey = metadata === null || metadata === void 0 ? void 0 : metadata.storageKey;
|
12335 |
|
12336 | if (typeof metadataStorageKey === 'string') {
|
12337 | return metadataStorageKey;
|
12338 | }
|
12339 |
|
12340 | if (!field.args || field.args.length === 0 || field.args.some(function (arg) {
|
12341 | return arg.kind !== 'Literal';
|
12342 | })) {
|
12343 | return null;
|
12344 | }
|
12345 |
|
12346 | return getStorageKey(field, {});
|
12347 | }
|
12348 |
|
12349 | function isPlural(schema, type) {
|
12350 | return schema.isList(schema.getNullableType(type));
|
12351 | }
|
12352 |
|
12353 | module.exports = {
|
12354 | generate: generate
|
12355 | };
|
12356 |
|
12357 | /***/ }),
|
12358 | /* 66 */
|
12359 | /***/ (function(module, exports, __webpack_require__) {
|
12360 |
|
12361 | "use strict";
|
12362 | /**
|
12363 | * Copyright (c) Facebook, Inc. and its affiliates.
|
12364 | *
|
12365 | * This source code is licensed under the MIT license found in the
|
12366 | * LICENSE file in the root directory of this source tree.
|
12367 | *
|
12368 | *
|
12369 | * @format
|
12370 | */
|
12371 |
|
12372 |
|
12373 | var _interopRequireDefault = __webpack_require__(0);
|
12374 |
|
12375 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
12376 |
|
12377 | var CodeMarker = __webpack_require__(32);
|
12378 |
|
12379 | var _require = __webpack_require__(1),
|
12380 | createCompilerError = _require.createCompilerError,
|
12381 | createUserError = _require.createUserError;
|
12382 |
|
12383 | var _require2 = __webpack_require__(9),
|
12384 | ConnectionInterface = _require2.ConnectionInterface,
|
12385 | getStorageKey = _require2.getStorageKey,
|
12386 | stableCopy = _require2.stableCopy;
|
12387 |
|
12388 | /**
|
12389 | * @public
|
12390 | *
|
12391 | * Converts a GraphQLIR node into a plain JS object representation that can be
|
12392 | * used at runtime.
|
12393 | */
|
12394 | function generate(schema, node) {
|
12395 | if (node == null) {
|
12396 | return node;
|
12397 | }
|
12398 |
|
12399 | var metadata = null;
|
12400 |
|
12401 | if (node.metadata != null) {
|
12402 | var _node$metadata = node.metadata,
|
12403 | mask = _node$metadata.mask,
|
12404 | plural = _node$metadata.plural,
|
12405 | connection = _node$metadata.connection,
|
12406 | refetch = _node$metadata.refetch;
|
12407 |
|
12408 | if (Array.isArray(connection)) {
|
12409 | var _metadata;
|
12410 |
|
12411 | metadata = (_metadata = metadata) !== null && _metadata !== void 0 ? _metadata : {};
|
12412 | metadata.connection = connection;
|
12413 | }
|
12414 |
|
12415 | if (typeof mask === 'boolean') {
|
12416 | var _metadata2;
|
12417 |
|
12418 | metadata = (_metadata2 = metadata) !== null && _metadata2 !== void 0 ? _metadata2 : {};
|
12419 | metadata.mask = mask;
|
12420 | }
|
12421 |
|
12422 | if (typeof plural === 'boolean') {
|
12423 | var _metadata3;
|
12424 |
|
12425 | metadata = (_metadata3 = metadata) !== null && _metadata3 !== void 0 ? _metadata3 : {};
|
12426 | metadata.plural = plural;
|
12427 | }
|
12428 |
|
12429 | if (typeof refetch === 'object') {
|
12430 | var _metadata4;
|
12431 |
|
12432 | metadata = (_metadata4 = metadata) !== null && _metadata4 !== void 0 ? _metadata4 : {};
|
12433 | metadata.refetch = {
|
12434 | // $FlowFixMe
|
12435 | connection: refetch.connection,
|
12436 | // $FlowFixMe
|
12437 | operation: CodeMarker.moduleDependency(refetch.operation + '.graphql'),
|
12438 | // $FlowFixMe
|
12439 | fragmentPathInResult: refetch.fragmentPathInResult
|
12440 | };
|
12441 | }
|
12442 | }
|
12443 |
|
12444 | return {
|
12445 | kind: 'Fragment',
|
12446 | name: node.name,
|
12447 | type: schema.getTypeString(node.type),
|
12448 | // $FlowFixMe
|
12449 | metadata: metadata,
|
12450 | argumentDefinitions: generateArgumentDefinitions(schema, node.argumentDefinitions),
|
12451 | selections: generateSelections(schema, node.selections)
|
12452 | };
|
12453 | }
|
12454 |
|
12455 | function generateSelections(schema, selections) {
|
12456 | return selections.map(function (selection) {
|
12457 | switch (selection.kind) {
|
12458 | case 'ClientExtension':
|
12459 | return generateClientExtension(schema, selection);
|
12460 |
|
12461 | case 'FragmentSpread':
|
12462 | return generateFragmentSpread(schema, selection);
|
12463 |
|
12464 | case 'Condition':
|
12465 | return generateCondition(schema, selection);
|
12466 |
|
12467 | case 'ScalarField':
|
12468 | return generateScalarField(schema, selection);
|
12469 |
|
12470 | case 'ModuleImport':
|
12471 | return generateModuleImport(schema, selection);
|
12472 |
|
12473 | case 'InlineDataFragmentSpread':
|
12474 | return generateInlineDataFragmentSpread(schema, selection);
|
12475 |
|
12476 | case 'InlineFragment':
|
12477 | return generateInlineFragment(schema, selection);
|
12478 |
|
12479 | case 'LinkedField':
|
12480 | return generateLinkedField(schema, selection);
|
12481 |
|
12482 | case 'ConnectionField':
|
12483 | return generateConnectionField(schema, selection);
|
12484 |
|
12485 | case 'Connection':
|
12486 | return generateConnection(schema, selection);
|
12487 |
|
12488 | case 'Defer':
|
12489 | return generateDefer(schema, selection);
|
12490 |
|
12491 | case 'Stream':
|
12492 | return generateStream(schema, selection);
|
12493 |
|
12494 | default:
|
12495 | selection;
|
12496 | throw new Error();
|
12497 | }
|
12498 | }).filter(Boolean);
|
12499 | }
|
12500 |
|
12501 | function generateArgumentDefinitions(schema, nodes) {
|
12502 | return nodes.map(function (node) {
|
12503 | switch (node.kind) {
|
12504 | case 'LocalArgumentDefinition':
|
12505 | return {
|
12506 | kind: 'LocalArgument',
|
12507 | name: node.name,
|
12508 | type: schema.getTypeString(node.type),
|
12509 | defaultValue: node.defaultValue
|
12510 | };
|
12511 |
|
12512 | case 'RootArgumentDefinition':
|
12513 | return {
|
12514 | kind: 'RootArgument',
|
12515 | name: node.name,
|
12516 | type: node.type ? schema.getTypeString(node.type) : null
|
12517 | };
|
12518 |
|
12519 | default:
|
12520 | throw new Error();
|
12521 | }
|
12522 | });
|
12523 | }
|
12524 |
|
12525 | function generateClientExtension(schema, node) {
|
12526 | return {
|
12527 | kind: 'ClientExtension',
|
12528 | selections: generateSelections(schema, node.selections)
|
12529 | };
|
12530 | }
|
12531 |
|
12532 | function generateDefer(schema, node) {
|
12533 | return {
|
12534 | kind: 'Defer',
|
12535 | selections: generateSelections(schema, node.selections)
|
12536 | };
|
12537 | }
|
12538 |
|
12539 | function generateStream(schema, node) {
|
12540 | return {
|
12541 | kind: 'Stream',
|
12542 | selections: generateSelections(schema, node.selections)
|
12543 | };
|
12544 | }
|
12545 |
|
12546 | function generateCondition(schema, node) {
|
12547 | if (node.condition.kind !== 'Variable') {
|
12548 | throw createCompilerError("ReaderCodeGenerator: Expected 'Condition' with static value to be " + 'pruned or inlined', [node.condition.loc]);
|
12549 | }
|
12550 |
|
12551 | return {
|
12552 | kind: 'Condition',
|
12553 | passingValue: node.passingValue,
|
12554 | condition: node.condition.variableName,
|
12555 | selections: generateSelections(schema, node.selections)
|
12556 | };
|
12557 | }
|
12558 |
|
12559 | function generateFragmentSpread(schema, node) {
|
12560 | return {
|
12561 | kind: 'FragmentSpread',
|
12562 | name: node.name,
|
12563 | args: generateArgs(node.args)
|
12564 | };
|
12565 | }
|
12566 |
|
12567 | function generateInlineFragment(schema, node) {
|
12568 | return {
|
12569 | kind: 'InlineFragment',
|
12570 | type: schema.getTypeString(node.typeCondition),
|
12571 | selections: generateSelections(schema, node.selections)
|
12572 | };
|
12573 | }
|
12574 |
|
12575 | function generateInlineDataFragmentSpread(schema, node) {
|
12576 | return {
|
12577 | kind: 'InlineDataFragmentSpread',
|
12578 | name: node.name,
|
12579 | selections: generateSelections(schema, node.selections)
|
12580 | };
|
12581 | }
|
12582 |
|
12583 | function generateLinkedField(schema, node) {
|
12584 | // Note: it is important that the arguments of this field be sorted to
|
12585 | // ensure stable generation of storage keys for equivalent arguments
|
12586 | // which may have originally appeared in different orders across an app.
|
12587 | // TODO(T37646905) enable this invariant after splitting the
|
12588 | // RelayCodeGenerator-test and running the FieldHandleTransform on
|
12589 | // Reader ASTs.
|
12590 | //
|
12591 | // invariant(
|
12592 | // node.handles == null,
|
12593 | // 'ReaderCodeGenerator: unexpected handles',
|
12594 | // );
|
12595 | var rawType = schema.getRawType(node.type);
|
12596 | var field = {
|
12597 | kind: 'LinkedField',
|
12598 | alias: node.alias === node.name ? null : node.alias,
|
12599 | name: node.name,
|
12600 | storageKey: null,
|
12601 | args: generateArgs(node.args),
|
12602 | concreteType: !schema.isAbstractType(rawType) ? schema.getTypeString(rawType) : null,
|
12603 | plural: isPlural(schema, node.type),
|
12604 | selections: generateSelections(schema, node.selections)
|
12605 | }; // Precompute storageKey if possible
|
12606 |
|
12607 | var storageKey = getStaticStorageKey(field, node.metadata);
|
12608 |
|
12609 | if (storageKey) {
|
12610 | field = (0, _objectSpread2["default"])({}, field, {
|
12611 | storageKey: storageKey
|
12612 | });
|
12613 | }
|
12614 |
|
12615 | return field;
|
12616 | }
|
12617 |
|
12618 | function generateConnectionField(schema, node) {
|
12619 | return generateLinkedField(schema, {
|
12620 | name: node.name,
|
12621 | alias: node.alias,
|
12622 | loc: node.loc,
|
12623 | directives: node.directives,
|
12624 | metadata: node.metadata,
|
12625 | selections: node.selections,
|
12626 | type: node.type,
|
12627 | connection: false,
|
12628 | // this is only on the linked fields with @conneciton
|
12629 | handles: null,
|
12630 | args: node.args.filter(function (arg) {
|
12631 | return !ConnectionInterface.isConnectionCall({
|
12632 | name: arg.name,
|
12633 | value: null
|
12634 | });
|
12635 | }),
|
12636 | kind: 'LinkedField'
|
12637 | });
|
12638 | }
|
12639 |
|
12640 | function generateConnection(schema, node) {
|
12641 | var _ConnectionInterface$ = ConnectionInterface.get(),
|
12642 | EDGES = _ConnectionInterface$.EDGES,
|
12643 | PAGE_INFO = _ConnectionInterface$.PAGE_INFO;
|
12644 |
|
12645 | var selections = generateSelections(schema, node.selections);
|
12646 | var edges;
|
12647 | var pageInfo;
|
12648 | selections.forEach(function (selection) {
|
12649 | if (selection.kind === 'LinkedField') {
|
12650 | if (selection.name === EDGES) {
|
12651 | edges = selection;
|
12652 | } else if (selection.name === PAGE_INFO) {
|
12653 | pageInfo = selection;
|
12654 | }
|
12655 | } else if (selection.kind === 'Stream') {
|
12656 | selection.selections.forEach(function (subselection) {
|
12657 | if (subselection.kind === 'LinkedField' && subselection.name === EDGES) {
|
12658 | edges = subselection;
|
12659 | }
|
12660 | });
|
12661 | } else if (selection.kind === 'Defer') {
|
12662 | selection.selections.forEach(function (subselection) {
|
12663 | if (subselection.kind === 'LinkedField' && subselection.name === PAGE_INFO) {
|
12664 | pageInfo = subselection;
|
12665 | }
|
12666 | });
|
12667 | }
|
12668 | });
|
12669 |
|
12670 | if (edges == null || pageInfo == null) {
|
12671 | throw createUserError("Invalid connection, expected the '".concat(EDGES, "' and '").concat(PAGE_INFO, "' fields ") + 'to exist.', [node.loc]);
|
12672 | }
|
12673 |
|
12674 | return {
|
12675 | kind: 'Connection',
|
12676 | label: node.label,
|
12677 | name: node.name,
|
12678 | args: generateArgs(node.args),
|
12679 | edges: edges,
|
12680 | pageInfo: pageInfo
|
12681 | };
|
12682 | }
|
12683 |
|
12684 | function generateModuleImport(schema, node) {
|
12685 | var fragmentName = node.name;
|
12686 | var regExpMatch = fragmentName.match(/^([a-zA-Z][a-zA-Z0-9]*)(?:_([a-zA-Z][_a-zA-Z0-9]*))?$/);
|
12687 |
|
12688 | if (!regExpMatch) {
|
12689 | throw createCompilerError('ReaderCodeGenerator: @match fragments should be named ' + "'FragmentName_propName', got '".concat(fragmentName, "'."), [node.loc]);
|
12690 | }
|
12691 |
|
12692 | var fragmentPropName = regExpMatch[2];
|
12693 |
|
12694 | if (typeof fragmentPropName !== 'string') {
|
12695 | throw createCompilerError('ReaderCodeGenerator: @module fragments should be named ' + "'FragmentName_propName', got '".concat(fragmentName, "'."), [node.loc]);
|
12696 | }
|
12697 |
|
12698 | return {
|
12699 | kind: 'ModuleImport',
|
12700 | documentName: node.documentName,
|
12701 | fragmentName: fragmentName,
|
12702 | fragmentPropName: fragmentPropName
|
12703 | };
|
12704 | }
|
12705 |
|
12706 | function generateScalarField(schema, node) {
|
12707 | // Note: it is important that the arguments of this field be sorted to
|
12708 | // ensure stable generation of storage keys for equivalent arguments
|
12709 | // which may have originally appeared in different orders across an app.
|
12710 | // TODO(T37646905) enable this invariant after splitting the
|
12711 | // RelayCodeGenerator-test and running the FieldHandleTransform on
|
12712 | // Reader ASTs.
|
12713 | //
|
12714 | // invariant(
|
12715 | // node.handles == null,
|
12716 | // 'ReaderCodeGenerator: unexpected handles',
|
12717 | // );
|
12718 | var field = {
|
12719 | kind: 'ScalarField',
|
12720 | alias: node.alias === node.name ? null : node.alias,
|
12721 | name: node.name,
|
12722 | args: generateArgs(node.args),
|
12723 | storageKey: null
|
12724 | }; // Precompute storageKey if possible
|
12725 |
|
12726 | var storageKey = getStaticStorageKey(field, node.metadata);
|
12727 |
|
12728 | if (storageKey) {
|
12729 | field = (0, _objectSpread2["default"])({}, field, {
|
12730 | storageKey: storageKey
|
12731 | });
|
12732 | }
|
12733 |
|
12734 | return field;
|
12735 | }
|
12736 |
|
12737 | function generateArgument(node) {
|
12738 | var value = node.value;
|
12739 |
|
12740 | switch (value.kind) {
|
12741 | case 'Variable':
|
12742 | return {
|
12743 | kind: 'Variable',
|
12744 | name: node.name,
|
12745 | variableName: value.variableName
|
12746 | };
|
12747 |
|
12748 | case 'Literal':
|
12749 | return value.value === null ? null : {
|
12750 | kind: 'Literal',
|
12751 | name: node.name,
|
12752 | value: stableCopy(value.value)
|
12753 | };
|
12754 |
|
12755 | default:
|
12756 | throw createUserError('ReaderCodeGenerator: Complex argument values (Lists or ' + 'InputObjects with nested variables) are not supported.', [node.value.loc]);
|
12757 | }
|
12758 | }
|
12759 |
|
12760 | function generateArgs(args) {
|
12761 | var concreteArguments = [];
|
12762 | args.forEach(function (arg) {
|
12763 | var concreteArgument = generateArgument(arg);
|
12764 |
|
12765 | if (concreteArgument !== null) {
|
12766 | concreteArguments.push(concreteArgument);
|
12767 | }
|
12768 | });
|
12769 | return concreteArguments.length === 0 ? null : concreteArguments.sort(nameComparator);
|
12770 | }
|
12771 |
|
12772 | function nameComparator(a, b) {
|
12773 | return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
12774 | }
|
12775 | /**
|
12776 | * Pre-computes storage key if possible and advantageous. Storage keys are
|
12777 | * generated for fields with supplied arguments that are all statically known
|
12778 | * (ie. literals, no variables) at build time.
|
12779 | */
|
12780 |
|
12781 |
|
12782 | function getStaticStorageKey(field, metadata) {
|
12783 | var metadataStorageKey = metadata === null || metadata === void 0 ? void 0 : metadata.storageKey;
|
12784 |
|
12785 | if (typeof metadataStorageKey === 'string') {
|
12786 | return metadataStorageKey;
|
12787 | }
|
12788 |
|
12789 | if (!field.args || field.args.length === 0 || field.args.some(function (arg) {
|
12790 | return arg.kind !== 'Literal';
|
12791 | })) {
|
12792 | return null;
|
12793 | }
|
12794 |
|
12795 | return getStorageKey(field, {});
|
12796 | }
|
12797 |
|
12798 | function isPlural(schema, type) {
|
12799 | return schema.isList(schema.getNullableType(type));
|
12800 | }
|
12801 |
|
12802 | module.exports = {
|
12803 | generate: generate
|
12804 | };
|
12805 |
|
12806 | /***/ }),
|
12807 | /* 67 */
|
12808 | /***/ (function(module, exports, __webpack_require__) {
|
12809 |
|
12810 | "use strict";
|
12811 | /**
|
12812 | * Copyright (c) Facebook, Inc. and its affiliates.
|
12813 | *
|
12814 | * This source code is licensed under the MIT license found in the
|
12815 | * LICENSE file in the root directory of this source tree.
|
12816 | *
|
12817 | *
|
12818 | * @format
|
12819 | */
|
12820 |
|
12821 |
|
12822 | var GraphQLCompilerContext = __webpack_require__(19);
|
12823 |
|
12824 | var _require = __webpack_require__(15),
|
12825 | visit = _require.visit;
|
12826 |
|
12827 | /**
|
12828 | * Returns a GraphQLCompilerContext containing only the documents referenced
|
12829 | * by and including the provided node.
|
12830 | */
|
12831 | function filterContextForNode(node, context) {
|
12832 | var queue = [node];
|
12833 | var filteredContext = new GraphQLCompilerContext(context.getSchema()).add(node);
|
12834 |
|
12835 | var visitFragmentSpread = function visitFragmentSpread(fragmentSpread) {
|
12836 | var name = fragmentSpread.name;
|
12837 |
|
12838 | if (!filteredContext.get(name)) {
|
12839 | var fragment = context.getFragment(name);
|
12840 | filteredContext = filteredContext.add(fragment);
|
12841 | queue.push(fragment);
|
12842 | }
|
12843 | };
|
12844 |
|
12845 | var visitorConfig = {
|
12846 | FragmentSpread: function FragmentSpread(fragmentSpread) {
|
12847 | visitFragmentSpread(fragmentSpread);
|
12848 | }
|
12849 | };
|
12850 |
|
12851 | while (queue.length) {
|
12852 | visit(queue.pop(), visitorConfig);
|
12853 | }
|
12854 |
|
12855 | return filteredContext;
|
12856 | }
|
12857 |
|
12858 | module.exports = filterContextForNode;
|
12859 |
|
12860 | /***/ }),
|
12861 | /* 68 */
|
12862 | /***/ (function(module, exports, __webpack_require__) {
|
12863 |
|
12864 | "use strict";
|
12865 | /**
|
12866 | * Copyright (c) Facebook, Inc. and its affiliates.
|
12867 | *
|
12868 | * This source code is licensed under the MIT license found in the
|
12869 | * LICENSE file in the root directory of this source tree.
|
12870 | *
|
12871 | *
|
12872 | * @format
|
12873 | */
|
12874 |
|
12875 |
|
12876 | var _interopRequireDefault = __webpack_require__(0);
|
12877 |
|
12878 | var _asyncToGenerator = __webpack_require__(10);
|
12879 |
|
12880 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
12881 |
|
12882 | var CodeMarker = __webpack_require__(32);
|
12883 |
|
12884 | var Profiler = __webpack_require__(6);
|
12885 |
|
12886 | var createPrintRequireModuleDependency = __webpack_require__(69);
|
12887 |
|
12888 | var crypto = __webpack_require__(12);
|
12889 |
|
12890 | var dedupeJSONStringify = __webpack_require__(70);
|
12891 |
|
12892 | var invariant = __webpack_require__(4);
|
12893 |
|
12894 | var _require = __webpack_require__(9),
|
12895 | RelayConcreteNode = _require.RelayConcreteNode;
|
12896 |
|
12897 | function getConcreteType(node) {
|
12898 | switch (node.kind) {
|
12899 | case RelayConcreteNode.FRAGMENT:
|
12900 | return 'ReaderFragment';
|
12901 |
|
12902 | case RelayConcreteNode.REQUEST:
|
12903 | return 'ConcreteRequest';
|
12904 |
|
12905 | case RelayConcreteNode.SPLIT_OPERATION:
|
12906 | return 'NormalizationSplitOperation';
|
12907 |
|
12908 | case RelayConcreteNode.INLINE_DATA_FRAGMENT:
|
12909 | return 'ReaderInlineDataFragment';
|
12910 |
|
12911 | default:
|
12912 | node;
|
12913 | true ? true ? invariant(false, 'Unexpected GeneratedNode kind: `%s`.', node.kind) : undefined : undefined;
|
12914 | }
|
12915 | }
|
12916 |
|
12917 | function writeRelayGeneratedFile(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8, _x9, _x10) {
|
12918 | return _writeRelayGeneratedFile.apply(this, arguments);
|
12919 | }
|
12920 |
|
12921 | function _writeRelayGeneratedFile() {
|
12922 | _writeRelayGeneratedFile = _asyncToGenerator(function* (schema, codegenDir, definition, _generatedNode, formatModule, typeText, _persistQuery, platform, sourceHash, extension) {
|
12923 | var printModuleDependency = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : createPrintRequireModuleDependency(extension);
|
12924 | var shouldRepersist = arguments.length > 11 ? arguments[11] : undefined;
|
12925 | var generatedNode = _generatedNode; // Copy to const so Flow can refine.
|
12926 |
|
12927 | var persistQuery = _persistQuery;
|
12928 | var moduleName = (generatedNode.kind === 'Request' ? generatedNode.params.name : generatedNode.name) + '.graphql';
|
12929 | var platformName = platform != null && platform.length > 0 ? moduleName + '.' + platform : moduleName;
|
12930 | var filename = platformName + '.' + extension;
|
12931 | var typeName = getConcreteType(generatedNode);
|
12932 | var docText;
|
12933 |
|
12934 | if (generatedNode.kind === RelayConcreteNode.REQUEST) {
|
12935 | docText = generatedNode.params.text;
|
12936 | }
|
12937 |
|
12938 | var hash = null;
|
12939 |
|
12940 | if (generatedNode.kind === RelayConcreteNode.REQUEST) {
|
12941 | var oldContent;
|
12942 | var oldHash = Profiler.run('RelayFileWriter:compareHash', function () {
|
12943 | oldContent = codegenDir.read(filename); // Hash the concrete node including the query text.
|
12944 |
|
12945 | var hasher = crypto.createHash('md5');
|
12946 | hasher.update('cache-breaker-9');
|
12947 | hasher.update(JSON.stringify(generatedNode));
|
12948 | hasher.update(sourceHash);
|
12949 |
|
12950 | if (typeText) {
|
12951 | hasher.update(typeText);
|
12952 | }
|
12953 |
|
12954 | if (persistQuery) {
|
12955 | hasher.update('persisted');
|
12956 | }
|
12957 |
|
12958 | hash = hasher.digest('hex');
|
12959 | return extractHash(oldContent);
|
12960 | });
|
12961 | var oldRequestParameters = extractRelayRequestParams(oldContent);
|
12962 |
|
12963 | if (!shouldRepersist && hash === oldHash) {
|
12964 | codegenDir.markUnchanged(filename);
|
12965 | return oldRequestParameters ? (0, _objectSpread2["default"])({}, generatedNode, {
|
12966 | params: oldRequestParameters
|
12967 | }) : null;
|
12968 | }
|
12969 |
|
12970 | if (codegenDir.onlyValidate) {
|
12971 | codegenDir.markUpdated(filename);
|
12972 | return null;
|
12973 | }
|
12974 |
|
12975 | if (persistQuery) {
|
12976 | switch (generatedNode.kind) {
|
12977 | case RelayConcreteNode.REQUEST:
|
12978 | var _text = generatedNode.params.text;
|
12979 | !(_text != null) ? true ? invariant(false, 'writeRelayGeneratedFile: Expected `text` in order to persist query') : undefined : void 0;
|
12980 | generatedNode = (0, _objectSpread2["default"])({}, generatedNode, {
|
12981 | params: {
|
12982 | operationKind: generatedNode.params.operationKind,
|
12983 | name: generatedNode.params.name,
|
12984 | id: yield persistQuery(_text),
|
12985 | text: null,
|
12986 | metadata: generatedNode.params.metadata
|
12987 | }
|
12988 | });
|
12989 | break;
|
12990 |
|
12991 | case RelayConcreteNode.FRAGMENT:
|
12992 | // Do not persist fragments.
|
12993 | break;
|
12994 |
|
12995 | default:
|
12996 | generatedNode.kind;
|
12997 | }
|
12998 | }
|
12999 | }
|
13000 |
|
13001 | var moduleText = formatModule({
|
13002 | moduleName: moduleName,
|
13003 | documentType: typeName,
|
13004 | definition: definition,
|
13005 | kind: generatedNode.kind,
|
13006 | docText: docText,
|
13007 | typeText: typeText,
|
13008 | hash: hash ? "@relayHash ".concat(hash) : null,
|
13009 | concreteText: CodeMarker.postProcess(dedupeJSONStringify(generatedNode), printModuleDependency),
|
13010 | sourceHash: sourceHash,
|
13011 | node: generatedNode,
|
13012 | schema: schema
|
13013 | });
|
13014 | codegenDir.writeFile(filename, moduleText, shouldRepersist);
|
13015 | return generatedNode;
|
13016 | });
|
13017 | return _writeRelayGeneratedFile.apply(this, arguments);
|
13018 | }
|
13019 |
|
13020 | function extractHash(text) {
|
13021 | if (text == null || text.length === 0) {
|
13022 | return null;
|
13023 | }
|
13024 |
|
13025 | if (/<<<<<|>>>>>/.test(text)) {
|
13026 | // looks like a merge conflict
|
13027 | return null;
|
13028 | }
|
13029 |
|
13030 | var match = text.match(/@relayHash (\w{32})\b/m);
|
13031 | return match && match[1];
|
13032 | }
|
13033 |
|
13034 | function extractRelayRequestParams(text) {
|
13035 | if (text == null || text.length === 0) {
|
13036 | return null;
|
13037 | }
|
13038 |
|
13039 | if (/<<<<<|>>>>>/.test(text)) {
|
13040 | // looks like a merge conflict
|
13041 | return null;
|
13042 | }
|
13043 |
|
13044 | var match = text.match(/@relayRequestParams (.+)/);
|
13045 | var requestParams;
|
13046 |
|
13047 | try {
|
13048 | var _ref;
|
13049 |
|
13050 | requestParams = JSON.parse((_ref = match === null || match === void 0 ? void 0 : match[1]) !== null && _ref !== void 0 ? _ref : '');
|
13051 | } catch (_unused) {}
|
13052 |
|
13053 | return requestParams;
|
13054 | }
|
13055 |
|
13056 | module.exports = writeRelayGeneratedFile;
|
13057 |
|
13058 | /***/ }),
|
13059 | /* 69 */
|
13060 | /***/ (function(module, exports, __webpack_require__) {
|
13061 |
|
13062 | "use strict";
|
13063 | /**
|
13064 | * Copyright (c) Facebook, Inc. and its affiliates.
|
13065 | *
|
13066 | * This source code is licensed under the MIT license found in the
|
13067 | * LICENSE file in the root directory of this source tree.
|
13068 | *
|
13069 | *
|
13070 | * @format
|
13071 | */
|
13072 |
|
13073 |
|
13074 | function createPrintRequireModuleDependency(extension) {
|
13075 | return function (moduleName) {
|
13076 | return "require('./".concat(moduleName, ".").concat(extension, "')");
|
13077 | };
|
13078 | }
|
13079 |
|
13080 | module.exports = createPrintRequireModuleDependency;
|
13081 |
|
13082 | /***/ }),
|
13083 | /* 70 */
|
13084 | /***/ (function(module, exports, __webpack_require__) {
|
13085 |
|
13086 | "use strict";
|
13087 | /**
|
13088 | * Copyright (c) Facebook, Inc. and its affiliates.
|
13089 | *
|
13090 | * This source code is licensed under the MIT license found in the
|
13091 | * LICENSE file in the root directory of this source tree.
|
13092 | *
|
13093 | *
|
13094 | * @format
|
13095 | */
|
13096 |
|
13097 | /**
|
13098 | * This function works similar to JSON.stringify except that for the case there
|
13099 | * are multiple common subtrees, it generates a string for a IIFE that re-uses
|
13100 | * the same objects for the duplicate subtrees.
|
13101 | */
|
13102 |
|
13103 | function dedupeJSONStringify(jsonValue) {
|
13104 | // Clone the object to convert references to the same object instance into
|
13105 | // copies. This is needed for the WeakMap/Map to recognize them as duplicates.
|
13106 | // $FlowFixMe(>=0.95.0) JSON.stringify can return undefined
|
13107 | jsonValue = JSON.parse(JSON.stringify(jsonValue));
|
13108 | var metadataForHash = new Map();
|
13109 | var metadataForVal = new WeakMap();
|
13110 | var varDefs = [];
|
13111 | collectMetadata(jsonValue);
|
13112 | collectDuplicates(jsonValue);
|
13113 | var code = printJSCode(false, '', jsonValue);
|
13114 | return varDefs.length === 0 ? code : "(function(){\nvar ".concat(varDefs.join(',\n'), ";\nreturn ").concat(code, ";\n})()"); // Collect common metadata for each object in the value tree, ensuring that
|
13115 | // equivalent values have the *same reference* to the same metadata. Note that
|
13116 | // the hashes generated are not exactly JSON, but still identify equivalent
|
13117 | // values. Runs in linear time due to hashing in a bottom-up recursion.
|
13118 |
|
13119 | function collectMetadata(value) {
|
13120 | if (value == null || typeof value !== 'object') {
|
13121 | return JSON.stringify(value);
|
13122 | }
|
13123 |
|
13124 | var hash;
|
13125 |
|
13126 | if (Array.isArray(value)) {
|
13127 | hash = '[';
|
13128 |
|
13129 | for (var i = 0; i < value.length; i++) {
|
13130 | hash += collectMetadata(value[i]) + ',';
|
13131 | }
|
13132 | } else {
|
13133 | hash = '{';
|
13134 |
|
13135 | for (var k in value) {
|
13136 | if (value.hasOwnProperty(k) && value[k] !== undefined) {
|
13137 | hash += k + ':' + collectMetadata(value[k]) + ',';
|
13138 | }
|
13139 | }
|
13140 | }
|
13141 |
|
13142 | var metadata = metadataForHash.get(hash);
|
13143 |
|
13144 | if (!metadata) {
|
13145 | metadata = {
|
13146 | value: value,
|
13147 | hash: hash,
|
13148 | isDuplicate: false
|
13149 | };
|
13150 | metadataForHash.set(hash, metadata);
|
13151 | }
|
13152 |
|
13153 | metadataForVal.set(value, metadata);
|
13154 | return hash;
|
13155 | } // Using top-down recursion, linearly scan the JSON tree to determine which
|
13156 | // values should be deduplicated.
|
13157 |
|
13158 |
|
13159 | function collectDuplicates(value) {
|
13160 | if (value == null || typeof value !== 'object') {
|
13161 | return;
|
13162 | }
|
13163 |
|
13164 | var metadata = metadataForVal.get(value); // Only consider duplicates with hashes longer than 2 (excludes [] and {}).
|
13165 |
|
13166 | if (metadata && metadata.value !== value && metadata.hash.length > 2) {
|
13167 | metadata.isDuplicate = true;
|
13168 | return;
|
13169 | }
|
13170 |
|
13171 | if (Array.isArray(value)) {
|
13172 | for (var i = 0; i < value.length; i++) {
|
13173 | collectDuplicates(value[i]);
|
13174 | }
|
13175 | } else {
|
13176 | for (var k in value) {
|
13177 | if (value.hasOwnProperty(k) && value[k] !== undefined) {
|
13178 | collectDuplicates(value[k]);
|
13179 | }
|
13180 | }
|
13181 | }
|
13182 | } // Stringify JS, replacing duplicates with variable references.
|
13183 |
|
13184 |
|
13185 | function printJSCode(isDupedVar, depth, value) {
|
13186 | if (value == null || typeof value !== 'object') {
|
13187 | return JSON.stringify(value);
|
13188 | } // Only use variable references at depth beyond the top level.
|
13189 |
|
13190 |
|
13191 | if (depth !== '') {
|
13192 | var metadata = metadataForVal.get(value);
|
13193 |
|
13194 | if (metadata && metadata.isDuplicate) {
|
13195 | if (!metadata.varName) {
|
13196 | var refCode = printJSCode(true, '', value);
|
13197 | metadata.varName = 'v' + varDefs.length;
|
13198 | varDefs.push(metadata.varName + ' = ' + refCode);
|
13199 | }
|
13200 |
|
13201 | return '(' + metadata.varName + '/*: any*/)';
|
13202 | }
|
13203 | }
|
13204 |
|
13205 | var str;
|
13206 | var isEmpty = true;
|
13207 | var depth2 = depth + ' ';
|
13208 |
|
13209 | if (Array.isArray(value)) {
|
13210 | // Empty arrays can only have one inferred flow type and then conflict if
|
13211 | // used in different places, this is unsound if we would write to them but
|
13212 | // this whole module is based on the idea of a read only JSON tree.
|
13213 | if (isDupedVar && value.length === 0) {
|
13214 | return '([]/*: any*/)';
|
13215 | }
|
13216 |
|
13217 | str = '[';
|
13218 |
|
13219 | for (var i = 0; i < value.length; i++) {
|
13220 | str += (isEmpty ? '\n' : ',\n') + depth2 + printJSCode(isDupedVar, depth2, value[i]);
|
13221 | isEmpty = false;
|
13222 | }
|
13223 |
|
13224 | str += isEmpty ? ']' : "\n".concat(depth, "]");
|
13225 | } else {
|
13226 | str = '{';
|
13227 |
|
13228 | for (var k in value) {
|
13229 | if (value.hasOwnProperty(k) && value[k] !== undefined) {
|
13230 | str += (isEmpty ? '\n' : ',\n') + depth2 + JSON.stringify(k) + ': ' + printJSCode(isDupedVar, depth2, value[k]);
|
13231 | isEmpty = false;
|
13232 | }
|
13233 | }
|
13234 |
|
13235 | str += isEmpty ? '}' : "\n".concat(depth, "}");
|
13236 | }
|
13237 |
|
13238 | return str;
|
13239 | }
|
13240 | }
|
13241 |
|
13242 | module.exports = dedupeJSONStringify;
|
13243 |
|
13244 | /***/ }),
|
13245 | /* 71 */
|
13246 | /***/ (function(module, exports, __webpack_require__) {
|
13247 |
|
13248 | "use strict";
|
13249 | /**
|
13250 | * Copyright (c) Facebook, Inc. and its affiliates.
|
13251 | *
|
13252 | * This source code is licensed under the MIT license found in the
|
13253 | * LICENSE file in the root directory of this source tree.
|
13254 | *
|
13255 | *
|
13256 | * @format
|
13257 | */
|
13258 |
|
13259 |
|
13260 | /**
|
13261 | * Helpers to retieve the name of the document from which the input derives:
|
13262 | * this is either the name of the input itself (if it is not a derived node)
|
13263 | * or the metadata.derivedFrom property for derived nodes.
|
13264 | */
|
13265 | // Version for generated nodes
|
13266 | function getReaderSourceDefinitionName(node) {
|
13267 | var _node$params$metadata, _node$metadata;
|
13268 |
|
13269 | var _ref = node.kind === 'Request' ? [node.params.name, (_node$params$metadata = node.params.metadata) === null || _node$params$metadata === void 0 ? void 0 : _node$params$metadata.derivedFrom] : node.kind === 'SplitOperation' ? [node.name, (_node$metadata = node.metadata) === null || _node$metadata === void 0 ? void 0 : _node$metadata.derivedFrom] : [node.name, null],
|
13270 | name = _ref[0],
|
13271 | derivedFrom = _ref[1];
|
13272 |
|
13273 | return typeof derivedFrom === 'string' ? derivedFrom : name;
|
13274 | } // Version for IR
|
13275 |
|
13276 |
|
13277 | function getSourceDefinitionName(node) {
|
13278 | var _node$metadata2;
|
13279 |
|
13280 | var derivedFrom = node.kind === 'Request' || node.kind === 'Root' || node.kind === 'SplitOperation' ? (_node$metadata2 = node.metadata) === null || _node$metadata2 === void 0 ? void 0 : _node$metadata2.derivedFrom : null;
|
13281 | return typeof derivedFrom === 'string' ? derivedFrom : node.name;
|
13282 | }
|
13283 |
|
13284 | module.exports = {
|
13285 | getReaderSourceDefinitionName: getReaderSourceDefinitionName,
|
13286 | getSourceDefinitionName: getSourceDefinitionName
|
13287 | };
|
13288 |
|
13289 | /***/ }),
|
13290 | /* 72 */
|
13291 | /***/ (function(module, exports, __webpack_require__) {
|
13292 |
|
13293 | "use strict";
|
13294 | /**
|
13295 | * Copyright (c) Facebook, Inc. and its affiliates.
|
13296 | *
|
13297 | * This source code is licensed under the MIT license found in the
|
13298 | * LICENSE file in the root directory of this source tree.
|
13299 | *
|
13300 | *
|
13301 | * @format
|
13302 | */
|
13303 |
|
13304 |
|
13305 | var ApplyFragmentArgumentTransform = __webpack_require__(73);
|
13306 |
|
13307 | var ClientExtensionsTransform = __webpack_require__(76);
|
13308 |
|
13309 | var ConnectionFieldTransform = __webpack_require__(34);
|
13310 |
|
13311 | var ConnectionTransform = __webpack_require__(35);
|
13312 |
|
13313 | var DeferStreamTransform = __webpack_require__(77);
|
13314 |
|
13315 | var DisallowIdAsAlias = __webpack_require__(78);
|
13316 |
|
13317 | var FieldHandleTransform = __webpack_require__(79);
|
13318 |
|
13319 | var FilterDirectivesTransform = __webpack_require__(80);
|
13320 |
|
13321 | var FlattenTransform = __webpack_require__(36);
|
13322 |
|
13323 | var GenerateIDFieldTransform = __webpack_require__(82);
|
13324 |
|
13325 | var GenerateTypeNameTransform = __webpack_require__(83);
|
13326 |
|
13327 | var InlineDataFragmentTransform = __webpack_require__(84);
|
13328 |
|
13329 | var InlineFragmentsTransform = __webpack_require__(85);
|
13330 |
|
13331 | var MaskTransform = __webpack_require__(39);
|
13332 |
|
13333 | var MatchTransform = __webpack_require__(40);
|
13334 |
|
13335 | var RefetchableFragmentTransform = __webpack_require__(42);
|
13336 |
|
13337 | var RelayDirectiveTransform = __webpack_require__(43);
|
13338 |
|
13339 | var RelayFlowGenerator = __webpack_require__(44);
|
13340 |
|
13341 | var SkipClientExtensionsTransform = __webpack_require__(93);
|
13342 |
|
13343 | var SkipHandleFieldTransform = __webpack_require__(94);
|
13344 |
|
13345 | var SkipRedundantNodesTransform = __webpack_require__(95);
|
13346 |
|
13347 | var SkipUnreachableNodeTransform = __webpack_require__(96);
|
13348 |
|
13349 | var SkipUnusedVariablesTransform = __webpack_require__(97);
|
13350 |
|
13351 | var SplitModuleImportTransform = __webpack_require__(98);
|
13352 |
|
13353 | var TestOperationTransform = __webpack_require__(99);
|
13354 |
|
13355 | var ValidateGlobalVariablesTransform = __webpack_require__(100);
|
13356 |
|
13357 | var ValidateRequiredArgumentsTransform = __webpack_require__(101);
|
13358 |
|
13359 | var ValidateServerOnlyDirectivesTransform = __webpack_require__(102);
|
13360 |
|
13361 | var ValidateUnusedVariablesTransform = __webpack_require__(103);
|
13362 |
|
13363 | // Transforms applied to the code used to process a query response.
|
13364 | var relaySchemaExtensions = [ConnectionTransform.SCHEMA_EXTENSION, MatchTransform.SCHEMA_EXTENSION, ConnectionFieldTransform.SCHEMA_EXTENSION, RelayDirectiveTransform.SCHEMA_EXTENSION, RefetchableFragmentTransform.SCHEMA_EXTENSION, TestOperationTransform.SCHEMA_EXTENSION, InlineDataFragmentTransform.SCHEMA_EXTENSION, RelayFlowGenerator.SCHEMA_EXTENSION, ValidateUnusedVariablesTransform.SCHEMA_EXTENSION]; // Transforms applied to both operations and fragments for both reading and
|
13365 | // writing from the store.
|
13366 |
|
13367 | var relayCommonTransforms = [DisallowIdAsAlias.transform, ConnectionTransform.transform, RelayDirectiveTransform.transform, MaskTransform.transform, MatchTransform.transform, ConnectionFieldTransform.transform, RefetchableFragmentTransform.transform, DeferStreamTransform.transform]; // Transforms applied to fragments used for reading data from a store
|
13368 |
|
13369 | var relayFragmentTransforms = [ClientExtensionsTransform.transform, FieldHandleTransform.transform, InlineDataFragmentTransform.transform, FlattenTransform.transformWithOptions({
|
13370 | flattenAbstractTypes: true
|
13371 | }), SkipRedundantNodesTransform.transform]; // Transforms applied to queries/mutations/subscriptions that are used for
|
13372 | // fetching data from the server and parsing those responses.
|
13373 |
|
13374 | var relayQueryTransforms = [ValidateUnusedVariablesTransform.transform, ApplyFragmentArgumentTransform.transform, ValidateGlobalVariablesTransform.transform, GenerateIDFieldTransform.transform, TestOperationTransform.transform]; // Transforms applied to the code used to process a query response.
|
13375 |
|
13376 | var relayCodegenTransforms = [SkipUnreachableNodeTransform.transform, SplitModuleImportTransform.transform, InlineFragmentsTransform.transform, // NOTE: For the codegen context, we make sure to run ClientExtensions
|
13377 | // transform after we've inlined fragment spreads (i.e. InlineFragmentsTransform)
|
13378 | // This will ensure that we don't generate nested ClientExtension nodes
|
13379 | ClientExtensionsTransform.transform, FlattenTransform.transformWithOptions({
|
13380 | flattenAbstractTypes: true
|
13381 | }), SkipRedundantNodesTransform.transform, GenerateTypeNameTransform.transform, ValidateServerOnlyDirectivesTransform.transform]; // Transforms applied before printing the query sent to the server.
|
13382 |
|
13383 | var relayPrintTransforms = [// NOTE: Skipping client extensions might leave empty selections, which we
|
13384 | // skip by running SkipUnreachableNodeTransform immediately after.
|
13385 | ClientExtensionsTransform.transform, SkipClientExtensionsTransform.transform, SkipUnreachableNodeTransform.transform, FlattenTransform.transformWithOptions({}), GenerateTypeNameTransform.transform, SkipHandleFieldTransform.transform, FilterDirectivesTransform.transform, SkipUnusedVariablesTransform.transform, ValidateRequiredArgumentsTransform.transform];
|
13386 | module.exports = {
|
13387 | commonTransforms: relayCommonTransforms,
|
13388 | codegenTransforms: relayCodegenTransforms,
|
13389 | fragmentTransforms: relayFragmentTransforms,
|
13390 | printTransforms: relayPrintTransforms,
|
13391 | queryTransforms: relayQueryTransforms,
|
13392 | schemaExtensions: relaySchemaExtensions
|
13393 | };
|
13394 |
|
13395 | /***/ }),
|
13396 | /* 73 */
|
13397 | /***/ (function(module, exports, __webpack_require__) {
|
13398 |
|
13399 | "use strict";
|
13400 | /**
|
13401 | * Copyright (c) Facebook, Inc. and its affiliates.
|
13402 | *
|
13403 | * This source code is licensed under the MIT license found in the
|
13404 | * LICENSE file in the root directory of this source tree.
|
13405 | *
|
13406 | *
|
13407 | * @format
|
13408 | */
|
13409 |
|
13410 |
|
13411 | var _interopRequireDefault = __webpack_require__(0);
|
13412 |
|
13413 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
13414 |
|
13415 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
13416 |
|
13417 | var IRTransformer = __webpack_require__(3);
|
13418 |
|
13419 | var RelayCompilerScope = __webpack_require__(74);
|
13420 |
|
13421 | var getIdentifierForArgumentValue = __webpack_require__(75);
|
13422 |
|
13423 | var murmurHash = __webpack_require__(33);
|
13424 |
|
13425 | var _require = __webpack_require__(1),
|
13426 | createCompilerError = _require.createCompilerError,
|
13427 | createNonRecoverableUserError = _require.createNonRecoverableUserError;
|
13428 |
|
13429 | var getFragmentScope = RelayCompilerScope.getFragmentScope,
|
13430 | getRootScope = RelayCompilerScope.getRootScope;
|
13431 |
|
13432 | /**
|
13433 | * A transform that converts a set of documents containing fragments/fragment
|
13434 | * spreads *with* arguments to one where all arguments have been inlined. This
|
13435 | * is effectively static currying of functions. Nodes are changed as follows:
|
13436 | * - Fragment spreads with arguments are replaced with references to an inlined
|
13437 | * version of the referenced fragment.
|
13438 | * - Fragments with argument definitions are cloned once per unique set of
|
13439 | * arguments, with the name changed to original name + hash and all nested
|
13440 | * variable references changed to the value of that variable given its
|
13441 | * arguments.
|
13442 | * - Field & directive argument variables are replaced with the value of those
|
13443 | * variables in context.
|
13444 | * - All nodes are cloned with updated children.
|
13445 | *
|
13446 | * The transform also handles statically passing/failing Condition nodes:
|
13447 | * - Literal Conditions with a passing value are elided and their selections
|
13448 | * inlined in their parent.
|
13449 | * - Literal Conditions with a failing value are removed.
|
13450 | * - Nodes that would become empty as a result of the above are removed.
|
13451 | *
|
13452 | * Note that unreferenced fragments are not added to the output.
|
13453 | */
|
13454 | function applyFragmentArgumentTransform(context) {
|
13455 | var fragments = new Map();
|
13456 | var nextContext = IRTransformer.transform(context, {
|
13457 | Root: function Root(node) {
|
13458 | var scope = getRootScope(node.argumentDefinitions);
|
13459 | return transformNode(context, fragments, scope, node, [node]);
|
13460 | },
|
13461 | // Fragments are included below where referenced.
|
13462 | // Unreferenced fragments are not included.
|
13463 | Fragment: function Fragment() {
|
13464 | return null;
|
13465 | }
|
13466 | });
|
13467 | var _iteratorNormalCompletion = true;
|
13468 | var _didIteratorError = false;
|
13469 | var _iteratorError = undefined;
|
13470 |
|
13471 | try {
|
13472 | for (var _iterator = fragments.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
13473 | var pendingFragment = _step.value;
|
13474 |
|
13475 | if (pendingFragment.kind === 'resolved' && pendingFragment.value) {
|
13476 | nextContext = nextContext.add(pendingFragment.value);
|
13477 | }
|
13478 | }
|
13479 | } catch (err) {
|
13480 | _didIteratorError = true;
|
13481 | _iteratorError = err;
|
13482 | } finally {
|
13483 | try {
|
13484 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
13485 | _iterator["return"]();
|
13486 | }
|
13487 | } finally {
|
13488 | if (_didIteratorError) {
|
13489 | throw _iteratorError;
|
13490 | }
|
13491 | }
|
13492 | }
|
13493 |
|
13494 | return nextContext;
|
13495 | }
|
13496 |
|
13497 | function transformNode(context, fragments, scope, node, errorContext) {
|
13498 | var selections = transformSelections(context, fragments, scope, node.selections, errorContext);
|
13499 |
|
13500 | if (!selections) {
|
13501 | return null;
|
13502 | }
|
13503 |
|
13504 | if (node.hasOwnProperty('directives')) {
|
13505 | var directives = transformDirectives(scope, node.directives, errorContext); // $FlowIssue: this is a valid `Node`:
|
13506 |
|
13507 | return (0, _objectSpread2["default"])({}, node, {
|
13508 | directives: directives,
|
13509 | selections: selections
|
13510 | });
|
13511 | }
|
13512 |
|
13513 | return (0, _objectSpread2["default"])({}, node, {
|
13514 | selections: selections
|
13515 | });
|
13516 | }
|
13517 |
|
13518 | function transformFragmentSpread(context, fragments, scope, spread, errorContext) {
|
13519 | var directives = transformDirectives(scope, spread.directives, errorContext);
|
13520 | var appliedFragment = transformFragment(context, fragments, scope, spread, spread.args, [].concat((0, _toConsumableArray2["default"])(errorContext), [spread]));
|
13521 |
|
13522 | if (!appliedFragment) {
|
13523 | return null;
|
13524 | }
|
13525 |
|
13526 | var transformed = (0, _objectSpread2["default"])({}, spread, {
|
13527 | kind: 'FragmentSpread',
|
13528 | args: [],
|
13529 | directives: directives,
|
13530 | name: appliedFragment.name
|
13531 | });
|
13532 | return transformed;
|
13533 | }
|
13534 |
|
13535 | function transformField(context, fragments, scope, field, errorContext) {
|
13536 | var args = transformArguments(scope, field.args, errorContext);
|
13537 | var directives = transformDirectives(scope, field.directives, errorContext);
|
13538 |
|
13539 | if (field.kind === 'LinkedField' || field.kind === 'ConnectionField') {
|
13540 | var selections = transformSelections(context, fragments, scope, field.selections, errorContext);
|
13541 |
|
13542 | if (!selections) {
|
13543 | return null;
|
13544 | }
|
13545 |
|
13546 | return (0, _objectSpread2["default"])({}, field, {
|
13547 | args: args,
|
13548 | directives: directives,
|
13549 | selections: selections
|
13550 | });
|
13551 | } else {
|
13552 | return (0, _objectSpread2["default"])({}, field, {
|
13553 | args: args,
|
13554 | directives: directives
|
13555 | });
|
13556 | }
|
13557 | }
|
13558 |
|
13559 | function transformConnection(context, fragments, scope, connection, errorContext) {
|
13560 | var args = transformArguments(scope, connection.args, errorContext);
|
13561 | var stream = connection.stream;
|
13562 |
|
13563 | if (stream != null) {
|
13564 | stream = (0, _objectSpread2["default"])({}, stream, {
|
13565 | "if": stream["if"] != null ? transformValue(scope, stream["if"], errorContext) : null,
|
13566 | initialCount: transformValue(scope, stream.initialCount, errorContext)
|
13567 | });
|
13568 | }
|
13569 |
|
13570 | var selections = transformSelections(context, fragments, scope, connection.selections, errorContext);
|
13571 |
|
13572 | if (!selections) {
|
13573 | return null;
|
13574 | }
|
13575 |
|
13576 | return (0, _objectSpread2["default"])({}, connection, {
|
13577 | args: args,
|
13578 | selections: selections,
|
13579 | stream: stream
|
13580 | });
|
13581 | }
|
13582 |
|
13583 | function transformCondition(context, fragments, scope, node, errorContext) {
|
13584 | var condition = transformValue(scope, node.condition, errorContext);
|
13585 |
|
13586 | if (!(condition.kind === 'Literal' || condition.kind === 'Variable')) {
|
13587 | // This transform does whole-program optimization, errors in
|
13588 | // a single document could break invariants and/or cause
|
13589 | // additional spurious errors.
|
13590 | throw createNonRecoverableUserError('A non-scalar value was applied to an @include or @skip directive, ' + 'the `if` argument value must be a ' + 'variable or a literal Boolean.', [condition.loc]);
|
13591 | }
|
13592 |
|
13593 | if (condition.kind === 'Literal' && condition.value !== node.passingValue) {
|
13594 | // Dead code, no need to traverse further.
|
13595 | return null;
|
13596 | }
|
13597 |
|
13598 | var selections = transformSelections(context, fragments, scope, node.selections, errorContext);
|
13599 |
|
13600 | if (!selections) {
|
13601 | return null;
|
13602 | }
|
13603 |
|
13604 | if (condition.kind === 'Literal' && condition.value === node.passingValue) {
|
13605 | // Always passes, return inlined selections
|
13606 | return selections;
|
13607 | }
|
13608 |
|
13609 | return [(0, _objectSpread2["default"])({}, node, {
|
13610 | condition: condition,
|
13611 | selections: selections
|
13612 | })];
|
13613 | }
|
13614 |
|
13615 | function transformSelections(context, fragments, scope, selections, errorContext) {
|
13616 | var nextSelections = null;
|
13617 | selections.forEach(function (selection) {
|
13618 | var nextSelection;
|
13619 |
|
13620 | if (selection.kind === 'ClientExtension' || selection.kind === 'InlineDataFragmentSpread' || selection.kind === 'InlineFragment' || selection.kind === 'ModuleImport' || selection.kind === 'Defer' || selection.kind === 'Stream') {
|
13621 | nextSelection = transformNode(context, fragments, scope, selection, errorContext);
|
13622 | } else if (selection.kind === 'FragmentSpread') {
|
13623 | nextSelection = transformFragmentSpread(context, fragments, scope, selection, errorContext);
|
13624 | } else if (selection.kind === 'Condition') {
|
13625 | var conditionSelections = transformCondition(context, fragments, scope, selection, errorContext);
|
13626 |
|
13627 | if (conditionSelections) {
|
13628 | var _nextSelections;
|
13629 |
|
13630 | nextSelections = nextSelections || [];
|
13631 |
|
13632 | (_nextSelections = nextSelections).push.apply(_nextSelections, (0, _toConsumableArray2["default"])(conditionSelections));
|
13633 | }
|
13634 | } else if (selection.kind === 'Connection') {
|
13635 | nextSelection = transformConnection(context, fragments, scope, selection, errorContext);
|
13636 | } else if (selection.kind === 'LinkedField' || selection.kind === 'ScalarField' || selection.kind === 'ConnectionField') {
|
13637 | nextSelection = transformField(context, fragments, scope, selection, errorContext);
|
13638 | } else {
|
13639 | selection;
|
13640 | throw createCompilerError("ApplyFragmentArgumentTransform: Unsupported kind '".concat(selection.kind, "'."), [selection.loc]);
|
13641 | }
|
13642 |
|
13643 | if (nextSelection) {
|
13644 | nextSelections = nextSelections || [];
|
13645 | nextSelections.push(nextSelection);
|
13646 | }
|
13647 | });
|
13648 | return nextSelections;
|
13649 | }
|
13650 |
|
13651 | function transformDirectives(scope, directives, errorContext) {
|
13652 | return directives.map(function (directive) {
|
13653 | var args = transformArguments(scope, directive.args, errorContext);
|
13654 | return (0, _objectSpread2["default"])({}, directive, {
|
13655 | args: args
|
13656 | });
|
13657 | });
|
13658 | }
|
13659 |
|
13660 | function transformArguments(scope, args, errorContext) {
|
13661 | return args.map(function (arg) {
|
13662 | var value = transformValue(scope, arg.value, errorContext);
|
13663 | return value === arg.value ? arg : (0, _objectSpread2["default"])({}, arg, {
|
13664 | value: value
|
13665 | });
|
13666 | });
|
13667 | }
|
13668 |
|
13669 | function transformValue(scope, value, errorContext) {
|
13670 | if (value.kind === 'Variable') {
|
13671 | var scopeValue = scope[value.variableName];
|
13672 |
|
13673 | if (scopeValue == null) {
|
13674 | var _errorContext$;
|
13675 |
|
13676 | // This transform does whole-program optimization, errors in
|
13677 | // a single document could break invariants and/or cause
|
13678 | // additional spurious errors.
|
13679 | throw createNonRecoverableUserError("Variable '$".concat(value.variableName, "' is not in scope."), [(_errorContext$ = errorContext[0]) === null || _errorContext$ === void 0 ? void 0 : _errorContext$.loc, value.loc].filter(Boolean));
|
13680 | }
|
13681 |
|
13682 | return scopeValue;
|
13683 | }
|
13684 |
|
13685 | return value;
|
13686 | }
|
13687 | /**
|
13688 | * Apply arguments to a fragment, creating a new fragment (with the given name)
|
13689 | * with all values recursively applied.
|
13690 | */
|
13691 |
|
13692 |
|
13693 | function transformFragment(context, fragments, parentScope, spread, args, errorContext) {
|
13694 | var schema = context.getSchema();
|
13695 | var fragment = context.getFragment(spread.name, spread.loc);
|
13696 | var argumentsHash = hashArguments(args, parentScope, errorContext);
|
13697 | var fragmentName = argumentsHash ? "".concat(fragment.name, "_").concat(argumentsHash) : fragment.name;
|
13698 | var appliedFragment = fragments.get(fragmentName);
|
13699 |
|
13700 | if (appliedFragment) {
|
13701 | if (appliedFragment.kind === 'resolved') {
|
13702 | return appliedFragment.value;
|
13703 | } else {
|
13704 | // This transform does whole-program optimization, errors in
|
13705 | // a single document could break invariants and/or cause
|
13706 | // additional spurious errors.
|
13707 | throw createNonRecoverableUserError("Found a circular reference from fragment '".concat(fragment.name, "'."), errorContext.map(function (node) {
|
13708 | return node.loc;
|
13709 | }));
|
13710 | }
|
13711 | }
|
13712 |
|
13713 | var fragmentScope = getFragmentScope(schema, fragment.argumentDefinitions, args, parentScope, spread); // record that this fragment is pending to detect circular references
|
13714 |
|
13715 | fragments.set(fragmentName, {
|
13716 | kind: 'pending'
|
13717 | });
|
13718 | var transformedFragment = null;
|
13719 | var selections = transformSelections(context, fragments, fragmentScope, fragment.selections, errorContext);
|
13720 |
|
13721 | if (selections) {
|
13722 | transformedFragment = (0, _objectSpread2["default"])({}, fragment, {
|
13723 | selections: selections,
|
13724 | name: fragmentName,
|
13725 | argumentDefinitions: []
|
13726 | });
|
13727 | }
|
13728 |
|
13729 | fragments.set(fragmentName, {
|
13730 | kind: 'resolved',
|
13731 | value: transformedFragment
|
13732 | });
|
13733 | return transformedFragment;
|
13734 | }
|
13735 |
|
13736 | function hashArguments(args, scope, errorContext) {
|
13737 | if (!args.length) {
|
13738 | return null;
|
13739 | }
|
13740 |
|
13741 | var sortedArgs = (0, _toConsumableArray2["default"])(args).sort(function (a, b) {
|
13742 | return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
13743 | });
|
13744 | var printedArgs = JSON.stringify(sortedArgs.map(function (arg) {
|
13745 | var value;
|
13746 |
|
13747 | if (arg.value.kind === 'Variable') {
|
13748 | value = scope[arg.value.variableName];
|
13749 |
|
13750 | if (value == null) {
|
13751 | var _errorContext$2;
|
13752 |
|
13753 | // This transform does whole-program optimization, errors in
|
13754 | // a single document could break invariants and/or cause
|
13755 | // additional spurious errors.
|
13756 | throw createNonRecoverableUserError("Variable '$".concat(arg.value.variableName, "' is not in scope."), [(_errorContext$2 = errorContext[0]) === null || _errorContext$2 === void 0 ? void 0 : _errorContext$2.loc, arg.value.loc].filter(Boolean));
|
13757 | }
|
13758 | } else {
|
13759 | value = arg.value;
|
13760 | }
|
13761 |
|
13762 | return {
|
13763 | name: arg.name,
|
13764 | value: getIdentifierForArgumentValue(value)
|
13765 | };
|
13766 | }));
|
13767 | return murmurHash(printedArgs);
|
13768 | }
|
13769 |
|
13770 | module.exports = {
|
13771 | transform: applyFragmentArgumentTransform
|
13772 | };
|
13773 |
|
13774 | /***/ }),
|
13775 | /* 74 */
|
13776 | /***/ (function(module, exports, __webpack_require__) {
|
13777 |
|
13778 | "use strict";
|
13779 | /**
|
13780 | * Copyright (c) Facebook, Inc. and its affiliates.
|
13781 | *
|
13782 | * This source code is licensed under the MIT license found in the
|
13783 | * LICENSE file in the root directory of this source tree.
|
13784 | *
|
13785 | *
|
13786 | * @format
|
13787 | */
|
13788 |
|
13789 |
|
13790 | var _require = __webpack_require__(1),
|
13791 | createUserError = _require.createUserError,
|
13792 | eachWithCombinedError = _require.eachWithCombinedError;
|
13793 |
|
13794 | /**
|
13795 | * Creates a scope for a `Root`, with each argument mapped to a variable of the
|
13796 | * same name. Example:
|
13797 | *
|
13798 | * Query:
|
13799 | * query Foo($id: ID, $size: Int = 42) { ... }
|
13800 | *
|
13801 | * Scope:
|
13802 | * {
|
13803 | * id: $id,
|
13804 | * size: $size,
|
13805 | * }
|
13806 | *
|
13807 | * Note that even though a default value is defined for $size, the scope must
|
13808 | * assume that this could be overridden at runtime. The value cannot be decided
|
13809 | * statically and therefore is set to a variable.
|
13810 | */
|
13811 | function getRootScope(definitions) {
|
13812 | var scope = {};
|
13813 | definitions.forEach(function (definition) {
|
13814 | scope[definition.name] = {
|
13815 | kind: 'Variable',
|
13816 | loc: definition.loc,
|
13817 | variableName: definition.name,
|
13818 | type: definition.type
|
13819 | };
|
13820 | });
|
13821 | return scope;
|
13822 | }
|
13823 | /**
|
13824 | * Creates a scope for a `Fragment` by translating fragment spread arguments in
|
13825 | * the context of a parent scope into a new scope and validating them against
|
13826 | * the argument definitions.
|
13827 | *
|
13828 | *
|
13829 | * Parent Scope:
|
13830 | * {
|
13831 | * active: $parentActive
|
13832 | * }
|
13833 | *
|
13834 | * Fragment Spread:
|
13835 | * ...Bar(size: 42, enabled: $active)
|
13836 | *
|
13837 | * Fragment:
|
13838 | * fragment Bar on Foo @argumentDefinitions(
|
13839 | * id: {type: "ID"}
|
13840 | * size: {type: "Int"}
|
13841 | * enabled: {type: "Boolean}
|
13842 | * scale: {type: "Int", imports: "pixelRatio"}
|
13843 | * )
|
13844 | *
|
13845 | * Scope:
|
13846 | * {
|
13847 | * // No argument is provided for $id, it gets the default value which in this
|
13848 | * // case is `null`:
|
13849 | * id: null,
|
13850 | *
|
13851 | * // The parent passes 42 as a literal value for $size:
|
13852 | * size: 42,
|
13853 | *
|
13854 | * // The parent passes a variable as the value of $enabled. This variable is
|
13855 | * // resolved in the parent scope to the value $parentActive, which becomes
|
13856 | * // the value of $enabled:
|
13857 | * $enabled: $parentActive,
|
13858 | *
|
13859 | * // $scale imports pixelRatio from the root scope. Since any argument in a
|
13860 | * // root scope maps to a variable of the same name, that means the value of
|
13861 | * // pixelRatio in the root is $pixelRatio:
|
13862 | * $scale: $pixelRatio,
|
13863 | * }
|
13864 | */
|
13865 |
|
13866 |
|
13867 | function getFragmentScope(schema, definitions, args, parentScope, spread) {
|
13868 | var argMap = new Map();
|
13869 | args.forEach(function (arg) {
|
13870 | if (arg.value.kind === 'Literal') {
|
13871 | argMap.set(arg.name, arg.value);
|
13872 | } else if (arg.value.kind === 'Variable') {
|
13873 | argMap.set(arg.name, parentScope[arg.value.variableName]);
|
13874 | }
|
13875 | });
|
13876 | var fragmentScope = {};
|
13877 | eachWithCombinedError(definitions, function (definition) {
|
13878 | if (definition.kind === 'RootArgumentDefinition') {
|
13879 | if (argMap.has(definition.name)) {
|
13880 | var _ref;
|
13881 |
|
13882 | var argNode = args.find(function (a) {
|
13883 | return a.name === definition.name;
|
13884 | });
|
13885 | throw createUserError("Unexpected argument '".concat(definition.name, "' supplied to fragment '").concat(spread.name, "'. @arguments may only be provided for variables defined in the fragment's @argumentDefinitions."), [(_ref = argNode === null || argNode === void 0 ? void 0 : argNode.loc) !== null && _ref !== void 0 ? _ref : spread.loc]);
|
13886 | }
|
13887 |
|
13888 | fragmentScope[definition.name] = {
|
13889 | kind: 'Variable',
|
13890 | loc: definition.loc,
|
13891 | variableName: definition.name,
|
13892 | type: definition.type
|
13893 | };
|
13894 | } else {
|
13895 | var arg = argMap.get(definition.name);
|
13896 |
|
13897 | if (arg == null || arg.kind === 'Literal' && arg.value == null) {
|
13898 | // No variable or literal null was passed, fall back to default
|
13899 | // value.
|
13900 | if (definition.defaultValue == null && schema.isNonNull(definition.type)) {
|
13901 | var _ref2;
|
13902 |
|
13903 | var _argNode = args.find(function (a) {
|
13904 | return a.name === definition.name;
|
13905 | });
|
13906 |
|
13907 | throw createUserError("No value found for required argument '".concat(definition.name, ": ").concat(schema.getTypeString(definition.type), "' on fragment '").concat(spread.name, "'."), [(_ref2 = _argNode === null || _argNode === void 0 ? void 0 : _argNode.loc) !== null && _ref2 !== void 0 ? _ref2 : spread.loc]);
|
13908 | }
|
13909 |
|
13910 | fragmentScope[definition.name] = {
|
13911 | kind: 'Literal',
|
13912 | value: definition.defaultValue
|
13913 | };
|
13914 | } else {
|
13915 | // Variable or non-null literal.
|
13916 | fragmentScope[definition.name] = arg;
|
13917 | }
|
13918 | }
|
13919 | });
|
13920 | return fragmentScope;
|
13921 | }
|
13922 |
|
13923 | module.exports = {
|
13924 | getFragmentScope: getFragmentScope,
|
13925 | getRootScope: getRootScope
|
13926 | };
|
13927 |
|
13928 | /***/ }),
|
13929 | /* 75 */
|
13930 | /***/ (function(module, exports, __webpack_require__) {
|
13931 |
|
13932 | "use strict";
|
13933 | /**
|
13934 | * Copyright (c) Facebook, Inc. and its affiliates.
|
13935 | *
|
13936 | * This source code is licensed under the MIT license found in the
|
13937 | * LICENSE file in the root directory of this source tree.
|
13938 | *
|
13939 | *
|
13940 | * @format
|
13941 | */
|
13942 |
|
13943 |
|
13944 | var invariant = __webpack_require__(4);
|
13945 |
|
13946 | /**
|
13947 | * Generates an identifier for an argument value. The identifier is based on the
|
13948 | * structure/order of items and keys in the value.
|
13949 | */
|
13950 | function getIdentifierForArgumentValue(value) {
|
13951 | switch (value.kind) {
|
13952 | case 'Variable':
|
13953 | return {
|
13954 | variable: value.variableName
|
13955 | };
|
13956 |
|
13957 | case 'Literal':
|
13958 | return {
|
13959 | value: value.value
|
13960 | };
|
13961 |
|
13962 | default:
|
13963 | true ? true ? invariant(false, 'getIdentifierForArgumentValue(): Unsupported AST kind `%s`.', value.kind) : undefined : undefined;
|
13964 | }
|
13965 | }
|
13966 |
|
13967 | module.exports = getIdentifierForArgumentValue;
|
13968 |
|
13969 | /***/ }),
|
13970 | /* 76 */
|
13971 | /***/ (function(module, exports, __webpack_require__) {
|
13972 |
|
13973 | "use strict";
|
13974 | /**
|
13975 | * Copyright (c) Facebook, Inc. and its affiliates.
|
13976 | *
|
13977 | * This source code is licensed under the MIT license found in the
|
13978 | * LICENSE file in the root directory of this source tree.
|
13979 | *
|
13980 | *
|
13981 | * @format
|
13982 | */
|
13983 |
|
13984 |
|
13985 | var _interopRequireDefault = __webpack_require__(0);
|
13986 |
|
13987 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
13988 |
|
13989 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
13990 |
|
13991 | var GraphQLIRTransformer = __webpack_require__(3);
|
13992 |
|
13993 | var _require = __webpack_require__(1),
|
13994 | createCompilerError = _require.createCompilerError,
|
13995 | createUserError = _require.createUserError;
|
13996 |
|
13997 | var cachesByNode = new Map();
|
13998 |
|
13999 | function clientExtensionTransform(context) {
|
14000 | cachesByNode = new Map();
|
14001 | return GraphQLIRTransformer.transform(context, {
|
14002 | Fragment: traverseDefinition,
|
14003 | Root: traverseDefinition,
|
14004 | SplitOperation: traverseDefinition
|
14005 | });
|
14006 | }
|
14007 |
|
14008 | function traverseDefinition(node) {
|
14009 | var compilerContext = this.getContext();
|
14010 | var schema = compilerContext.getSchema();
|
14011 | var rootType;
|
14012 |
|
14013 | switch (node.kind) {
|
14014 | case 'Root':
|
14015 | switch (node.operation) {
|
14016 | case 'query':
|
14017 | rootType = schema.getQueryType();
|
14018 | break;
|
14019 |
|
14020 | case 'mutation':
|
14021 | rootType = schema.getMutationType();
|
14022 | break;
|
14023 |
|
14024 | case 'subscription':
|
14025 | rootType = schema.getSubscriptionType();
|
14026 | break;
|
14027 |
|
14028 | default:
|
14029 | node.operation;
|
14030 | }
|
14031 |
|
14032 | break;
|
14033 |
|
14034 | case 'SplitOperation':
|
14035 | if (!schema.isServerType(node.type)) {
|
14036 | throw createUserError('ClientExtensionTransform: SplitOperation (@module) can be created ' + 'only for fragments that defined on a server type', [node.loc]);
|
14037 | }
|
14038 |
|
14039 | rootType = node.type;
|
14040 | break;
|
14041 |
|
14042 | case 'Fragment':
|
14043 | rootType = node.type;
|
14044 | break;
|
14045 |
|
14046 | default:
|
14047 | node;
|
14048 | }
|
14049 |
|
14050 | if (rootType == null) {
|
14051 | throw createUserError("ClientExtensionTransform: Expected the type of `".concat(node.name, "` to have been defined in the schema. Make sure both server and ") + 'client schema are up to date.', [node.loc]);
|
14052 | }
|
14053 |
|
14054 | return traverseSelections(node, compilerContext, rootType);
|
14055 | }
|
14056 |
|
14057 | function traverseSelections(node, compilerContext, parentType) {
|
14058 | var nodeCache = cachesByNode.get(node);
|
14059 |
|
14060 | if (nodeCache == null) {
|
14061 | nodeCache = new Map();
|
14062 | cachesByNode.set(node, nodeCache);
|
14063 | }
|
14064 |
|
14065 | var result = nodeCache.get(parentType);
|
14066 |
|
14067 | if (result != null) {
|
14068 | // $FlowFixMe - TODO: type IRTransformer to allow changing result type
|
14069 | return result;
|
14070 | }
|
14071 |
|
14072 | var schema = compilerContext.getSchema();
|
14073 | var clientSelections = [];
|
14074 | var serverSelections = cowMap(node.selections, function (selection) {
|
14075 | switch (selection.kind) {
|
14076 | case 'ClientExtension':
|
14077 | throw createCompilerError('Unexpected ClientExtension node before ClientExtensionTransform', [selection.loc]);
|
14078 |
|
14079 | case 'Condition':
|
14080 | case 'Connection':
|
14081 | case 'Defer':
|
14082 | case 'InlineDataFragmentSpread':
|
14083 | case 'ModuleImport':
|
14084 | case 'Stream':
|
14085 | return traverseSelections(selection, compilerContext, parentType);
|
14086 |
|
14087 | case 'ScalarField':
|
14088 | if (schema.isClientDefinedField(schema.assertCompositeType(schema.getRawType(parentType)), selection)) {
|
14089 | clientSelections.push(selection);
|
14090 | return null;
|
14091 | } else {
|
14092 | return selection;
|
14093 | }
|
14094 |
|
14095 | case 'ConnectionField':
|
14096 | case 'LinkedField':
|
14097 | {
|
14098 | if (schema.isClientDefinedField(schema.assertCompositeType(schema.getRawType(parentType)), selection)) {
|
14099 | clientSelections.push(selection);
|
14100 | return null;
|
14101 | }
|
14102 |
|
14103 | return traverseSelections(selection, compilerContext, selection.type);
|
14104 | }
|
14105 |
|
14106 | case 'InlineFragment':
|
14107 | {
|
14108 | var isClientType = !schema.isServerType(selection.typeCondition);
|
14109 |
|
14110 | if (isClientType) {
|
14111 | clientSelections.push(selection);
|
14112 | return null;
|
14113 | }
|
14114 |
|
14115 | return traverseSelections(selection, compilerContext, selection.typeCondition);
|
14116 | }
|
14117 |
|
14118 | case 'FragmentSpread':
|
14119 | {
|
14120 | var fragment = compilerContext.getFragment(selection.name, selection.loc);
|
14121 |
|
14122 | var _isClientType = !schema.isServerType(fragment.type);
|
14123 |
|
14124 | if (_isClientType) {
|
14125 | clientSelections.push(selection);
|
14126 | return null;
|
14127 | }
|
14128 |
|
14129 | return selection;
|
14130 | }
|
14131 |
|
14132 | default:
|
14133 | selection;
|
14134 | throw createCompilerError("ClientExtensionTransform: Unexpected selection of kind `".concat(selection.kind, "`."), [selection.loc]);
|
14135 | }
|
14136 | });
|
14137 |
|
14138 | if (clientSelections.length === 0) {
|
14139 | if (serverSelections === node.selections) {
|
14140 | result = node;
|
14141 | } else {
|
14142 | result = (0, _objectSpread2["default"])({}, node, {
|
14143 | selections: serverSelections
|
14144 | });
|
14145 | }
|
14146 | } else {
|
14147 | result = (0, _objectSpread2["default"])({}, node, {
|
14148 | selections: [].concat((0, _toConsumableArray2["default"])(serverSelections), [// Group client fields under a single ClientExtension node
|
14149 | {
|
14150 | kind: 'ClientExtension',
|
14151 | loc: node.loc,
|
14152 | metadata: null,
|
14153 | selections: clientSelections
|
14154 | }])
|
14155 | });
|
14156 | }
|
14157 |
|
14158 | nodeCache.set(parentType, result); // $FlowFixMe - TODO: type IRTransformer to allow changing result type
|
14159 |
|
14160 | return result;
|
14161 | }
|
14162 | /**
|
14163 | * Maps an array with copy-on-write semantics.
|
14164 | * `null` return values from the map function are removals.
|
14165 | */
|
14166 |
|
14167 |
|
14168 | function cowMap(selections, f) {
|
14169 | for (var i = 0; i < selections.length; i++) {
|
14170 | var prevSelection = selections[i];
|
14171 | var nextSelection = f(prevSelection);
|
14172 |
|
14173 | if (prevSelection !== nextSelection) {
|
14174 | var result = selections.slice(0, i);
|
14175 |
|
14176 | if (nextSelection != null) {
|
14177 | result.push(nextSelection);
|
14178 | }
|
14179 |
|
14180 | for (var j = i + 1; j < selections.length; j++) {
|
14181 | var innerNextSelection = f(selections[j]);
|
14182 |
|
14183 | if (innerNextSelection != null) {
|
14184 | result.push(innerNextSelection);
|
14185 | }
|
14186 | }
|
14187 |
|
14188 | return result;
|
14189 | }
|
14190 | } // nothing changed, return original
|
14191 |
|
14192 |
|
14193 | return selections;
|
14194 | }
|
14195 |
|
14196 | module.exports = {
|
14197 | transform: clientExtensionTransform
|
14198 | };
|
14199 |
|
14200 | /***/ }),
|
14201 | /* 77 */
|
14202 | /***/ (function(module, exports, __webpack_require__) {
|
14203 |
|
14204 | "use strict";
|
14205 | /**
|
14206 | * Copyright (c) Facebook, Inc. and its affiliates.
|
14207 | *
|
14208 | * This source code is licensed under the MIT license found in the
|
14209 | * LICENSE file in the root directory of this source tree.
|
14210 | *
|
14211 | *
|
14212 | * @format
|
14213 | */
|
14214 |
|
14215 |
|
14216 | var _interopRequireDefault = __webpack_require__(0);
|
14217 |
|
14218 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
14219 |
|
14220 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
14221 |
|
14222 | var IRTransformer = __webpack_require__(3);
|
14223 |
|
14224 | var murmurHash = __webpack_require__(33);
|
14225 |
|
14226 | var _require = __webpack_require__(1),
|
14227 | createUserError = _require.createUserError;
|
14228 |
|
14229 | var _require2 = __webpack_require__(9),
|
14230 | ConnectionInterface = _require2.ConnectionInterface;
|
14231 |
|
14232 | /**
|
14233 | * This transform finds usages of @defer and @stream, validates them, and
|
14234 | * converts the using node to specialized IR nodes (Defer/Stream).
|
14235 | */
|
14236 | function deferStreamTransform(context) {
|
14237 | return IRTransformer.transform(context, {
|
14238 | Connection: visitConnection,
|
14239 | // TODO: type IRTransformer to allow changing result type
|
14240 | FragmentSpread: visitFragmentSpread,
|
14241 | // TODO: type IRTransformer to allow changing result type
|
14242 | InlineFragment: visitInlineFragment,
|
14243 | // TODO: type IRTransformer to allow changing result type
|
14244 | LinkedField: visitLinkedField,
|
14245 | ScalarField: visitScalarField
|
14246 | }, function (sourceNode) {
|
14247 | var labels = new Map();
|
14248 | return {
|
14249 | documentName: sourceNode.name,
|
14250 | recordLabel: function recordLabel(label, directive) {
|
14251 | var prevDirective = labels.get(label);
|
14252 |
|
14253 | if (prevDirective) {
|
14254 | var _ref;
|
14255 |
|
14256 | var labelArg = directive.args.find(function (_ref4) {
|
14257 | var name = _ref4.name;
|
14258 | return name === 'label';
|
14259 | });
|
14260 | var prevLabelArg = prevDirective.args.find(function (_ref5) {
|
14261 | var name = _ref5.name;
|
14262 | return name === 'label';
|
14263 | });
|
14264 | var previousLocation = (_ref = prevLabelArg === null || prevLabelArg === void 0 ? void 0 : prevLabelArg.loc) !== null && _ref !== void 0 ? _ref : prevDirective.loc;
|
14265 |
|
14266 | if (labelArg) {
|
14267 | throw createUserError("Invalid use of @".concat(directive.name, ", the provided label is ") + "not unique. Specify a unique 'label' as a literal string.", [labelArg === null || labelArg === void 0 ? void 0 : labelArg.loc, previousLocation]);
|
14268 | } else {
|
14269 | throw createUserError("Invalid use of @".concat(directive.name, ", could not generate a ") + "default label that is unique. Specify a unique 'label' " + 'as a literal string.', [directive.loc, previousLocation]);
|
14270 | }
|
14271 | }
|
14272 |
|
14273 | labels.set(label, directive);
|
14274 | }
|
14275 | };
|
14276 | });
|
14277 | }
|
14278 |
|
14279 | function visitConnection(connection, state) {
|
14280 | var transformed = this.traverse(connection, state);
|
14281 | var stream = transformed.stream;
|
14282 |
|
14283 | if (stream == null) {
|
14284 | return transformed;
|
14285 | }
|
14286 |
|
14287 | var _ConnectionInterface$ = ConnectionInterface.get(),
|
14288 | EDGES = _ConnectionInterface$.EDGES,
|
14289 | PAGE_INFO = _ConnectionInterface$.PAGE_INFO;
|
14290 |
|
14291 | var edges = transformed.selections.find(function (selection) {
|
14292 | return selection.kind === 'LinkedField' && selection.name === EDGES;
|
14293 | });
|
14294 | var pageInfo = transformed.selections.find(function (selection) {
|
14295 | return selection.kind === 'LinkedField' && selection.name === PAGE_INFO;
|
14296 | });
|
14297 |
|
14298 | if (edges == null || pageInfo == null) {
|
14299 | throw createUserError("Invalid connection, expected the '".concat(EDGES, "' and '").concat(PAGE_INFO, "' fields ") + 'to exist.', [transformed.loc]);
|
14300 | }
|
14301 |
|
14302 | var derivedLocation = {
|
14303 | kind: 'Derived',
|
14304 | source: transformed.loc
|
14305 | };
|
14306 | var streamLabel = transformLabel(state.documentName, 'stream', transformed.label);
|
14307 | var deferLabel = transformLabel(state.documentName, 'defer', transformed.label);
|
14308 | return (0, _objectSpread2["default"])({}, connection, {
|
14309 | selections: [{
|
14310 | kind: 'Stream',
|
14311 | loc: derivedLocation,
|
14312 | metadata: null,
|
14313 | selections: [edges],
|
14314 | label: streamLabel,
|
14315 | "if": stream["if"],
|
14316 | initialCount: stream.initialCount
|
14317 | }, {
|
14318 | kind: 'Defer',
|
14319 | loc: derivedLocation,
|
14320 | metadata: null,
|
14321 | selections: [pageInfo],
|
14322 | label: deferLabel,
|
14323 | "if": stream["if"]
|
14324 | }],
|
14325 | stream: (0, _objectSpread2["default"])({}, stream, {
|
14326 | streamLabel: streamLabel,
|
14327 | deferLabel: deferLabel
|
14328 | })
|
14329 | });
|
14330 | }
|
14331 |
|
14332 | function visitLinkedField(field, state) {
|
14333 | var _getLiteralStringArgu, _ref2;
|
14334 |
|
14335 | var context = this.getContext();
|
14336 | var schema = context.getSchema();
|
14337 | var transformedField = this.traverse(field, state);
|
14338 | var streamDirective = transformedField.directives.find(function (directive) {
|
14339 | return directive.name === 'stream';
|
14340 | });
|
14341 |
|
14342 | if (streamDirective == null) {
|
14343 | return transformedField;
|
14344 | }
|
14345 |
|
14346 | var type = schema.getNullableType(field.type);
|
14347 |
|
14348 | if (!schema.isList(type)) {
|
14349 | throw createUserError("Invalid use of @stream on non-plural field '".concat(field.name, "'"), [streamDirective.loc]);
|
14350 | }
|
14351 |
|
14352 | transformedField = (0, _objectSpread2["default"])({}, transformedField, {
|
14353 | directives: transformedField.directives.filter(function (directive) {
|
14354 | return directive.name !== 'stream';
|
14355 | })
|
14356 | });
|
14357 | var ifArg = streamDirective.args.find(function (arg) {
|
14358 | return arg.name === 'if';
|
14359 | });
|
14360 |
|
14361 | if (isLiteralFalse(ifArg)) {
|
14362 | return transformedField;
|
14363 | }
|
14364 |
|
14365 | var initialCount = streamDirective.args.find(function (arg) {
|
14366 | return arg.name === 'initial_count';
|
14367 | });
|
14368 |
|
14369 | if (initialCount == null) {
|
14370 | throw createUserError("Invalid use of @stream, the 'initial_count' argument is required.", [streamDirective.loc]);
|
14371 | }
|
14372 |
|
14373 | var label = (_getLiteralStringArgu = getLiteralStringArgument(streamDirective, 'label')) !== null && _getLiteralStringArgu !== void 0 ? _getLiteralStringArgu : field.alias;
|
14374 | var transformedLabel = transformLabel(state.documentName, 'stream', label);
|
14375 | state.recordLabel(transformedLabel, streamDirective);
|
14376 | return {
|
14377 | "if": (_ref2 = ifArg === null || ifArg === void 0 ? void 0 : ifArg.value) !== null && _ref2 !== void 0 ? _ref2 : null,
|
14378 | initialCount: initialCount.value,
|
14379 | kind: 'Stream',
|
14380 | label: transformedLabel,
|
14381 | loc: {
|
14382 | kind: 'Derived',
|
14383 | source: streamDirective.loc
|
14384 | },
|
14385 | metadata: null,
|
14386 | selections: [transformedField]
|
14387 | };
|
14388 | }
|
14389 |
|
14390 | function visitScalarField(field, state) {
|
14391 | var streamDirective = field.directives.find(function (directive) {
|
14392 | return directive.name === 'stream';
|
14393 | });
|
14394 |
|
14395 | if (streamDirective != null) {
|
14396 | throw createUserError("Invalid use of @stream on scalar field '".concat(field.name, "'"), [streamDirective.loc]);
|
14397 | }
|
14398 |
|
14399 | return this.traverse(field, state);
|
14400 | }
|
14401 |
|
14402 | function visitInlineFragment(fragment, state) {
|
14403 | var deferDirective = fragment.directives.find(function (directive) {
|
14404 | return directive.name === 'defer';
|
14405 | });
|
14406 |
|
14407 | if (deferDirective != null) {
|
14408 | throw createUserError('Invalid use of @defer on an inline fragment, @defer is only supported on fragment spreads.', [fragment.loc]);
|
14409 | }
|
14410 |
|
14411 | return this.traverse(fragment, state);
|
14412 | }
|
14413 |
|
14414 | function visitFragmentSpread(spread, state) {
|
14415 | var _getLiteralStringArgu2, _ref3;
|
14416 |
|
14417 | var transformedSpread = this.traverse(spread, state);
|
14418 | var deferDirective = transformedSpread.directives.find(function (directive) {
|
14419 | return directive.name === 'defer';
|
14420 | });
|
14421 |
|
14422 | if (deferDirective == null) {
|
14423 | return transformedSpread;
|
14424 | }
|
14425 |
|
14426 | transformedSpread = (0, _objectSpread2["default"])({}, transformedSpread, {
|
14427 | directives: transformedSpread.directives.filter(function (directive) {
|
14428 | return directive.name !== 'defer';
|
14429 | })
|
14430 | });
|
14431 | var ifArg = deferDirective.args.find(function (arg) {
|
14432 | return arg.name === 'if';
|
14433 | });
|
14434 |
|
14435 | if (isLiteralFalse(ifArg)) {
|
14436 | return transformedSpread;
|
14437 | }
|
14438 |
|
14439 | var label = (_getLiteralStringArgu2 = getLiteralStringArgument(deferDirective, 'label')) !== null && _getLiteralStringArgu2 !== void 0 ? _getLiteralStringArgu2 : getFragmentSpreadName(spread);
|
14440 | var transformedLabel = transformLabel(state.documentName, 'defer', label);
|
14441 | state.recordLabel(transformedLabel, deferDirective);
|
14442 | return {
|
14443 | "if": (_ref3 = ifArg === null || ifArg === void 0 ? void 0 : ifArg.value) !== null && _ref3 !== void 0 ? _ref3 : null,
|
14444 | kind: 'Defer',
|
14445 | label: transformedLabel,
|
14446 | loc: {
|
14447 | kind: 'Derived',
|
14448 | source: deferDirective.loc
|
14449 | },
|
14450 | metadata: null,
|
14451 | selections: [transformedSpread]
|
14452 | };
|
14453 | }
|
14454 |
|
14455 | function getLiteralStringArgument(directive, argName) {
|
14456 | var arg = directive.args.find(function (_ref6) {
|
14457 | var name = _ref6.name;
|
14458 | return name === argName;
|
14459 | });
|
14460 |
|
14461 | if (arg == null) {
|
14462 | return null;
|
14463 | }
|
14464 |
|
14465 | var value = arg.value.kind === 'Literal' ? arg.value.value : null;
|
14466 |
|
14467 | if (value == null || typeof value !== 'string') {
|
14468 | throw createUserError("Expected the '".concat(argName, "' value to @").concat(directive.name, " to be a string literal if provided."), [arg.value.loc]);
|
14469 | }
|
14470 |
|
14471 | return value;
|
14472 | }
|
14473 |
|
14474 | function transformLabel(parentName, directive, label) {
|
14475 | return "".concat(parentName, "$").concat(directive, "$").concat(label);
|
14476 | }
|
14477 |
|
14478 | function isLiteralFalse(arg) {
|
14479 | return arg != null && arg.value.kind === 'Literal' && arg.value.value === false;
|
14480 | }
|
14481 |
|
14482 | function getFragmentSpreadName(fragmentSpread) {
|
14483 | if (fragmentSpread.args.length === 0) {
|
14484 | return fragmentSpread.name;
|
14485 | }
|
14486 |
|
14487 | var sortedArgs = (0, _toConsumableArray2["default"])(fragmentSpread.args).sort(function (a, b) {
|
14488 | return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
14489 | });
|
14490 | var hash = murmurHash(JSON.stringify(sortedArgs));
|
14491 | return "".concat(fragmentSpread.name, "_").concat(hash);
|
14492 | }
|
14493 |
|
14494 | module.exports = {
|
14495 | transform: deferStreamTransform
|
14496 | };
|
14497 |
|
14498 | /***/ }),
|
14499 | /* 78 */
|
14500 | /***/ (function(module, exports, __webpack_require__) {
|
14501 |
|
14502 | "use strict";
|
14503 | /**
|
14504 | * Copyright (c) Facebook, Inc. and its affiliates.
|
14505 | *
|
14506 | * This source code is licensed under the MIT license found in the
|
14507 | * LICENSE file in the root directory of this source tree.
|
14508 | *
|
14509 | *
|
14510 | * @format
|
14511 | */
|
14512 |
|
14513 |
|
14514 | var GraphQLIRTransformer = __webpack_require__(3);
|
14515 |
|
14516 | var _require = __webpack_require__(1),
|
14517 | createUserError = _require.createUserError;
|
14518 |
|
14519 | function visitField(field) {
|
14520 | if (field.alias === 'id' && field.name !== 'id') {
|
14521 | throw createUserError('Relay does not allow aliasing fields to `id`. ' + 'This name is reserved for the globally unique `id` field on ' + '`Node`.', [field.loc]);
|
14522 | }
|
14523 |
|
14524 | return field;
|
14525 | }
|
14526 | /**
|
14527 | * This is not an actual transform (but more a validation)
|
14528 | * Relay does not allow aliasing fields to `id`.
|
14529 | */
|
14530 |
|
14531 |
|
14532 | function disallowIdAsAlias(context) {
|
14533 | return GraphQLIRTransformer.transform(context, {
|
14534 | ScalarField: visitField,
|
14535 | LinkedField: visitField
|
14536 | });
|
14537 | }
|
14538 |
|
14539 | module.exports = {
|
14540 | transform: disallowIdAsAlias
|
14541 | };
|
14542 |
|
14543 | /***/ }),
|
14544 | /* 79 */
|
14545 | /***/ (function(module, exports, __webpack_require__) {
|
14546 |
|
14547 | "use strict";
|
14548 | /**
|
14549 | * Copyright (c) Facebook, Inc. and its affiliates.
|
14550 | *
|
14551 | * This source code is licensed under the MIT license found in the
|
14552 | * LICENSE file in the root directory of this source tree.
|
14553 | *
|
14554 | *
|
14555 | * @format
|
14556 | */
|
14557 |
|
14558 |
|
14559 | var _interopRequireDefault = __webpack_require__(0);
|
14560 |
|
14561 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
14562 |
|
14563 | var IRTransformer = __webpack_require__(3);
|
14564 |
|
14565 | var SchemaUtils = __webpack_require__(11);
|
14566 |
|
14567 | var invariant = __webpack_require__(4);
|
14568 |
|
14569 | var nullthrows = __webpack_require__(20);
|
14570 |
|
14571 | var _require = __webpack_require__(9),
|
14572 | getRelayHandleKey = _require.getRelayHandleKey;
|
14573 |
|
14574 | function fieldHandleTransform(context) {
|
14575 | return IRTransformer.transform(context, {
|
14576 | LinkedField: visitField,
|
14577 | ScalarField: visitField
|
14578 | });
|
14579 | }
|
14580 | /**
|
14581 | * @internal
|
14582 | */
|
14583 |
|
14584 |
|
14585 | function visitField(field) {
|
14586 | var nextField = field.kind === 'LinkedField' ? this.traverse(field) : field;
|
14587 | var handles = nextField.handles;
|
14588 |
|
14589 | if (!handles || !handles.length) {
|
14590 | return nextField;
|
14591 | } // ensure exactly one handle
|
14592 |
|
14593 |
|
14594 | !(handles.length === 1) ? true ? invariant(false, 'FieldHandleTransform: Expected fields to have at most one ' + '"handle" property, got `%s`.', handles.join(', ')) : undefined : void 0;
|
14595 | var context = this.getContext();
|
14596 | var schema = context.getSchema();
|
14597 | var alias = nextField.alias;
|
14598 | var handle = handles[0];
|
14599 | var name = getRelayHandleKey(handle.name, handle.key, nextField.name);
|
14600 | var filters = handle.filters;
|
14601 | var args = filters ? nextField.args.filter(function (arg) {
|
14602 | return filters.indexOf(arg.name) !== -1;
|
14603 | }) : []; // T45504512: new connection model
|
14604 |
|
14605 | if (handle.dynamicKey != null) {
|
14606 | args.push({
|
14607 | kind: 'Argument',
|
14608 | loc: handle.dynamicKey.loc,
|
14609 | name: '__dynamicKey',
|
14610 | type: SchemaUtils.getNullableStringInput(schema),
|
14611 | value: nullthrows(handle.dynamicKey)
|
14612 | });
|
14613 | }
|
14614 |
|
14615 | return (0, _objectSpread2["default"])({}, nextField, {
|
14616 | args: args,
|
14617 | alias: alias,
|
14618 | name: name,
|
14619 | handles: null
|
14620 | });
|
14621 | }
|
14622 |
|
14623 | module.exports = {
|
14624 | transform: fieldHandleTransform
|
14625 | };
|
14626 |
|
14627 | /***/ }),
|
14628 | /* 80 */
|
14629 | /***/ (function(module, exports, __webpack_require__) {
|
14630 |
|
14631 | "use strict";
|
14632 | /**
|
14633 | * Copyright (c) Facebook, Inc. and its affiliates.
|
14634 | *
|
14635 | * This source code is licensed under the MIT license found in the
|
14636 | * LICENSE file in the root directory of this source tree.
|
14637 | *
|
14638 | *
|
14639 | * @format
|
14640 | */
|
14641 |
|
14642 |
|
14643 | var GraphQLIRTransformer = __webpack_require__(3);
|
14644 |
|
14645 | /**
|
14646 | * A transform that removes any directives that were not present in the
|
14647 | * server schema.
|
14648 | */
|
14649 | function filterDirectivesTransform(context) {
|
14650 | var schemaDirectives = new Set(context.getSchema().getDirectives().filter(function (directive) {
|
14651 | return !directive.clientOnlyDirective;
|
14652 | }).map(function (schemaDirective) {
|
14653 | return schemaDirective.name;
|
14654 | }));
|
14655 |
|
14656 | var visitDirective = function visitDirective(directive) {
|
14657 | if (schemaDirectives.has(directive.name)) {
|
14658 | return directive;
|
14659 | }
|
14660 |
|
14661 | return null;
|
14662 | };
|
14663 |
|
14664 | return GraphQLIRTransformer.transform(context, {
|
14665 | Directive: visitDirective
|
14666 | });
|
14667 | }
|
14668 |
|
14669 | module.exports = {
|
14670 | transform: filterDirectivesTransform
|
14671 | };
|
14672 |
|
14673 | /***/ }),
|
14674 | /* 81 */
|
14675 | /***/ (function(module, exports, __webpack_require__) {
|
14676 |
|
14677 | "use strict";
|
14678 | /**
|
14679 | * Copyright (c) Facebook, Inc. and its affiliates.
|
14680 | *
|
14681 | * This source code is licensed under the MIT license found in the
|
14682 | * LICENSE file in the root directory of this source tree.
|
14683 | *
|
14684 | *
|
14685 | * @format
|
14686 | */
|
14687 |
|
14688 |
|
14689 | var aStackPool = [];
|
14690 | var bStackPool = [];
|
14691 | /**
|
14692 | * Checks if two values are equal. Values may be primitives, arrays, or objects.
|
14693 | * Returns true if both arguments have the same keys and values.
|
14694 | *
|
14695 | * @see http://underscorejs.org
|
14696 | * @copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
|
14697 | * @license MIT
|
14698 | */
|
14699 |
|
14700 | function areEqual(a, b) {
|
14701 | var aStack = aStackPool.length ? aStackPool.pop() : [];
|
14702 | var bStack = bStackPool.length ? bStackPool.pop() : [];
|
14703 | var result = eq(a, b, aStack, bStack);
|
14704 | aStack.length = 0;
|
14705 | bStack.length = 0;
|
14706 | aStackPool.push(aStack);
|
14707 | bStackPool.push(bStack);
|
14708 | return result;
|
14709 | }
|
14710 |
|
14711 | function eq(a, b, aStack, bStack) {
|
14712 | if (a === b) {
|
14713 | // Identical objects are equal. `0 === -0`, but they aren't identical.
|
14714 | return a !== 0 || 1 / a === 1 / b;
|
14715 | }
|
14716 |
|
14717 | if (a == null || b == null) {
|
14718 | // a or b can be `null` or `undefined`
|
14719 | return false;
|
14720 | }
|
14721 |
|
14722 | if (typeof a !== 'object' || typeof b !== 'object') {
|
14723 | return false;
|
14724 | }
|
14725 |
|
14726 | var objToStr = Object.prototype.toString;
|
14727 | var className = objToStr.call(a);
|
14728 |
|
14729 | if (className !== objToStr.call(b)) {
|
14730 | return false;
|
14731 | }
|
14732 |
|
14733 | switch (className) {
|
14734 | case '[object String]':
|
14735 | return a === String(b);
|
14736 |
|
14737 | case '[object Number]':
|
14738 | return isNaN(a) || isNaN(b) ? false : a === Number(b);
|
14739 |
|
14740 | case '[object Date]':
|
14741 | case '[object Boolean]':
|
14742 | return +a === +b;
|
14743 |
|
14744 | case '[object RegExp]':
|
14745 | return a.source === b.source && a.global === b.global && a.multiline === b.multiline && a.ignoreCase === b.ignoreCase;
|
14746 | } // Assume equality for cyclic structures.
|
14747 |
|
14748 |
|
14749 | var length = aStack.length;
|
14750 |
|
14751 | while (length--) {
|
14752 | if (aStack[length] === a) {
|
14753 | return bStack[length] === b;
|
14754 | }
|
14755 | }
|
14756 |
|
14757 | aStack.push(a);
|
14758 | bStack.push(b);
|
14759 | var size = 0; // Recursively compare objects and arrays.
|
14760 |
|
14761 | if (className === '[object Array]') {
|
14762 | size = a.length;
|
14763 |
|
14764 | if (size !== b.length) {
|
14765 | return false;
|
14766 | } // Deep compare the contents, ignoring non-numeric properties.
|
14767 |
|
14768 |
|
14769 | while (size--) {
|
14770 | if (!eq(a[size], b[size], aStack, bStack)) {
|
14771 | return false;
|
14772 | }
|
14773 | }
|
14774 | } else {
|
14775 | if (a.constructor !== b.constructor) {
|
14776 | return false;
|
14777 | }
|
14778 |
|
14779 | if (a.hasOwnProperty('valueOf') && b.hasOwnProperty('valueOf')) {
|
14780 | return a.valueOf() === b.valueOf();
|
14781 | }
|
14782 |
|
14783 | var keys = Object.keys(a);
|
14784 |
|
14785 | if (keys.length !== Object.keys(b).length) {
|
14786 | return false;
|
14787 | }
|
14788 |
|
14789 | for (var i = 0; i < keys.length; i++) {
|
14790 | if (keys[i] === '_owner') {
|
14791 | // HACK: Comparing deeply nested React trees is slow since you end up
|
14792 | // comparing the entire tree (all ancestors and all children) and
|
14793 | // likely not what you want if you're comparing two elements with
|
14794 | // areEqual. We bail out here for now.
|
14795 | continue;
|
14796 | }
|
14797 |
|
14798 | if (!b.hasOwnProperty(keys[i]) || !eq(a[keys[i]], b[keys[i]], aStack, bStack)) {
|
14799 | return false;
|
14800 | }
|
14801 | }
|
14802 | }
|
14803 |
|
14804 | aStack.pop();
|
14805 | bStack.pop();
|
14806 | return true;
|
14807 | }
|
14808 |
|
14809 | module.exports = areEqual;
|
14810 |
|
14811 | /***/ }),
|
14812 | /* 82 */
|
14813 | /***/ (function(module, exports, __webpack_require__) {
|
14814 |
|
14815 | "use strict";
|
14816 | /**
|
14817 | * Copyright (c) Facebook, Inc. and its affiliates.
|
14818 | *
|
14819 | * This source code is licensed under the MIT license found in the
|
14820 | * LICENSE file in the root directory of this source tree.
|
14821 | *
|
14822 | *
|
14823 | * @format
|
14824 | */
|
14825 |
|
14826 |
|
14827 | var _interopRequireDefault = __webpack_require__(0);
|
14828 |
|
14829 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
14830 |
|
14831 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
14832 |
|
14833 | var IRTransformer = __webpack_require__(3);
|
14834 |
|
14835 | var SchemaUtils = __webpack_require__(11);
|
14836 |
|
14837 | var _require = __webpack_require__(38),
|
14838 | hasUnaliasedSelection = _require.hasUnaliasedSelection;
|
14839 |
|
14840 | var generateIDField = SchemaUtils.generateIDField;
|
14841 | var ID = 'id';
|
14842 | var NODE_TYPE = 'Node';
|
14843 |
|
14844 | /**
|
14845 | * A transform that adds an `id` field on any type that has an id field but
|
14846 | * where there is no unaliased `id` selection.
|
14847 | */
|
14848 | function generateIDFieldTransform(context) {
|
14849 | var schema = context.getSchema();
|
14850 | var idType = schema.expectIdType();
|
14851 | var idField = generateIDField(idType);
|
14852 | var state = {
|
14853 | idField: idField
|
14854 | };
|
14855 | return IRTransformer.transform(context, {
|
14856 | LinkedField: visitLinkedField
|
14857 | }, function () {
|
14858 | return state;
|
14859 | });
|
14860 | }
|
14861 |
|
14862 | function visitLinkedField(field, state) {
|
14863 | var transformedNode = this.traverse(field, state); // If the field already has an unaliased `id` field, do nothing
|
14864 |
|
14865 | if (hasUnaliasedSelection(field, ID)) {
|
14866 | return transformedNode;
|
14867 | }
|
14868 |
|
14869 | var context = this.getContext();
|
14870 | var schema = context.getSchema();
|
14871 | var unmodifiedType = schema.assertCompositeType(schema.getRawType(field.type)); // If the field type has an `id` subfield add an `id` selection
|
14872 |
|
14873 | if (schema.canHaveSelections(unmodifiedType) && schema.hasId(unmodifiedType)) {
|
14874 | return (0, _objectSpread2["default"])({}, transformedNode, {
|
14875 | selections: [].concat((0, _toConsumableArray2["default"])(transformedNode.selections), [state.idField])
|
14876 | });
|
14877 | } // If the field type is abstract, then generate a `... on Node { id }`
|
14878 | // fragment if *any* concrete type implements Node. Then generate a
|
14879 | // `... on PossibleType { id }` for every concrete type that does *not*
|
14880 | // implement `Node`
|
14881 |
|
14882 |
|
14883 | var nodeType = schema.getTypeFromString(NODE_TYPE);
|
14884 |
|
14885 | if (!nodeType) {
|
14886 | return transformedNode;
|
14887 | }
|
14888 |
|
14889 | var nodeInterface = schema.assertInterfaceType(nodeType);
|
14890 |
|
14891 | if (schema.isAbstractType(unmodifiedType)) {
|
14892 | var selections = (0, _toConsumableArray2["default"])(transformedNode.selections);
|
14893 |
|
14894 | if (schema.mayImplement(unmodifiedType, nodeInterface)) {
|
14895 | selections.push(buildIDFragment(nodeInterface, state.idField));
|
14896 | }
|
14897 |
|
14898 | schema.getPossibleTypes(schema.assertAbstractType(unmodifiedType)).forEach(function (possibleType) {
|
14899 | if (!schema.implementsInterface(schema.assertCompositeType(possibleType), nodeInterface) && schema.hasId(possibleType)) {
|
14900 | selections.push(buildIDFragment(possibleType, state.idField));
|
14901 | }
|
14902 | });
|
14903 | return (0, _objectSpread2["default"])({}, transformedNode, {
|
14904 | selections: selections
|
14905 | });
|
14906 | }
|
14907 |
|
14908 | return transformedNode;
|
14909 | }
|
14910 | /**
|
14911 | * @internal
|
14912 | *
|
14913 | * Returns IR for `... on FRAGMENT_TYPE { id }`
|
14914 | */
|
14915 |
|
14916 |
|
14917 | function buildIDFragment(fragmentType, idField) {
|
14918 | return {
|
14919 | kind: 'InlineFragment',
|
14920 | directives: [],
|
14921 | loc: {
|
14922 | kind: 'Generated'
|
14923 | },
|
14924 | metadata: null,
|
14925 | selections: [idField],
|
14926 | typeCondition: fragmentType
|
14927 | };
|
14928 | }
|
14929 |
|
14930 | module.exports = {
|
14931 | transform: generateIDFieldTransform
|
14932 | };
|
14933 |
|
14934 | /***/ }),
|
14935 | /* 83 */
|
14936 | /***/ (function(module, exports, __webpack_require__) {
|
14937 |
|
14938 | "use strict";
|
14939 | /**
|
14940 | * Copyright (c) Facebook, Inc. and its affiliates.
|
14941 | *
|
14942 | * This source code is licensed under the MIT license found in the
|
14943 | * LICENSE file in the root directory of this source tree.
|
14944 | *
|
14945 | *
|
14946 | * @format
|
14947 | */
|
14948 |
|
14949 |
|
14950 | var _interopRequireDefault = __webpack_require__(0);
|
14951 |
|
14952 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
14953 |
|
14954 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
14955 |
|
14956 | var IRTransformer = __webpack_require__(3);
|
14957 |
|
14958 | var _require = __webpack_require__(38),
|
14959 | hasUnaliasedSelection = _require.hasUnaliasedSelection;
|
14960 |
|
14961 | var TYPENAME_KEY = '__typename';
|
14962 | var cache = new Map();
|
14963 | /**
|
14964 | * A transform that adds `__typename` field on any `LinkedField` of a union or
|
14965 | * interface type where there is no unaliased `__typename` selection.
|
14966 | */
|
14967 |
|
14968 | function generateTypeNameTransform(context) {
|
14969 | cache = new Map();
|
14970 | var schema = context.getSchema();
|
14971 | var typenameField = {
|
14972 | kind: 'ScalarField',
|
14973 | alias: TYPENAME_KEY,
|
14974 | args: [],
|
14975 | directives: [],
|
14976 | handles: null,
|
14977 | loc: {
|
14978 | kind: 'Generated'
|
14979 | },
|
14980 | metadata: null,
|
14981 | name: TYPENAME_KEY,
|
14982 | type: schema.expectStringType()
|
14983 | };
|
14984 | var state = {
|
14985 | typenameField: typenameField
|
14986 | };
|
14987 | return IRTransformer.transform(context, {
|
14988 | LinkedField: visitLinkedField
|
14989 | }, function () {
|
14990 | return state;
|
14991 | });
|
14992 | }
|
14993 |
|
14994 | function visitLinkedField(field, state) {
|
14995 | var schema = this.getContext().getSchema();
|
14996 | var transformedNode = cache.get(field);
|
14997 |
|
14998 | if (transformedNode != null) {
|
14999 | return transformedNode;
|
15000 | }
|
15001 |
|
15002 | transformedNode = this.traverse(field, state);
|
15003 |
|
15004 | if (schema.isAbstractType(schema.getRawType(transformedNode.type)) && !hasUnaliasedSelection(transformedNode, TYPENAME_KEY)) {
|
15005 | transformedNode = (0, _objectSpread2["default"])({}, transformedNode, {
|
15006 | selections: [state.typenameField].concat((0, _toConsumableArray2["default"])(transformedNode.selections))
|
15007 | });
|
15008 | }
|
15009 |
|
15010 | cache.set(field, transformedNode);
|
15011 | return transformedNode;
|
15012 | }
|
15013 |
|
15014 | module.exports = {
|
15015 | transform: generateTypeNameTransform
|
15016 | };
|
15017 |
|
15018 | /***/ }),
|
15019 | /* 84 */
|
15020 | /***/ (function(module, exports, __webpack_require__) {
|
15021 |
|
15022 | "use strict";
|
15023 | /**
|
15024 | * Copyright (c) Facebook, Inc. and its affiliates.
|
15025 | *
|
15026 | * This source code is licensed under the MIT license found in the
|
15027 | * LICENSE file in the root directory of this source tree.
|
15028 | *
|
15029 | *
|
15030 | * @format
|
15031 | */
|
15032 |
|
15033 |
|
15034 | var _interopRequireDefault = __webpack_require__(0);
|
15035 |
|
15036 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
15037 |
|
15038 | var GraphQLIRTransformer = __webpack_require__(3);
|
15039 |
|
15040 | var _require = __webpack_require__(1),
|
15041 | createUserError = _require.createUserError;
|
15042 |
|
15043 | var SCHEMA_EXTENSION = "\ndirective @inline on FRAGMENT_DEFINITION\n";
|
15044 | /**
|
15045 | * A transform that converts fragment spreads where the referenced fragment
|
15046 | * is annotated with @inline to a InlineDataFragmentSpread.
|
15047 | * InlineDataFragmentSpreads have the selections of the referenced fragment inlined.
|
15048 | */
|
15049 |
|
15050 | function inlineDataFragmentTransform(context) {
|
15051 | return GraphQLIRTransformer.transform(context, {
|
15052 | // $FlowFixMe - this visitor intentionally changes node types
|
15053 | FragmentSpread: visitFragmentSpread,
|
15054 | Fragment: visitFragment
|
15055 | });
|
15056 | }
|
15057 |
|
15058 | function visitFragment(fragment) {
|
15059 | var transformedFragment = this.traverse(fragment);
|
15060 | var inlineDirective = transformedFragment.directives.find(function (directive) {
|
15061 | return directive.name === 'inline';
|
15062 | });
|
15063 |
|
15064 | if (inlineDirective == null) {
|
15065 | return transformedFragment;
|
15066 | }
|
15067 |
|
15068 | return (0, _objectSpread2["default"])({}, transformedFragment, {
|
15069 | directives: transformedFragment.directives.filter(function (directive) {
|
15070 | return directive !== inlineDirective;
|
15071 | }),
|
15072 | metadata: (0, _objectSpread2["default"])({}, transformedFragment.metadata || {}, {
|
15073 | inlineData: true
|
15074 | })
|
15075 | });
|
15076 | }
|
15077 |
|
15078 | function visitFragmentSpread(fragmentSpread) {
|
15079 | var transformedFragmentSpread = this.traverse(fragmentSpread);
|
15080 | var context = this.getContext();
|
15081 | var fragment = context.get(transformedFragmentSpread.name);
|
15082 |
|
15083 | if (!fragment || fragment.kind !== 'Fragment' || !fragment.directives.some(function (directive) {
|
15084 | return directive.name === 'inline';
|
15085 | })) {
|
15086 | return transformedFragmentSpread;
|
15087 | }
|
15088 |
|
15089 | if (fragment.argumentDefinitions.length > 0 || transformedFragmentSpread.args.length > 0) {
|
15090 | throw createUserError('Variables are not yet supported inside @inline fragments.', [fragment.argumentDefinitions[0].loc]);
|
15091 | }
|
15092 |
|
15093 | if (transformedFragmentSpread.directives.length > 0) {
|
15094 | throw createUserError('Directives on fragment spreads for @inline fragments are not yet ' + 'supported', [transformedFragmentSpread.loc]);
|
15095 | }
|
15096 |
|
15097 | var transformedFragment = this.visit(fragment);
|
15098 | return {
|
15099 | kind: 'InlineDataFragmentSpread',
|
15100 | loc: transformedFragmentSpread.loc,
|
15101 | metadata: transformedFragmentSpread.metadata,
|
15102 | name: transformedFragmentSpread.name,
|
15103 | selections: [{
|
15104 | directives: [],
|
15105 | kind: 'InlineFragment',
|
15106 | loc: {
|
15107 | kind: 'Derived',
|
15108 | source: transformedFragmentSpread.loc
|
15109 | },
|
15110 | metadata: null,
|
15111 | selections: transformedFragment.selections,
|
15112 | typeCondition: transformedFragment.type
|
15113 | }]
|
15114 | };
|
15115 | }
|
15116 |
|
15117 | module.exports = {
|
15118 | SCHEMA_EXTENSION: SCHEMA_EXTENSION,
|
15119 | transform: inlineDataFragmentTransform
|
15120 | };
|
15121 |
|
15122 | /***/ }),
|
15123 | /* 85 */
|
15124 | /***/ (function(module, exports, __webpack_require__) {
|
15125 |
|
15126 | "use strict";
|
15127 | /**
|
15128 | * Copyright (c) Facebook, Inc. and its affiliates.
|
15129 | *
|
15130 | * This source code is licensed under the MIT license found in the
|
15131 | * LICENSE file in the root directory of this source tree.
|
15132 | *
|
15133 | *
|
15134 | * @format
|
15135 | */
|
15136 |
|
15137 |
|
15138 | var GraphQLIRTransformer = __webpack_require__(3);
|
15139 |
|
15140 | var invariant = __webpack_require__(4);
|
15141 |
|
15142 | /**
|
15143 | * A transform that inlines all fragments and removes them.
|
15144 | */
|
15145 | function inlineFragmentsTransform(context) {
|
15146 | var visitFragmentSpread = fragmentSpreadVisitor(new Map());
|
15147 | return GraphQLIRTransformer.transform(context, {
|
15148 | Fragment: visitFragment,
|
15149 | FragmentSpread: visitFragmentSpread
|
15150 | });
|
15151 | }
|
15152 |
|
15153 | function visitFragment(fragment) {
|
15154 | return null;
|
15155 | }
|
15156 |
|
15157 | function fragmentSpreadVisitor(cache) {
|
15158 | return function visitFragmentSpread(fragmentSpread) {
|
15159 | var traverseResult = cache.get(fragmentSpread);
|
15160 |
|
15161 | if (traverseResult != null) {
|
15162 | return traverseResult;
|
15163 | }
|
15164 |
|
15165 | !(fragmentSpread.args.length === 0) ? true ? invariant(false, 'InlineFragmentsTransform: Cannot flatten fragment spread `%s` with ' + 'arguments. Use the `ApplyFragmentArgumentTransform` before flattening', fragmentSpread.name) : undefined : void 0;
|
15166 | var fragment = this.getContext().getFragment(fragmentSpread.name, fragmentSpread.loc);
|
15167 | var result = {
|
15168 | kind: 'InlineFragment',
|
15169 | directives: fragmentSpread.directives,
|
15170 | loc: {
|
15171 | kind: 'Derived',
|
15172 | source: fragmentSpread.loc
|
15173 | },
|
15174 | metadata: fragmentSpread.metadata,
|
15175 | selections: fragment.selections,
|
15176 | typeCondition: fragment.type
|
15177 | };
|
15178 | traverseResult = this.traverse(result);
|
15179 | cache.set(fragmentSpread, traverseResult);
|
15180 | return traverseResult;
|
15181 | };
|
15182 | }
|
15183 |
|
15184 | module.exports = {
|
15185 | transform: inlineFragmentsTransform
|
15186 | };
|
15187 |
|
15188 | /***/ }),
|
15189 | /* 86 */
|
15190 | /***/ (function(module, exports, __webpack_require__) {
|
15191 |
|
15192 | "use strict";
|
15193 | /**
|
15194 | * Copyright (c) Facebook, Inc. and its affiliates.
|
15195 | *
|
15196 | * This source code is licensed under the MIT license found in the
|
15197 | * LICENSE file in the root directory of this source tree.
|
15198 | *
|
15199 | *
|
15200 | * @format
|
15201 | */
|
15202 |
|
15203 |
|
15204 | var _require = __webpack_require__(1),
|
15205 | createUserError = _require.createUserError;
|
15206 |
|
15207 | /**
|
15208 | * Attempts to join the argument definitions for a root fragment
|
15209 | * and any unmasked fragment spreads reachable from that root fragment,
|
15210 | * returning a combined list of arguments or throwing if the same
|
15211 | * variable(s) are used in incompatible ways in different fragments.
|
15212 | */
|
15213 | function joinArgumentDefinitions(schema, fragment, reachableArguments, directiveName) {
|
15214 | var joinedArgumentDefinitions = new Map();
|
15215 | fragment.argumentDefinitions.forEach(function (prevArgDef) {
|
15216 | joinedArgumentDefinitions.set(prevArgDef.name, prevArgDef);
|
15217 | });
|
15218 | reachableArguments.forEach(function (nextArgDef) {
|
15219 | var prevArgDef = joinedArgumentDefinitions.get(nextArgDef.name);
|
15220 | var joinedArgDef = prevArgDef == null ? nextArgDef : joinArgumentDefinition(schema, prevArgDef, nextArgDef, directiveName);
|
15221 | joinedArgumentDefinitions.set(joinedArgDef.name, joinedArgDef);
|
15222 | });
|
15223 | return Array.from(joinedArgumentDefinitions.values());
|
15224 | }
|
15225 | /**
|
15226 | * @private
|
15227 | *
|
15228 | * Attempts to join two argument definitions, returning a single argument
|
15229 | * definition that is compatible with both of the inputs:
|
15230 | * - If the kind, name, or defaultValue is different then the arguments
|
15231 | * cannot be joined, indicated by returning null.
|
15232 | * - If either of next/prev is a subtype of the other, return the one
|
15233 | * that is the subtype: a more narrow type can flow into a more general
|
15234 | * type but not the inverse.
|
15235 | * - Otherwise there is no subtyping relation between prev/next, so return
|
15236 | * null to indicate they cannot be joined.
|
15237 | */
|
15238 |
|
15239 |
|
15240 | function joinArgumentDefinition(schema, prevArgDef, nextArgDef, directiveName) {
|
15241 | if (prevArgDef.kind !== nextArgDef.kind) {
|
15242 | throw createUserError('Cannot combine global and local variables when applying ' + "".concat(directiveName, "."), [prevArgDef.loc, nextArgDef.loc]);
|
15243 | } else if (prevArgDef.kind === 'LocalArgumentDefinition' && nextArgDef.kind === 'LocalArgumentDefinition' && prevArgDef.defaultValue !== nextArgDef.defaultValue) {
|
15244 | throw createUserError('Cannot combine local variables with different defaultValues when ' + "applying ".concat(directiveName, "."), [prevArgDef.loc, nextArgDef.loc]);
|
15245 | } else if (schema.isTypeSubTypeOf(nextArgDef.type, prevArgDef.type)) {
|
15246 | // prevArgDef is less strict than nextArgDef
|
15247 | return nextArgDef;
|
15248 | } else if (schema.isTypeSubTypeOf(prevArgDef.type, nextArgDef.type)) {
|
15249 | return prevArgDef;
|
15250 | } else {
|
15251 | throw createUserError('Cannot combine variables with incompatible types ' + "".concat(schema.getTypeString(prevArgDef.type), " and ").concat(schema.getTypeString(nextArgDef.type), " ") + "when applying ".concat(directiveName, "."), [prevArgDef.loc, nextArgDef.loc]);
|
15252 | }
|
15253 | }
|
15254 |
|
15255 | module.exports = joinArgumentDefinitions;
|
15256 |
|
15257 | /***/ }),
|
15258 | /* 87 */
|
15259 | /***/ (function(module, exports, __webpack_require__) {
|
15260 |
|
15261 | "use strict";
|
15262 | /**
|
15263 | * Copyright (c) Facebook, Inc. and its affiliates.
|
15264 | *
|
15265 | * This source code is licensed under the MIT license found in the
|
15266 | * LICENSE file in the root directory of this source tree.
|
15267 | *
|
15268 | *
|
15269 | * @format
|
15270 | */
|
15271 |
|
15272 |
|
15273 | var NodeQueryGenerator = __webpack_require__(88);
|
15274 |
|
15275 | var QueryQueryGenerator = __webpack_require__(89);
|
15276 |
|
15277 | var ViewerQueryGenerator = __webpack_require__(90);
|
15278 |
|
15279 | var _require = __webpack_require__(1),
|
15280 | createUserError = _require.createUserError;
|
15281 |
|
15282 | var GENERATORS = [ViewerQueryGenerator, QueryQueryGenerator, NodeQueryGenerator];
|
15283 | /**
|
15284 | * Builds a query to refetch the given fragment or throws if we have not way to
|
15285 | * generate one.
|
15286 | */
|
15287 |
|
15288 | function buildRefetchOperation(schema, fragment, queryName) {
|
15289 | for (var _i = 0, _GENERATORS = GENERATORS; _i < _GENERATORS.length; _i++) {
|
15290 | var generator = _GENERATORS[_i];
|
15291 | var refetchRoot = generator.buildRefetchOperation(schema, fragment, queryName);
|
15292 |
|
15293 | if (refetchRoot != null) {
|
15294 | return refetchRoot;
|
15295 | }
|
15296 | }
|
15297 |
|
15298 | throw createUserError("Invalid use of @refetchable on fragment '".concat(fragment.name, "', only ") + 'supported are fragments on:\n' + GENERATORS.map(function (generator) {
|
15299 | return " - ".concat(generator.description);
|
15300 | }).join('\n'), [fragment.loc]);
|
15301 | }
|
15302 |
|
15303 | module.exports = {
|
15304 | buildRefetchOperation: buildRefetchOperation
|
15305 | };
|
15306 |
|
15307 | /***/ }),
|
15308 | /* 88 */
|
15309 | /***/ (function(module, exports, __webpack_require__) {
|
15310 |
|
15311 | "use strict";
|
15312 | /**
|
15313 | * Copyright (c) Facebook, Inc. and its affiliates.
|
15314 | *
|
15315 | * This source code is licensed under the MIT license found in the
|
15316 | * LICENSE file in the root directory of this source tree.
|
15317 | *
|
15318 | *
|
15319 | * @format
|
15320 | */
|
15321 |
|
15322 |
|
15323 | var _interopRequireDefault = __webpack_require__(0);
|
15324 |
|
15325 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
15326 |
|
15327 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
15328 |
|
15329 | var SchemaUtils = __webpack_require__(11);
|
15330 |
|
15331 | var _require = __webpack_require__(1),
|
15332 | createUserError = _require.createUserError;
|
15333 |
|
15334 | var _require2 = __webpack_require__(21),
|
15335 | buildFragmentSpread = _require2.buildFragmentSpread,
|
15336 | buildOperationArgumentDefinitions = _require2.buildOperationArgumentDefinitions;
|
15337 |
|
15338 | var NODE_TYPE_NAME = 'Node';
|
15339 | var NODE_FIELD_NAME = 'node';
|
15340 |
|
15341 | function buildRefetchOperation(schema, fragment, queryName) {
|
15342 | var eligible = schema.getTypeString(fragment.type) === NODE_TYPE_NAME || schema.isObject(fragment.type) && schema.getInterfaces(schema.assertCompositeType(fragment.type)).some(function (interfaceType) {
|
15343 | return schema.areEqualTypes(interfaceType, schema.expectTypeFromString(NODE_TYPE_NAME));
|
15344 | }) || schema.isAbstractType(fragment.type) && Array.from(schema.getPossibleTypes(schema.assertAbstractType(fragment.type))).every(function (possibleType) {
|
15345 | return schema.implementsInterface(schema.assertCompositeType(possibleType), schema.assertInterfaceType(schema.expectTypeFromString(NODE_TYPE_NAME)));
|
15346 | });
|
15347 |
|
15348 | if (!eligible) {
|
15349 | return null;
|
15350 | }
|
15351 |
|
15352 | var queryType = schema.expectQueryType();
|
15353 | var nodeType = schema.getTypeFromString(NODE_TYPE_NAME);
|
15354 | var nodeField = schema.getFieldConfig(schema.expectField(queryType, NODE_FIELD_NAME));
|
15355 |
|
15356 | if (!(nodeType && schema.isInterface(nodeType) && schema.isInterface(nodeField.type) && schema.areEqualTypes(nodeField.type, nodeType) && nodeField.args.length === 1 && schema.areEqualTypes(schema.getNullableType(nodeField.args[0].type), schema.expectIdType()) && ( // the fragment must be on Node or on a type that implements Node
|
15357 | schema.isObject(fragment.type) && schema.getInterfaces(schema.assertCompositeType(fragment.type)).some(function (interfaceType) {
|
15358 | return schema.areEqualTypes(interfaceType, nodeType);
|
15359 | }) || schema.isAbstractType(fragment.type) && Array.from(schema.getPossibleTypes(schema.assertAbstractType(fragment.type))).every(function (possibleType) {
|
15360 | return schema.getInterfaces(schema.assertCompositeType(possibleType)).some(function (interfaceType) {
|
15361 | return schema.areEqualTypes(interfaceType, nodeType);
|
15362 | });
|
15363 | })))) {
|
15364 | throw createUserError("Invalid use of @refetchable on fragment '".concat(fragment.name, "', check ") + 'that your schema defines a `Node { id: ID }` interface and has a ' + '`node(id: ID): Node` field on the query type (the id argument may ' + 'also be non-null).', [fragment.loc]);
|
15365 | } // name and type of the node(_: ID) field parameter
|
15366 |
|
15367 |
|
15368 | var idArgName = nodeField.args[0].name;
|
15369 | var idArgType = nodeField.args[0].type; // name and type of the query variable
|
15370 |
|
15371 | var idVariableType = SchemaUtils.getNonNullIdInput(schema);
|
15372 | var idVariableName = 'id';
|
15373 | var argumentDefinitions = buildOperationArgumentDefinitions(fragment.argumentDefinitions);
|
15374 | var idArgument = argumentDefinitions.find(function (argDef) {
|
15375 | return argDef.name === idVariableName;
|
15376 | });
|
15377 |
|
15378 | if (idArgument != null) {
|
15379 | throw createUserError("Invalid use of @refetchable on fragment `".concat(fragment.name, "`, this ") + 'fragment already has an `$id` variable in scope.', [idArgument.loc]);
|
15380 | }
|
15381 |
|
15382 | var argumentDefinitionsWithId = [].concat((0, _toConsumableArray2["default"])(argumentDefinitions), [{
|
15383 | defaultValue: null,
|
15384 | kind: 'LocalArgumentDefinition',
|
15385 | loc: {
|
15386 | kind: 'Derived',
|
15387 | source: fragment.loc
|
15388 | },
|
15389 | name: idVariableName,
|
15390 | type: idVariableType
|
15391 | }]);
|
15392 | return {
|
15393 | path: [NODE_FIELD_NAME],
|
15394 | node: {
|
15395 | argumentDefinitions: argumentDefinitionsWithId,
|
15396 | directives: [],
|
15397 | kind: 'Root',
|
15398 | loc: {
|
15399 | kind: 'Derived',
|
15400 | source: fragment.loc
|
15401 | },
|
15402 | metadata: null,
|
15403 | name: queryName,
|
15404 | operation: 'query',
|
15405 | selections: [{
|
15406 | alias: NODE_FIELD_NAME,
|
15407 | args: [{
|
15408 | kind: 'Argument',
|
15409 | loc: {
|
15410 | kind: 'Derived',
|
15411 | source: fragment.loc
|
15412 | },
|
15413 | name: idArgName,
|
15414 | type: schema.assertInputType(idArgType),
|
15415 | value: {
|
15416 | kind: 'Variable',
|
15417 | loc: {
|
15418 | kind: 'Derived',
|
15419 | source: fragment.loc
|
15420 | },
|
15421 | variableName: idVariableName,
|
15422 | type: idVariableType
|
15423 | }
|
15424 | }],
|
15425 | connection: false,
|
15426 | directives: [],
|
15427 | handles: null,
|
15428 | kind: 'LinkedField',
|
15429 | loc: {
|
15430 | kind: 'Derived',
|
15431 | source: fragment.loc
|
15432 | },
|
15433 | metadata: null,
|
15434 | name: NODE_FIELD_NAME,
|
15435 | selections: [buildFragmentSpread(fragment)],
|
15436 | type: schema.assertLinkedFieldType(nodeType)
|
15437 | }],
|
15438 | type: queryType
|
15439 | },
|
15440 | transformedFragment: enforceIDField(schema, fragment)
|
15441 | };
|
15442 | }
|
15443 |
|
15444 | function enforceIDField(schema, fragment) {
|
15445 | var idSelection = fragment.selections.find(function (selection) {
|
15446 | return selection.kind === 'ScalarField' && selection.name === 'id' && selection.alias === 'id' && schema.areEqualTypes(schema.getNullableType(selection.type), schema.expectIdType());
|
15447 | });
|
15448 |
|
15449 | if (idSelection) {
|
15450 | return fragment;
|
15451 | }
|
15452 |
|
15453 | return (0, _objectSpread2["default"])({}, fragment, {
|
15454 | selections: [].concat((0, _toConsumableArray2["default"])(fragment.selections), [SchemaUtils.generateIDField(schema.expectIdType())])
|
15455 | });
|
15456 | }
|
15457 |
|
15458 | module.exports = {
|
15459 | description: 'the Node interface or types implementing the Node interface',
|
15460 | buildRefetchOperation: buildRefetchOperation
|
15461 | };
|
15462 |
|
15463 | /***/ }),
|
15464 | /* 89 */
|
15465 | /***/ (function(module, exports, __webpack_require__) {
|
15466 |
|
15467 | "use strict";
|
15468 | /**
|
15469 | * Copyright (c) Facebook, Inc. and its affiliates.
|
15470 | *
|
15471 | * This source code is licensed under the MIT license found in the
|
15472 | * LICENSE file in the root directory of this source tree.
|
15473 | *
|
15474 | *
|
15475 | * @format
|
15476 | */
|
15477 |
|
15478 |
|
15479 | var _require = __webpack_require__(21),
|
15480 | buildFragmentSpread = _require.buildFragmentSpread,
|
15481 | buildOperationArgumentDefinitions = _require.buildOperationArgumentDefinitions;
|
15482 |
|
15483 | function buildRefetchOperation(schema, fragment, queryName) {
|
15484 | var queryType = schema.expectQueryType();
|
15485 |
|
15486 | if (!schema.areEqualTypes(fragment.type, queryType)) {
|
15487 | return null;
|
15488 | }
|
15489 |
|
15490 | return {
|
15491 | path: [],
|
15492 | node: {
|
15493 | argumentDefinitions: buildOperationArgumentDefinitions(fragment.argumentDefinitions),
|
15494 | directives: [],
|
15495 | kind: 'Root',
|
15496 | loc: {
|
15497 | kind: 'Derived',
|
15498 | source: fragment.loc
|
15499 | },
|
15500 | metadata: null,
|
15501 | name: queryName,
|
15502 | operation: 'query',
|
15503 | selections: [buildFragmentSpread(fragment)],
|
15504 | type: queryType
|
15505 | },
|
15506 | transformedFragment: fragment
|
15507 | };
|
15508 | }
|
15509 |
|
15510 | module.exports = {
|
15511 | description: 'the query type',
|
15512 | buildRefetchOperation: buildRefetchOperation
|
15513 | };
|
15514 |
|
15515 | /***/ }),
|
15516 | /* 90 */
|
15517 | /***/ (function(module, exports, __webpack_require__) {
|
15518 |
|
15519 | "use strict";
|
15520 | /**
|
15521 | * Copyright (c) Facebook, Inc. and its affiliates.
|
15522 | *
|
15523 | * This source code is licensed under the MIT license found in the
|
15524 | * LICENSE file in the root directory of this source tree.
|
15525 | *
|
15526 | *
|
15527 | * @format
|
15528 | */
|
15529 |
|
15530 |
|
15531 | var _require = __webpack_require__(1),
|
15532 | createUserError = _require.createUserError;
|
15533 |
|
15534 | var _require2 = __webpack_require__(21),
|
15535 | buildFragmentSpread = _require2.buildFragmentSpread,
|
15536 | buildOperationArgumentDefinitions = _require2.buildOperationArgumentDefinitions;
|
15537 |
|
15538 | var VIEWER_TYPE_NAME = 'Viewer';
|
15539 | var VIEWER_FIELD_NAME = 'viewer';
|
15540 |
|
15541 | function buildRefetchOperation(schema, fragment, queryName) {
|
15542 | if (schema.getTypeString(fragment.type) !== VIEWER_TYPE_NAME) {
|
15543 | return null;
|
15544 | } // Handle fragments on viewer
|
15545 |
|
15546 |
|
15547 | var queryType = schema.expectQueryType();
|
15548 | var viewerType = schema.getTypeFromString(VIEWER_TYPE_NAME);
|
15549 | var viewerField = schema.getFieldConfig(schema.expectField(queryType, VIEWER_FIELD_NAME));
|
15550 |
|
15551 | if (!(viewerType && schema.isObject(viewerType) && schema.isObject(viewerField.type) && schema.areEqualTypes(viewerField.type, viewerType) && viewerField.args.length === 0 && schema.areEqualTypes(fragment.type, viewerType))) {
|
15552 | throw createUserError("Invalid use of @refetchable on fragment '".concat(fragment.name, "', check ") + "that your schema defines a 'Viewer' object type and has a " + "'viewer: Viewer' field on the query type.", [fragment.loc]);
|
15553 | }
|
15554 |
|
15555 | return {
|
15556 | path: [VIEWER_FIELD_NAME],
|
15557 | node: {
|
15558 | argumentDefinitions: buildOperationArgumentDefinitions(fragment.argumentDefinitions),
|
15559 | directives: [],
|
15560 | kind: 'Root',
|
15561 | loc: {
|
15562 | kind: 'Derived',
|
15563 | source: fragment.loc
|
15564 | },
|
15565 | metadata: null,
|
15566 | name: queryName,
|
15567 | operation: 'query',
|
15568 | selections: [{
|
15569 | alias: VIEWER_FIELD_NAME,
|
15570 | args: [],
|
15571 | connection: false,
|
15572 | directives: [],
|
15573 | handles: null,
|
15574 | kind: 'LinkedField',
|
15575 | loc: {
|
15576 | kind: 'Derived',
|
15577 | source: fragment.loc
|
15578 | },
|
15579 | metadata: null,
|
15580 | name: VIEWER_FIELD_NAME,
|
15581 | selections: [buildFragmentSpread(fragment)],
|
15582 | type: schema.assertLinkedFieldType(viewerType)
|
15583 | }],
|
15584 | type: queryType
|
15585 | },
|
15586 | transformedFragment: fragment
|
15587 | };
|
15588 | }
|
15589 |
|
15590 | module.exports = {
|
15591 | description: 'the Viewer type',
|
15592 | buildRefetchOperation: buildRefetchOperation
|
15593 | };
|
15594 |
|
15595 | /***/ }),
|
15596 | /* 91 */
|
15597 | /***/ (function(module, exports, __webpack_require__) {
|
15598 |
|
15599 | "use strict";
|
15600 | /**
|
15601 | * Copyright (c) Facebook, Inc. and its affiliates.
|
15602 | *
|
15603 | * This source code is licensed under the MIT license found in the
|
15604 | * LICENSE file in the root directory of this source tree.
|
15605 | *
|
15606 | *
|
15607 | * @format
|
15608 | */
|
15609 |
|
15610 |
|
15611 | var t = __webpack_require__(22);
|
15612 |
|
15613 | var _require = __webpack_require__(45),
|
15614 | exactObjectTypeAnnotation = _require.exactObjectTypeAnnotation,
|
15615 | readOnlyArrayOfType = _require.readOnlyArrayOfType;
|
15616 |
|
15617 | function getInputObjectTypeIdentifier(schema, typeID) {
|
15618 | return schema.getTypeString(typeID);
|
15619 | }
|
15620 |
|
15621 | function transformScalarType(schema, type, state, objectProps) {
|
15622 | if (schema.isNonNull(type)) {
|
15623 | return transformNonNullableScalarType(schema, schema.getNullableType(type), state, objectProps);
|
15624 | } else {
|
15625 | return t.nullableTypeAnnotation(transformNonNullableScalarType(schema, type, state, objectProps));
|
15626 | }
|
15627 | }
|
15628 |
|
15629 | function transformNonNullableScalarType(schema, type, state, objectProps) {
|
15630 | if (schema.isList(type)) {
|
15631 | return readOnlyArrayOfType(transformScalarType(schema, schema.getListItemType(type), state, objectProps));
|
15632 | } else if (schema.isObject(type) || schema.isUnion(type) || schema.isInterface(type)) {
|
15633 | return objectProps;
|
15634 | } else if (schema.isScalar(type)) {
|
15635 | return transformGraphQLScalarType(schema.getTypeString(type), state);
|
15636 | } else if (schema.isEnum(type)) {
|
15637 | return transformGraphQLEnumType(schema, schema.assertEnumType(type), state);
|
15638 | } else {
|
15639 | throw new Error("Could not convert from GraphQL type ".concat(String(type)));
|
15640 | }
|
15641 | }
|
15642 |
|
15643 | function transformGraphQLScalarType(typeName, state) {
|
15644 | var _customType;
|
15645 |
|
15646 | var customType = state.customScalars[typeName];
|
15647 |
|
15648 | if (typeof customType === 'function') {
|
15649 | return customType(t);
|
15650 | }
|
15651 |
|
15652 | switch ((_customType = customType) !== null && _customType !== void 0 ? _customType : typeName) {
|
15653 | case 'ID':
|
15654 | case 'String':
|
15655 | return t.stringTypeAnnotation();
|
15656 |
|
15657 | case 'Float':
|
15658 | case 'Int':
|
15659 | return t.numberTypeAnnotation();
|
15660 |
|
15661 | case 'Boolean':
|
15662 | return t.booleanTypeAnnotation();
|
15663 |
|
15664 | default:
|
15665 | return customType == null ? t.anyTypeAnnotation() : t.genericTypeAnnotation(t.identifier(customType));
|
15666 | }
|
15667 | }
|
15668 |
|
15669 | function transformGraphQLEnumType(schema, type, state) {
|
15670 | state.usedEnums[schema.getTypeString(type)] = type;
|
15671 | return t.genericTypeAnnotation(t.identifier(schema.getTypeString(type)));
|
15672 | }
|
15673 |
|
15674 | function transformInputType(schema, type, state) {
|
15675 | if (schema.isNonNull(type)) {
|
15676 | return transformNonNullableInputType(schema, schema.getNullableType(type), state);
|
15677 | } else {
|
15678 | return t.nullableTypeAnnotation(transformNonNullableInputType(schema, type, state));
|
15679 | }
|
15680 | }
|
15681 |
|
15682 | function transformNonNullableInputType(schema, type, state) {
|
15683 | if (schema.isList(type)) {
|
15684 | return readOnlyArrayOfType(transformInputType(schema, schema.getListItemType(type), state));
|
15685 | } else if (schema.isScalar(type)) {
|
15686 | return transformGraphQLScalarType(schema.getTypeString(type), state);
|
15687 | } else if (schema.isEnum(type)) {
|
15688 | return transformGraphQLEnumType(schema, schema.assertEnumType(type), state);
|
15689 | } else if (schema.isInputObject(type)) {
|
15690 | var typeIdentifier = getInputObjectTypeIdentifier(schema, type);
|
15691 |
|
15692 | if (state.generatedInputObjectTypes[typeIdentifier]) {
|
15693 | return t.genericTypeAnnotation(t.identifier(typeIdentifier));
|
15694 | }
|
15695 |
|
15696 | state.generatedInputObjectTypes[typeIdentifier] = 'pending';
|
15697 | var fields = schema.getFields(schema.assertInputObjectType(type));
|
15698 | var props = fields.map(function (fieldID) {
|
15699 | var fieldType = schema.getFieldType(fieldID);
|
15700 | var fieldName = schema.getFieldName(fieldID);
|
15701 | var property = t.objectTypeProperty(t.identifier(fieldName), transformInputType(schema, fieldType, state));
|
15702 |
|
15703 | if (state.optionalInputFields.indexOf(fieldName) >= 0 || !schema.isNonNull(fieldType)) {
|
15704 | property.optional = true;
|
15705 | }
|
15706 |
|
15707 | return property;
|
15708 | });
|
15709 | state.generatedInputObjectTypes[typeIdentifier] = exactObjectTypeAnnotation(props);
|
15710 | return t.genericTypeAnnotation(t.identifier(typeIdentifier));
|
15711 | } else {
|
15712 | throw new Error("Could not convert from GraphQL type ".concat(schema.getTypeString(type)));
|
15713 | }
|
15714 | }
|
15715 |
|
15716 | module.exports = {
|
15717 | transformInputType: transformInputType,
|
15718 | transformScalarType: transformScalarType
|
15719 | };
|
15720 |
|
15721 | /***/ }),
|
15722 | /* 92 */
|
15723 | /***/ (function(module, exports) {
|
15724 |
|
15725 | module.exports = require("@babel/generator");
|
15726 |
|
15727 | /***/ }),
|
15728 | /* 93 */
|
15729 | /***/ (function(module, exports, __webpack_require__) {
|
15730 |
|
15731 | "use strict";
|
15732 | /**
|
15733 | * Copyright (c) Facebook, Inc. and its affiliates.
|
15734 | *
|
15735 | * This source code is licensed under the MIT license found in the
|
15736 | * LICENSE file in the root directory of this source tree.
|
15737 | *
|
15738 | *
|
15739 | * @format
|
15740 | */
|
15741 |
|
15742 |
|
15743 | var GraphQLIRTransformer = __webpack_require__(3);
|
15744 |
|
15745 | function skipClientExtensionTransform(context) {
|
15746 | return GraphQLIRTransformer.transform(context, {
|
15747 | Fragment: visitFragment,
|
15748 | ClientExtension: visitClientExtension
|
15749 | });
|
15750 | }
|
15751 |
|
15752 | function visitFragment(node) {
|
15753 | var context = this.getContext();
|
15754 |
|
15755 | if (context.getSchema().isServerType(node.type)) {
|
15756 | return this.traverse(node);
|
15757 | }
|
15758 |
|
15759 | return null;
|
15760 | }
|
15761 |
|
15762 | function visitClientExtension(node, state) {
|
15763 | return null;
|
15764 | }
|
15765 |
|
15766 | module.exports = {
|
15767 | transform: skipClientExtensionTransform
|
15768 | };
|
15769 |
|
15770 | /***/ }),
|
15771 | /* 94 */
|
15772 | /***/ (function(module, exports, __webpack_require__) {
|
15773 |
|
15774 | "use strict";
|
15775 | /**
|
15776 | * Copyright (c) Facebook, Inc. and its affiliates.
|
15777 | *
|
15778 | * This source code is licensed under the MIT license found in the
|
15779 | * LICENSE file in the root directory of this source tree.
|
15780 | *
|
15781 | *
|
15782 | * @format
|
15783 | */
|
15784 |
|
15785 |
|
15786 | var _interopRequireDefault = __webpack_require__(0);
|
15787 |
|
15788 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
15789 |
|
15790 | var IRTransformer = __webpack_require__(3);
|
15791 |
|
15792 | /**
|
15793 | * A transform that removes field `handles`. Intended for use when e.g.
|
15794 | * printing queries to send to a GraphQL server.
|
15795 | */
|
15796 | function skipHandleFieldTransform(context) {
|
15797 | return IRTransformer.transform(context, {
|
15798 | LinkedField: visitField,
|
15799 | ScalarField: visitField
|
15800 | });
|
15801 | }
|
15802 |
|
15803 | function visitField(field) {
|
15804 | var transformedNode = this.traverse(field);
|
15805 |
|
15806 | if (transformedNode.handles) {
|
15807 | return (0, _objectSpread2["default"])({}, transformedNode, {
|
15808 | handles: null
|
15809 | });
|
15810 | }
|
15811 |
|
15812 | return transformedNode;
|
15813 | }
|
15814 |
|
15815 | module.exports = {
|
15816 | transform: skipHandleFieldTransform
|
15817 | };
|
15818 |
|
15819 | /***/ }),
|
15820 | /* 95 */
|
15821 | /***/ (function(module, exports, __webpack_require__) {
|
15822 |
|
15823 | "use strict";
|
15824 | /**
|
15825 | * Copyright (c) Facebook, Inc. and its affiliates.
|
15826 | *
|
15827 | * This source code is licensed under the MIT license found in the
|
15828 | * LICENSE file in the root directory of this source tree.
|
15829 | *
|
15830 | *
|
15831 | * @format
|
15832 | */
|
15833 |
|
15834 |
|
15835 | var _interopRequireDefault = __webpack_require__(0);
|
15836 |
|
15837 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
15838 |
|
15839 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
15840 |
|
15841 | var GraphQLIRTransformer = __webpack_require__(3);
|
15842 |
|
15843 | var IMap = __webpack_require__(14).Map;
|
15844 |
|
15845 | var partitionArray = __webpack_require__(28);
|
15846 |
|
15847 | var getIdentifierForSelection = __webpack_require__(37);
|
15848 |
|
15849 | var invariant = __webpack_require__(4);
|
15850 |
|
15851 | /**
|
15852 | * A transform that removes redundant fields and fragment spreads. Redundancy is
|
15853 | * defined in this context as any selection that is guaranteed to already be
|
15854 | * fetched by an ancestor selection. This can occur in two cases:
|
15855 | *
|
15856 | * 1. Simple duplicates at the same level of the document can always be skipped:
|
15857 | *
|
15858 | * ```
|
15859 | * fragment Foo on FooType {
|
15860 | * id
|
15861 | * id
|
15862 | * ...Bar
|
15863 | * ...Bar
|
15864 | * }
|
15865 | * ```
|
15866 | *
|
15867 | * Becomes
|
15868 | *
|
15869 | * ```
|
15870 | * fragment Foo on FooType {
|
15871 | * id
|
15872 | * ...Bar
|
15873 | * }
|
15874 | * ```
|
15875 | *
|
15876 | * 2. Inline fragments and conditions introduce the possibility for duplication
|
15877 | * at different levels of the tree. Whenever a selection is fetched in a parent,
|
15878 | * it is redundant to also fetch it in a child:
|
15879 | *
|
15880 | * ```
|
15881 | * fragment Foo on FooType {
|
15882 | * id
|
15883 | * ... on OtherType {
|
15884 | * id # 1
|
15885 | * }
|
15886 | * ... on FooType @include(if: $cond) {
|
15887 | * id # 2
|
15888 | * }
|
15889 | * }
|
15890 | * ```
|
15891 | *
|
15892 | * Becomes:
|
15893 | *
|
15894 | * ```
|
15895 | * fragment Foo on FooType {
|
15896 | * id
|
15897 | * }
|
15898 | * ```
|
15899 | *
|
15900 | * In this example:
|
15901 | * - 1 can be skipped because `id` is already fetched by the parent. Even
|
15902 | * though the type is different (FooType/OtherType), the inline fragment
|
15903 | * cannot match without the outer fragment matching so the outer `id` is
|
15904 | * guaranteed to already be fetched.
|
15905 | * - 2 can be skipped for similar reasons: it doesn't matter if the condition
|
15906 | * holds, `id` is already fetched by the parent regardless.
|
15907 | *
|
15908 | * This transform also handles more complicated cases in which selections are
|
15909 | * nested:
|
15910 | *
|
15911 | * ```
|
15912 | * fragment Foo on FooType {
|
15913 | * a {
|
15914 | * bb
|
15915 | * }
|
15916 | * ... on OtherType {
|
15917 | * a {
|
15918 | * bb # 1
|
15919 | * cc
|
15920 | * }
|
15921 | * }
|
15922 | * }
|
15923 | * ```
|
15924 | *
|
15925 | * Becomes
|
15926 | *
|
15927 | * ```
|
15928 | * fragment Foo on FooType {
|
15929 | * a {
|
15930 | * bb
|
15931 | * }
|
15932 | * ... on OtherType {
|
15933 | * a {
|
15934 | * cc
|
15935 | * }
|
15936 | * }
|
15937 | * }
|
15938 | * ```
|
15939 | *
|
15940 | * 1 can be skipped because it is already fetched at the outer level.
|
15941 | */
|
15942 | function skipRedundantNodesTransform(context) {
|
15943 | return GraphQLIRTransformer.transform(context, {
|
15944 | Root: visitNode,
|
15945 | Fragment: visitNode
|
15946 | });
|
15947 | }
|
15948 |
|
15949 | var cache = new Map();
|
15950 |
|
15951 | function visitNode(node) {
|
15952 | cache = new Map();
|
15953 | var context = this.getContext();
|
15954 | return transformNode(context.getSchema(), node, new IMap()).node;
|
15955 | }
|
15956 | /**
|
15957 | * The most straightforward approach would be two passes: one to record the
|
15958 | * structure of the document, one to prune duplicates. This implementation uses
|
15959 | * a single pass. Selections are sorted with fields first, "conditionals"
|
15960 | * (inline fragments & conditions) last. This means that all fields that are
|
15961 | * guaranteed to be fetched are encountered prior to any duplicates that may be
|
15962 | * fetched within a conditional.
|
15963 | *
|
15964 | * Because selections fetched within a conditional are not guaranteed to be
|
15965 | * fetched in the parent, a fork of the selection map is created when entering a
|
15966 | * conditional. The sort ensures that guaranteed fields have already been seen
|
15967 | * prior to the clone.
|
15968 | */
|
15969 |
|
15970 |
|
15971 | function transformNode(schema, node, selectionMap) {
|
15972 | // This will optimize a traversal of the same subselections.
|
15973 | // If it's the same node, and selectionMap is empty
|
15974 | // result of transformNode has to be the same.
|
15975 | var isEmptySelectionMap = selectionMap.size === 0;
|
15976 | var result;
|
15977 |
|
15978 | if (isEmptySelectionMap) {
|
15979 | result = cache.get(node);
|
15980 |
|
15981 | if (result != null) {
|
15982 | return result;
|
15983 | }
|
15984 | }
|
15985 |
|
15986 | var selections = [];
|
15987 | sortSelections(node.selections).forEach(function (selection) {
|
15988 | var identifier = getIdentifierForSelection(schema, selection);
|
15989 |
|
15990 | switch (selection.kind) {
|
15991 | case 'ScalarField':
|
15992 | case 'FragmentSpread':
|
15993 | {
|
15994 | if (!selectionMap.has(identifier)) {
|
15995 | selections.push(selection);
|
15996 | selectionMap = selectionMap.set(identifier, null);
|
15997 | }
|
15998 |
|
15999 | break;
|
16000 | }
|
16001 |
|
16002 | case 'Defer':
|
16003 | case 'Stream':
|
16004 | case 'ModuleImport':
|
16005 | case 'ClientExtension':
|
16006 | case 'InlineDataFragmentSpread':
|
16007 | case 'Connection':
|
16008 | case 'ConnectionField':
|
16009 | case 'LinkedField':
|
16010 | {
|
16011 | var transformed = transformNode(schema, selection, selectionMap.get(identifier) || new IMap());
|
16012 |
|
16013 | if (transformed.node) {
|
16014 | selections.push(transformed.node);
|
16015 | selectionMap = selectionMap.set(identifier, transformed.selectionMap);
|
16016 | }
|
16017 |
|
16018 | break;
|
16019 | }
|
16020 |
|
16021 | case 'InlineFragment':
|
16022 | case 'Condition':
|
16023 | {
|
16024 | // Fork the selection map to prevent conditional selections from
|
16025 | // affecting the outer "guaranteed" selections.
|
16026 | var _transformed = transformNode(schema, selection, selectionMap.get(identifier) || selectionMap);
|
16027 |
|
16028 | if (_transformed.node) {
|
16029 | selections.push(_transformed.node);
|
16030 | selectionMap = selectionMap.set(identifier, _transformed.selectionMap);
|
16031 | }
|
16032 |
|
16033 | break;
|
16034 | }
|
16035 |
|
16036 | default:
|
16037 | selection;
|
16038 | true ? true ? invariant(false, 'SkipRedundantNodesTransform: Unexpected node kind `%s`.', selection.kind) : undefined : undefined;
|
16039 | }
|
16040 | });
|
16041 | var nextNode = selections.length ? (0, _objectSpread2["default"])({}, node, {
|
16042 | selections: selections
|
16043 | }) : null;
|
16044 | result = {
|
16045 | selectionMap: selectionMap,
|
16046 | node: nextNode
|
16047 | };
|
16048 |
|
16049 | if (isEmptySelectionMap) {
|
16050 | cache.set(node, result);
|
16051 | }
|
16052 |
|
16053 | return result;
|
16054 | }
|
16055 | /**
|
16056 | * Sort inline fragments and conditions after other selections.
|
16057 | */
|
16058 |
|
16059 |
|
16060 | function sortSelections(selections) {
|
16061 | var isScalarOrLinkedField = function isScalarOrLinkedField(selection) {
|
16062 | return selection.kind === 'ScalarField' || selection.kind === 'LinkedField';
|
16063 | };
|
16064 |
|
16065 | var _partitionArray = partitionArray(selections, isScalarOrLinkedField),
|
16066 | scalarsAndLinkedFields = _partitionArray[0],
|
16067 | rest = _partitionArray[1];
|
16068 |
|
16069 | return [].concat((0, _toConsumableArray2["default"])(scalarsAndLinkedFields), (0, _toConsumableArray2["default"])(rest));
|
16070 | }
|
16071 |
|
16072 | module.exports = {
|
16073 | transform: skipRedundantNodesTransform
|
16074 | };
|
16075 |
|
16076 | /***/ }),
|
16077 | /* 96 */
|
16078 | /***/ (function(module, exports, __webpack_require__) {
|
16079 |
|
16080 | "use strict";
|
16081 | /**
|
16082 | * Copyright (c) Facebook, Inc. and its affiliates.
|
16083 | *
|
16084 | * This source code is licensed under the MIT license found in the
|
16085 | * LICENSE file in the root directory of this source tree.
|
16086 | *
|
16087 | *
|
16088 | * @format
|
16089 | */
|
16090 |
|
16091 |
|
16092 | var _interopRequireDefault = __webpack_require__(0);
|
16093 |
|
16094 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
16095 |
|
16096 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
16097 |
|
16098 | var GraphQLIRTransformer = __webpack_require__(3);
|
16099 |
|
16100 | var invariant = __webpack_require__(4);
|
16101 |
|
16102 | var FAIL = 'fail';
|
16103 | var PASS = 'pass';
|
16104 | var VARIABLE = 'variable';
|
16105 | /**
|
16106 | * A tranform that removes unreachable IR nodes from all documents in a corpus.
|
16107 | * The following nodes are removed:
|
16108 | * - Any node with `@include(if: false)`
|
16109 | * - Any node with `@skip(if: true)`
|
16110 | * - Any node with empty `selections`
|
16111 | */
|
16112 |
|
16113 | function skipUnreachableNodeTransform(context) {
|
16114 | var fragments = new Map();
|
16115 | var nextContext = GraphQLIRTransformer.transform(context, {
|
16116 | Root: function Root(node) {
|
16117 | return transformNode(context, fragments, node);
|
16118 | },
|
16119 | // Fragments are included below where referenced.
|
16120 | // Unreferenced fragments are not included.
|
16121 | Fragment: function Fragment(id) {
|
16122 | return null;
|
16123 | }
|
16124 | });
|
16125 | return Array.from(fragments.values()).reduce(function (ctx, fragment) {
|
16126 | return fragment ? ctx.add(fragment) : ctx;
|
16127 | }, nextContext);
|
16128 | }
|
16129 |
|
16130 | function transformNode(context, fragments, node) {
|
16131 | var queue = (0, _toConsumableArray2["default"])(node.selections);
|
16132 | var selections;
|
16133 |
|
16134 | while (queue.length) {
|
16135 | var selection = queue.shift();
|
16136 | var nextSelection = void 0;
|
16137 |
|
16138 | switch (selection.kind) {
|
16139 | case 'Condition':
|
16140 | var match = testCondition(selection);
|
16141 |
|
16142 | if (match === PASS) {
|
16143 | queue.unshift.apply(queue, (0, _toConsumableArray2["default"])(selection.selections));
|
16144 | } else if (match === VARIABLE) {
|
16145 | nextSelection = transformNode(context, fragments, selection);
|
16146 | }
|
16147 |
|
16148 | break;
|
16149 |
|
16150 | case 'FragmentSpread':
|
16151 | {
|
16152 | // Skip fragment spreads if the referenced fragment is empty
|
16153 | if (!fragments.has(selection.name)) {
|
16154 | var fragment = context.getFragment(selection.name);
|
16155 | var nextFragment = transformNode(context, fragments, fragment);
|
16156 | fragments.set(selection.name, nextFragment);
|
16157 | }
|
16158 |
|
16159 | if (fragments.get(selection.name)) {
|
16160 | nextSelection = selection;
|
16161 | }
|
16162 |
|
16163 | break;
|
16164 | }
|
16165 |
|
16166 | case 'ClientExtension':
|
16167 | nextSelection = transformNode(context, fragments, selection);
|
16168 | break;
|
16169 |
|
16170 | case 'ModuleImport':
|
16171 | nextSelection = transformNode(context, fragments, selection);
|
16172 | break;
|
16173 |
|
16174 | case 'LinkedField':
|
16175 | nextSelection = transformNode(context, fragments, selection);
|
16176 | break;
|
16177 |
|
16178 | case 'ConnectionField':
|
16179 | nextSelection = transformNode(context, fragments, selection);
|
16180 | break;
|
16181 |
|
16182 | case 'Connection':
|
16183 | nextSelection = transformNode(context, fragments, selection);
|
16184 | break;
|
16185 |
|
16186 | case 'InlineFragment':
|
16187 | // TODO combine with the LinkedField case when flow supports this
|
16188 | nextSelection = transformNode(context, fragments, selection);
|
16189 | break;
|
16190 |
|
16191 | case 'Defer':
|
16192 | nextSelection = transformNode(context, fragments, selection);
|
16193 | break;
|
16194 |
|
16195 | case 'Stream':
|
16196 | nextSelection = transformNode(context, fragments, selection);
|
16197 | break;
|
16198 |
|
16199 | case 'ScalarField':
|
16200 | nextSelection = selection;
|
16201 | break;
|
16202 |
|
16203 | case 'InlineDataFragmentSpread':
|
16204 | true ? true ? invariant(false, 'SkipUnreachableNodeTransform: Did not expect an ' + 'InlineDataFragmentSpread here. Only expecting ' + 'InlineDataFragmentSpread in reader ASTs and this transform to ' + 'run only on normalization ASTs.') : undefined : undefined;
|
16205 | // fallthrough
|
16206 |
|
16207 | default:
|
16208 | selection.kind;
|
16209 | true ? true ? invariant(false, 'SkipUnreachableNodeTransform: Unexpected selection kind `%s`.', selection.kind) : undefined : undefined;
|
16210 | }
|
16211 |
|
16212 | if (nextSelection) {
|
16213 | selections = selections || [];
|
16214 | selections.push(nextSelection);
|
16215 | }
|
16216 | }
|
16217 |
|
16218 | if (selections) {
|
16219 | return (0, _objectSpread2["default"])({}, node, {
|
16220 | selections: selections
|
16221 | });
|
16222 | }
|
16223 |
|
16224 | return null;
|
16225 | }
|
16226 | /**
|
16227 | * Determines whether a condition statically passes/fails or is unknown
|
16228 | * (variable).
|
16229 | */
|
16230 |
|
16231 |
|
16232 | function testCondition(condition) {
|
16233 | if (condition.condition.kind === 'Variable') {
|
16234 | return VARIABLE;
|
16235 | }
|
16236 |
|
16237 | return condition.condition.value === condition.passingValue ? PASS : FAIL;
|
16238 | }
|
16239 |
|
16240 | module.exports = {
|
16241 | transform: skipUnreachableNodeTransform
|
16242 | };
|
16243 |
|
16244 | /***/ }),
|
16245 | /* 97 */
|
16246 | /***/ (function(module, exports, __webpack_require__) {
|
16247 |
|
16248 | "use strict";
|
16249 | /**
|
16250 | * Copyright (c) Facebook, Inc. and its affiliates.
|
16251 | *
|
16252 | * This source code is licensed under the MIT license found in the
|
16253 | * LICENSE file in the root directory of this source tree.
|
16254 | *
|
16255 | *
|
16256 | * @format
|
16257 | */
|
16258 |
|
16259 |
|
16260 | var _interopRequireDefault = __webpack_require__(0);
|
16261 |
|
16262 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
16263 |
|
16264 | var inferRootArgumentDefinitions = __webpack_require__(17);
|
16265 |
|
16266 | /**
|
16267 | * Refines the argument definitions for operations to remove unused arguments
|
16268 | * due to statically pruned conditional branches (e.g. because of overriding
|
16269 | * a variable used in `@include()` to be false).
|
16270 | */
|
16271 | function skipUnusedVariablesTransform(context) {
|
16272 | var contextWithUsedArguments = inferRootArgumentDefinitions(context);
|
16273 | return context.withMutations(function (ctx) {
|
16274 | var nextContext = ctx;
|
16275 | var _iteratorNormalCompletion = true;
|
16276 | var _didIteratorError = false;
|
16277 | var _iteratorError = undefined;
|
16278 |
|
16279 | try {
|
16280 | var _loop = function _loop() {
|
16281 | var node = _step.value;
|
16282 |
|
16283 | if (node.kind !== 'Root') {
|
16284 | return "continue";
|
16285 | }
|
16286 |
|
16287 | var usedArguments = new Set(contextWithUsedArguments.getRoot(node.name).argumentDefinitions.map(function (argDef) {
|
16288 | return argDef.name;
|
16289 | })); // Remove unused argument definitions
|
16290 |
|
16291 | var usedArgumentDefinitions = node.argumentDefinitions.filter(function (argDef) {
|
16292 | return usedArguments.has(argDef.name);
|
16293 | });
|
16294 |
|
16295 | if (usedArgumentDefinitions.length !== node.argumentDefinitions.length) {
|
16296 | nextContext = nextContext.replace((0, _objectSpread2["default"])({}, node, {
|
16297 | argumentDefinitions: usedArgumentDefinitions
|
16298 | }));
|
16299 | }
|
16300 | };
|
16301 |
|
16302 | for (var _iterator = nextContext.documents()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
16303 | var _ret = _loop();
|
16304 |
|
16305 | if (_ret === "continue") continue;
|
16306 | }
|
16307 | } catch (err) {
|
16308 | _didIteratorError = true;
|
16309 | _iteratorError = err;
|
16310 | } finally {
|
16311 | try {
|
16312 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
16313 | _iterator["return"]();
|
16314 | }
|
16315 | } finally {
|
16316 | if (_didIteratorError) {
|
16317 | throw _iteratorError;
|
16318 | }
|
16319 | }
|
16320 | }
|
16321 |
|
16322 | return nextContext;
|
16323 | });
|
16324 | }
|
16325 |
|
16326 | module.exports = {
|
16327 | transform: skipUnusedVariablesTransform
|
16328 | };
|
16329 |
|
16330 | /***/ }),
|
16331 | /* 98 */
|
16332 | /***/ (function(module, exports, __webpack_require__) {
|
16333 |
|
16334 | "use strict";
|
16335 | /**
|
16336 | * Copyright (c) Facebook, Inc. and its affiliates.
|
16337 | *
|
16338 | * This source code is licensed under the MIT license found in the
|
16339 | * LICENSE file in the root directory of this source tree.
|
16340 | *
|
16341 | *
|
16342 | * @format
|
16343 | */
|
16344 |
|
16345 |
|
16346 | var IRTransformer = __webpack_require__(3);
|
16347 |
|
16348 | var getNormalizationOperationName = __webpack_require__(41);
|
16349 |
|
16350 | /**
|
16351 | * This transform creates a SplitOperation root for every ModuleImport.
|
16352 | */
|
16353 | function splitMatchTransform(context) {
|
16354 | var splitOperations = new Map();
|
16355 | var transformedContext = IRTransformer.transform(context, {
|
16356 | LinkedField: visitLinkedField,
|
16357 | InlineFragment: visitInlineFragment,
|
16358 | ModuleImport: visitModuleImport
|
16359 | }, function (node) {
|
16360 | return {
|
16361 | parentType: node.type,
|
16362 | splitOperations: splitOperations
|
16363 | };
|
16364 | });
|
16365 | return transformedContext.addAll(Array.from(splitOperations.values()));
|
16366 | }
|
16367 |
|
16368 | function visitLinkedField(field, state) {
|
16369 | return this.traverse(field, {
|
16370 | parentType: field.type,
|
16371 | splitOperations: state.splitOperations
|
16372 | });
|
16373 | }
|
16374 |
|
16375 | function visitInlineFragment(fragment, state) {
|
16376 | return this.traverse(fragment, {
|
16377 | parentType: fragment.typeCondition,
|
16378 | splitOperations: state.splitOperations
|
16379 | });
|
16380 | }
|
16381 |
|
16382 | function visitModuleImport(node, state) {
|
16383 | // It's possible for the same fragment to be selected in multiple usages
|
16384 | // of @module: skip processing a node if its SplitOperation has already
|
16385 | // been generated
|
16386 | var normalizationName = getNormalizationOperationName(node.name);
|
16387 | var createdSplitOperation = state.splitOperations.get(normalizationName);
|
16388 |
|
16389 | if (createdSplitOperation) {
|
16390 | createdSplitOperation.parentSources.add(node.documentName);
|
16391 | return node;
|
16392 | }
|
16393 |
|
16394 | var transformedNode = this.traverse(node, state);
|
16395 | var splitOperation = {
|
16396 | kind: 'SplitOperation',
|
16397 | name: normalizationName,
|
16398 | selections: transformedNode.selections,
|
16399 | loc: {
|
16400 | kind: 'Derived',
|
16401 | source: node.loc
|
16402 | },
|
16403 | parentSources: new Set([node.documentName]),
|
16404 | metadata: {
|
16405 | derivedFrom: transformedNode.name
|
16406 | },
|
16407 | type: state.parentType
|
16408 | };
|
16409 | state.splitOperations.set(normalizationName, splitOperation);
|
16410 | return transformedNode;
|
16411 | }
|
16412 |
|
16413 | module.exports = {
|
16414 | transform: splitMatchTransform
|
16415 | };
|
16416 |
|
16417 | /***/ }),
|
16418 | /* 99 */
|
16419 | /***/ (function(module, exports, __webpack_require__) {
|
16420 |
|
16421 | "use strict";
|
16422 | /**
|
16423 | * Copyright (c) Facebook, Inc. and its affiliates.
|
16424 | *
|
16425 | * This source code is licensed under the MIT license found in the
|
16426 | * LICENSE file in the root directory of this source tree.
|
16427 | *
|
16428 | *
|
16429 | * @format
|
16430 | * @emails oncall+relay
|
16431 | */
|
16432 |
|
16433 |
|
16434 | var _interopRequireDefault = __webpack_require__(0);
|
16435 |
|
16436 | var _objectSpread2 = _interopRequireDefault(__webpack_require__(2));
|
16437 |
|
16438 | var IRTransformer = __webpack_require__(3);
|
16439 |
|
16440 | // The purpose of this directive is to add GraphQL type inform for fields in
|
16441 | // the operation selection in order to use in in RelayMockPayloadGenerator
|
16442 | // to generate better mock values, and expand the API of MockResolvers
|
16443 | var SCHEMA_EXTENSION = 'directive @relay_test_operation on QUERY | MUTATION | SUBSCRIPTION';
|
16444 |
|
16445 | function testOperationDirective(context) {
|
16446 | return IRTransformer.transform(context, {
|
16447 | Fragment: function Fragment(node) {
|
16448 | return node;
|
16449 | },
|
16450 | Root: visitRoot,
|
16451 | SplitOperation: function SplitOperation(node) {
|
16452 | return node;
|
16453 | }
|
16454 | });
|
16455 | }
|
16456 |
|
16457 | function getTypeDetails(schema, fieldType) {
|
16458 | var nullableType = schema.getNullableType(fieldType);
|
16459 | var isNullable = !schema.isNonNull(fieldType);
|
16460 | var isPlural = schema.isList(nullableType);
|
16461 | var type = schema.getRawType(nullableType);
|
16462 | return {
|
16463 | type: schema.getTypeString(type),
|
16464 | enumValues: schema.isEnum(type) ? schema.getEnumValues(schema.assertEnumType(type)) : null,
|
16465 | plural: isPlural,
|
16466 | nullable: isNullable
|
16467 | };
|
16468 | }
|
16469 |
|
16470 | function visitRoot(node) {
|
16471 | var schema = this.getContext().getSchema();
|
16472 | var testDirective = node.directives.find(function (directive) {
|
16473 | return directive.name === 'relay_test_operation';
|
16474 | });
|
16475 |
|
16476 | if (testDirective == null) {
|
16477 | return node;
|
16478 | }
|
16479 |
|
16480 | var context = this.getContext();
|
16481 | var queue = [{
|
16482 | selections: node.selections,
|
16483 | path: null
|
16484 | }];
|
16485 | var selectionsTypeInfo = {};
|
16486 |
|
16487 | var _loop = function _loop() {
|
16488 | var _queue$pop = queue.pop(),
|
16489 | currentSelections = _queue$pop.selections,
|
16490 | path = _queue$pop.path;
|
16491 |
|
16492 | currentSelections.forEach(function (selection) {
|
16493 | switch (selection.kind) {
|
16494 | case 'FragmentSpread':
|
16495 | var fragment = context.get(selection.name);
|
16496 |
|
16497 | if (fragment != null) {
|
16498 | queue.unshift({
|
16499 | selections: fragment.selections,
|
16500 | path: path
|
16501 | });
|
16502 | }
|
16503 |
|
16504 | break;
|
16505 |
|
16506 | case 'ScalarField':
|
16507 | {
|
16508 | var nextPath = path === null ? selection.alias : "".concat(path, ".").concat(selection.alias);
|
16509 | selectionsTypeInfo[nextPath] = getTypeDetails(schema, selection.type);
|
16510 | break;
|
16511 | }
|
16512 |
|
16513 | case 'ConnectionField':
|
16514 | case 'LinkedField':
|
16515 | {
|
16516 | var _nextPath = path === null ? selection.alias : "".concat(path, ".").concat(selection.alias);
|
16517 |
|
16518 | selectionsTypeInfo[_nextPath] = getTypeDetails(schema, selection.type);
|
16519 | queue.unshift({
|
16520 | selections: selection.selections,
|
16521 | path: _nextPath
|
16522 | });
|
16523 | break;
|
16524 | }
|
16525 |
|
16526 | case 'Condition':
|
16527 | case 'Connection':
|
16528 | case 'ClientExtension':
|
16529 | case 'Defer':
|
16530 | case 'InlineDataFragmentSpread':
|
16531 | case 'InlineFragment':
|
16532 | case 'ModuleImport':
|
16533 | case 'Stream':
|
16534 | queue.unshift({
|
16535 | selections: selection.selections,
|
16536 | path: path
|
16537 | });
|
16538 | break;
|
16539 |
|
16540 | default:
|
16541 | selection;
|
16542 | break;
|
16543 | }
|
16544 | });
|
16545 | };
|
16546 |
|
16547 | while (queue.length > 0) {
|
16548 | _loop();
|
16549 | }
|
16550 |
|
16551 | return (0, _objectSpread2["default"])({}, node, {
|
16552 | directives: node.directives.filter(function (directive) {
|
16553 | return directive !== testDirective;
|
16554 | }),
|
16555 | metadata: (0, _objectSpread2["default"])({}, node.metadata || {}, {
|
16556 | relayTestingSelectionTypeInfo: selectionsTypeInfo
|
16557 | })
|
16558 | });
|
16559 | }
|
16560 |
|
16561 | module.exports = {
|
16562 | SCHEMA_EXTENSION: SCHEMA_EXTENSION,
|
16563 | transform: testOperationDirective
|
16564 | };
|
16565 |
|
16566 | /***/ }),
|
16567 | /* 100 */
|
16568 | /***/ (function(module, exports, __webpack_require__) {
|
16569 |
|
16570 | "use strict";
|
16571 | /**
|
16572 | * Copyright (c) Facebook, Inc. and its affiliates.
|
16573 | *
|
16574 | * This source code is licensed under the MIT license found in the
|
16575 | * LICENSE file in the root directory of this source tree.
|
16576 | *
|
16577 | *
|
16578 | * @format
|
16579 | */
|
16580 |
|
16581 |
|
16582 | var inferRootArgumentDefinitions = __webpack_require__(17);
|
16583 |
|
16584 | var _require = __webpack_require__(1),
|
16585 | createUserError = _require.createUserError,
|
16586 | eachWithCombinedError = _require.eachWithCombinedError;
|
16587 |
|
16588 | /**
|
16589 | * Validates that all global variables used in operations are defined at the
|
16590 | * root. This isn't a real transform as it returns the original context, but
|
16591 | * has to happen before other transforms strip certain variable usages.
|
16592 | */
|
16593 | function validateGlobalVariablesTransform(context) {
|
16594 | var contextWithUsedArguments = inferRootArgumentDefinitions(context);
|
16595 | eachWithCombinedError(context.documents(), function (node) {
|
16596 | if (node.kind !== 'Root') {
|
16597 | return;
|
16598 | }
|
16599 |
|
16600 | var nodeWithUsedArguments = contextWithUsedArguments.getRoot(node.name);
|
16601 | var definedArguments = argumentDefinitionsToMap(node.argumentDefinitions);
|
16602 | var usedArguments = argumentDefinitionsToMap(nodeWithUsedArguments.argumentDefinitions); // All used arguments must be defined
|
16603 |
|
16604 | var undefinedVariables = [];
|
16605 | var _iteratorNormalCompletion = true;
|
16606 | var _didIteratorError = false;
|
16607 | var _iteratorError = undefined;
|
16608 |
|
16609 | try {
|
16610 | for (var _iterator = usedArguments.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
16611 | var argDef = _step.value;
|
16612 |
|
16613 | if (!definedArguments.has(argDef.name)) {
|
16614 | undefinedVariables.push(argDef);
|
16615 | }
|
16616 | }
|
16617 | } catch (err) {
|
16618 | _didIteratorError = true;
|
16619 | _iteratorError = err;
|
16620 | } finally {
|
16621 | try {
|
16622 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
16623 | _iterator["return"]();
|
16624 | }
|
16625 | } finally {
|
16626 | if (_didIteratorError) {
|
16627 | throw _iteratorError;
|
16628 | }
|
16629 | }
|
16630 | }
|
16631 |
|
16632 | if (undefinedVariables.length !== 0) {
|
16633 | throw createUserError("Operation '".concat(node.name, "' references undefined variable(s):\n").concat(undefinedVariables.map(function (argDef) {
|
16634 | return "- $".concat(argDef.name, ": ").concat(context.getSchema().getTypeString(argDef.type));
|
16635 | }).join('\n'), "."), undefinedVariables.map(function (argDef) {
|
16636 | return argDef.loc;
|
16637 | }));
|
16638 | }
|
16639 | });
|
16640 | return context;
|
16641 | }
|
16642 |
|
16643 | function argumentDefinitionsToMap(argDefs) {
|
16644 | var map = new Map();
|
16645 | var _iteratorNormalCompletion2 = true;
|
16646 | var _didIteratorError2 = false;
|
16647 | var _iteratorError2 = undefined;
|
16648 |
|
16649 | try {
|
16650 | for (var _iterator2 = argDefs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
16651 | var argDef = _step2.value;
|
16652 | map.set(argDef.name, argDef);
|
16653 | }
|
16654 | } catch (err) {
|
16655 | _didIteratorError2 = true;
|
16656 | _iteratorError2 = err;
|
16657 | } finally {
|
16658 | try {
|
16659 | if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
16660 | _iterator2["return"]();
|
16661 | }
|
16662 | } finally {
|
16663 | if (_didIteratorError2) {
|
16664 | throw _iteratorError2;
|
16665 | }
|
16666 | }
|
16667 | }
|
16668 |
|
16669 | return map;
|
16670 | }
|
16671 |
|
16672 | module.exports = {
|
16673 | transform: validateGlobalVariablesTransform
|
16674 | };
|
16675 |
|
16676 | /***/ }),
|
16677 | /* 101 */
|
16678 | /***/ (function(module, exports, __webpack_require__) {
|
16679 |
|
16680 | "use strict";
|
16681 | /**
|
16682 | * Copyright (c) Facebook, Inc. and its affiliates.
|
16683 | *
|
16684 | * This source code is licensed under the MIT license found in the
|
16685 | * LICENSE file in the root directory of this source tree.
|
16686 | *
|
16687 | *
|
16688 | * @format
|
16689 | */
|
16690 |
|
16691 |
|
16692 | var GraphQLIRValidator = __webpack_require__(46);
|
16693 |
|
16694 | var _require = __webpack_require__(1),
|
16695 | createUserError = _require.createUserError;
|
16696 |
|
16697 | var _require2 = __webpack_require__(30),
|
16698 | getFieldDefinitionStrict = _require2.getFieldDefinitionStrict;
|
16699 |
|
16700 | /*
|
16701 | * Validate required arguments are provided after transforms filling in arguments
|
16702 | */
|
16703 | function validateRequiredArguments(context) {
|
16704 | GraphQLIRValidator.validate(context, {
|
16705 | Directive: visitDirective,
|
16706 | ConnectionField: visitField,
|
16707 | InlineFragment: visitInlineFragment,
|
16708 | LinkedField: visitField,
|
16709 | ScalarField: visitField // FragmentSpread validation is done in ApplyFragmentArgumentTransform
|
16710 |
|
16711 | }, function (node) {
|
16712 | return {
|
16713 | rootNode: node,
|
16714 | parentType: node.type
|
16715 | };
|
16716 | });
|
16717 | return context;
|
16718 | }
|
16719 |
|
16720 | function visitDirective(node, _ref) {
|
16721 | var rootNode = _ref.rootNode;
|
16722 | var context = this.getContext();
|
16723 | var directiveDef = context.getSchema().getDirective(node.name);
|
16724 |
|
16725 | if (directiveDef == null) {
|
16726 | return;
|
16727 | }
|
16728 |
|
16729 | validateRequiredArgumentsOnNode(context.getSchema(), node, directiveDef.args, rootNode);
|
16730 | }
|
16731 |
|
16732 | function visitInlineFragment(fragment, _ref2) {
|
16733 | var rootNode = _ref2.rootNode;
|
16734 | this.traverse(fragment, {
|
16735 | rootNode: rootNode,
|
16736 | parentType: fragment.typeCondition
|
16737 | });
|
16738 | }
|
16739 |
|
16740 | function visitField(node, _ref3) {
|
16741 | var parentType = _ref3.parentType,
|
16742 | rootNode = _ref3.rootNode;
|
16743 | var context = this.getContext();
|
16744 | var schema = context.getSchema();
|
16745 | var definition = getFieldDefinitionStrict(schema, parentType, node.name);
|
16746 |
|
16747 | if (definition == null) {
|
16748 | var isLegacyFatInterface = node.directives.some(function (directive) {
|
16749 | return directive.name === 'fixme_fat_interface';
|
16750 | });
|
16751 |
|
16752 | if (!isLegacyFatInterface) {
|
16753 | throw createUserError("Unknown field '".concat(node.name, "' on type ") + "'".concat(schema.getTypeString(parentType), "'."), [node.loc]);
|
16754 | }
|
16755 | } else {
|
16756 | validateRequiredArgumentsOnNode(schema, node, schema.getFieldConfig(definition).args, rootNode);
|
16757 | }
|
16758 |
|
16759 | this.traverse(node, {
|
16760 | rootNode: rootNode,
|
16761 | parentType: node.type
|
16762 | });
|
16763 | }
|
16764 |
|
16765 | function validateRequiredArgumentsOnNode(schema, node, definitionArgs, rootNode) {
|
16766 | var nodeArgsSet = new Set(node.args.map(function (arg) {
|
16767 | return arg.name;
|
16768 | }));
|
16769 | var _iteratorNormalCompletion = true;
|
16770 | var _didIteratorError = false;
|
16771 | var _iteratorError = undefined;
|
16772 |
|
16773 | try {
|
16774 | for (var _iterator = definitionArgs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
16775 | var arg = _step.value;
|
16776 |
|
16777 | if (schema.isNonNull(arg.type) && !nodeArgsSet.has(arg.name)) {
|
16778 | throw createUserError("Required argument '".concat(arg.name, ": ").concat(schema.getTypeString(arg.type), "' ") + "is missing on '".concat(node.name, "' in '").concat(rootNode.name, "'."), [node.loc, rootNode.loc]);
|
16779 | }
|
16780 | }
|
16781 | } catch (err) {
|
16782 | _didIteratorError = true;
|
16783 | _iteratorError = err;
|
16784 | } finally {
|
16785 | try {
|
16786 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
16787 | _iterator["return"]();
|
16788 | }
|
16789 | } finally {
|
16790 | if (_didIteratorError) {
|
16791 | throw _iteratorError;
|
16792 | }
|
16793 | }
|
16794 | }
|
16795 | }
|
16796 |
|
16797 | module.exports = {
|
16798 | transform: validateRequiredArguments
|
16799 | };
|
16800 |
|
16801 | /***/ }),
|
16802 | /* 102 */
|
16803 | /***/ (function(module, exports, __webpack_require__) {
|
16804 |
|
16805 | "use strict";
|
16806 | /**
|
16807 | * Copyright (c) Facebook, Inc. and its affiliates.
|
16808 | *
|
16809 | * This source code is licensed under the MIT license found in the
|
16810 | * LICENSE file in the root directory of this source tree.
|
16811 | *
|
16812 | *
|
16813 | * @format
|
16814 | */
|
16815 |
|
16816 |
|
16817 | var GraphQLIRValidator = __webpack_require__(46);
|
16818 |
|
16819 | var _require = __webpack_require__(1),
|
16820 | createUserError = _require.createUserError;
|
16821 |
|
16822 | var NODEKIND_DIRECTIVE_MAP = {
|
16823 | Defer: 'defer',
|
16824 | Stream: 'stream'
|
16825 | };
|
16826 | /*
|
16827 | * Validate that server-only directives are not used inside client fields
|
16828 | */
|
16829 |
|
16830 | function validateServerOnlyDirectives(context) {
|
16831 | GraphQLIRValidator.validate(context, {
|
16832 | ClientExtension: visitClientExtension,
|
16833 | Defer: visitTransformedDirective,
|
16834 | Stream: visitTransformedDirective,
|
16835 | LinkedField: visitLinkedField,
|
16836 | ScalarField: stopVisit
|
16837 | }, function () {
|
16838 | return {
|
16839 | rootClientSelection: null
|
16840 | };
|
16841 | });
|
16842 | return context;
|
16843 | } // If an empty visitor is defined, we no longer automatically visit child nodes
|
16844 | // such as arguments.
|
16845 |
|
16846 |
|
16847 | function stopVisit() {} // Only visits selections as an optimization to not look at arguments
|
16848 |
|
16849 |
|
16850 | function visitLinkedField(node, state) {
|
16851 | var _iteratorNormalCompletion = true;
|
16852 | var _didIteratorError = false;
|
16853 | var _iteratorError = undefined;
|
16854 |
|
16855 | try {
|
16856 | for (var _iterator = node.selections[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
16857 | var selection = _step.value;
|
16858 | this.visit(selection, state);
|
16859 | }
|
16860 | } catch (err) {
|
16861 | _didIteratorError = true;
|
16862 | _iteratorError = err;
|
16863 | } finally {
|
16864 | try {
|
16865 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
16866 | _iterator["return"]();
|
16867 | }
|
16868 | } finally {
|
16869 | if (_didIteratorError) {
|
16870 | throw _iteratorError;
|
16871 | }
|
16872 | }
|
16873 | }
|
16874 | }
|
16875 |
|
16876 | function visitClientExtension(node, state) {
|
16877 | var _iteratorNormalCompletion2 = true;
|
16878 | var _didIteratorError2 = false;
|
16879 | var _iteratorError2 = undefined;
|
16880 |
|
16881 | try {
|
16882 | for (var _iterator2 = node.selections[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
16883 | var selection = _step2.value;
|
16884 | this.visit(selection, {
|
16885 | rootClientSelection: selection
|
16886 | });
|
16887 | }
|
16888 | } catch (err) {
|
16889 | _didIteratorError2 = true;
|
16890 | _iteratorError2 = err;
|
16891 | } finally {
|
16892 | try {
|
16893 | if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
16894 | _iterator2["return"]();
|
16895 | }
|
16896 | } finally {
|
16897 | if (_didIteratorError2) {
|
16898 | throw _iteratorError2;
|
16899 | }
|
16900 | }
|
16901 | }
|
16902 | }
|
16903 |
|
16904 | function visitTransformedDirective(node, state) {
|
16905 | if (state.rootClientSelection) {
|
16906 | throwError("@".concat(NODEKIND_DIRECTIVE_MAP[node.kind]), node.loc, state.rootClientSelection.loc);
|
16907 | } // directive used only on client fields
|
16908 |
|
16909 |
|
16910 | if (node.selections.every(function (sel) {
|
16911 | return sel.kind === 'ClientExtension';
|
16912 | })) {
|
16913 | var _clientExtension$sele;
|
16914 |
|
16915 | var clientExtension = node.selections[0];
|
16916 | throwError("@".concat(NODEKIND_DIRECTIVE_MAP[node.kind]), node.loc, clientExtension && clientExtension.kind === 'ClientExtension' ? (_clientExtension$sele = clientExtension.selections[0]) === null || _clientExtension$sele === void 0 ? void 0 : _clientExtension$sele.loc : null);
|
16917 | }
|
16918 |
|
16919 | this.traverse(node, state);
|
16920 | }
|
16921 |
|
16922 | function throwError(directiveName, directiveLoc, clientExtensionLoc) {
|
16923 | throw createUserError("Unexpected directive: ".concat(directiveName, ". ") + 'This directive can only be used on fields/fragments that are ' + 'fetched from the server schema, but it is used ' + 'inside a client-only selection.', clientExtensionLoc == null || directiveLoc === clientExtensionLoc ? [directiveLoc] : [directiveLoc, clientExtensionLoc]);
|
16924 | }
|
16925 |
|
16926 | module.exports = {
|
16927 | transform: validateServerOnlyDirectives
|
16928 | };
|
16929 |
|
16930 | /***/ }),
|
16931 | /* 103 */
|
16932 | /***/ (function(module, exports, __webpack_require__) {
|
16933 |
|
16934 | "use strict";
|
16935 | /**
|
16936 | * Copyright (c) Facebook, Inc. and its affiliates.
|
16937 | *
|
16938 | * This source code is licensed under the MIT license found in the
|
16939 | * LICENSE file in the root directory of this source tree.
|
16940 | *
|
16941 | *
|
16942 | * @format
|
16943 | */
|
16944 |
|
16945 |
|
16946 | var inferRootArgumentDefinitions = __webpack_require__(17);
|
16947 |
|
16948 | var _require = __webpack_require__(1),
|
16949 | createUserError = _require.createUserError,
|
16950 | eachWithCombinedError = _require.eachWithCombinedError;
|
16951 |
|
16952 | var SCHEMA_EXTENSION = 'directive @DEPRECATED__relay_ignore_unused_variables_error on QUERY | MUTATION | SUBSCRIPTION';
|
16953 | /**
|
16954 | * Validates that there are no unused variables in the operation.
|
16955 | * former `graphql-js`` NoUnusedVariablesRule
|
16956 | */
|
16957 |
|
16958 | function validateUnusedVariablesTransform(context) {
|
16959 | var contextWithUsedArguments = inferRootArgumentDefinitions(context);
|
16960 | eachWithCombinedError(context.documents(), function (node) {
|
16961 | if (node.kind !== 'Root') {
|
16962 | return;
|
16963 | }
|
16964 |
|
16965 | var rootArgumentLocations = new Map(node.argumentDefinitions.map(function (arg) {
|
16966 | return [arg.name, arg.loc];
|
16967 | }));
|
16968 | var nodeWithUsedArguments = contextWithUsedArguments.getRoot(node.name);
|
16969 | var usedArguments = argumentDefinitionsToMap(nodeWithUsedArguments.argumentDefinitions);
|
16970 | var _iteratorNormalCompletion = true;
|
16971 | var _didIteratorError = false;
|
16972 | var _iteratorError = undefined;
|
16973 |
|
16974 | try {
|
16975 | for (var _iterator = usedArguments.keys()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
16976 | var usedArgumentName = _step.value;
|
16977 | rootArgumentLocations["delete"](usedArgumentName);
|
16978 | }
|
16979 | } catch (err) {
|
16980 | _didIteratorError = true;
|
16981 | _iteratorError = err;
|
16982 | } finally {
|
16983 | try {
|
16984 | if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
16985 | _iterator["return"]();
|
16986 | }
|
16987 | } finally {
|
16988 | if (_didIteratorError) {
|
16989 | throw _iteratorError;
|
16990 | }
|
16991 | }
|
16992 | }
|
16993 |
|
16994 | var ignoreErrorDirective = node.directives.find(function (_ref) {
|
16995 | var name = _ref.name;
|
16996 | return name === 'DEPRECATED__relay_ignore_unused_variables_error';
|
16997 | });
|
16998 |
|
16999 | if (rootArgumentLocations.size > 0 && !ignoreErrorDirective) {
|
17000 | var isPlural = rootArgumentLocations.size > 1;
|
17001 | throw createUserError("Variable".concat(isPlural ? 's' : '', " '$").concat(Array.from(rootArgumentLocations.keys()).join("', '$"), "' ").concat(isPlural ? 'are' : 'is', " never used in operation '").concat(node.name, "'."), Array.from(rootArgumentLocations.values()));
|
17002 | }
|
17003 |
|
17004 | if (rootArgumentLocations.size === 0 && ignoreErrorDirective) {
|
17005 | throw createUserError("Invalid usage of '@DEPRECATED__relay_ignore_unused_variables_error.'" + "No unused variables found in the query '".concat(node.name, "'"), [ignoreErrorDirective.loc]);
|
17006 | }
|
17007 | });
|
17008 | return context;
|
17009 | }
|
17010 |
|
17011 | function argumentDefinitionsToMap(argDefs) {
|
17012 | var map = new Map();
|
17013 | var _iteratorNormalCompletion2 = true;
|
17014 | var _didIteratorError2 = false;
|
17015 | var _iteratorError2 = undefined;
|
17016 |
|
17017 | try {
|
17018 | for (var _iterator2 = argDefs[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
17019 | var argDef = _step2.value;
|
17020 | map.set(argDef.name, argDef);
|
17021 | }
|
17022 | } catch (err) {
|
17023 | _didIteratorError2 = true;
|
17024 | _iteratorError2 = err;
|
17025 | } finally {
|
17026 | try {
|
17027 | if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
17028 | _iterator2["return"]();
|
17029 | }
|
17030 | } finally {
|
17031 | if (_didIteratorError2) {
|
17032 | throw _iteratorError2;
|
17033 | }
|
17034 | }
|
17035 | }
|
17036 |
|
17037 | return map;
|
17038 | }
|
17039 |
|
17040 | module.exports = {
|
17041 | transform: validateUnusedVariablesTransform,
|
17042 | SCHEMA_EXTENSION: SCHEMA_EXTENSION
|
17043 | };
|
17044 |
|
17045 | /***/ }),
|
17046 | /* 104 */
|
17047 | /***/ (function(module, exports, __webpack_require__) {
|
17048 |
|
17049 | "use strict";
|
17050 | /**
|
17051 | * Copyright (c) Facebook, Inc. and its affiliates.
|
17052 | *
|
17053 | * This source code is licensed under the MIT license found in the
|
17054 | * LICENSE file in the root directory of this source tree.
|
17055 | *
|
17056 | *
|
17057 | * @format
|
17058 | */
|
17059 |
|
17060 |
|
17061 | var RelayFlowGenerator = __webpack_require__(44);
|
17062 |
|
17063 | var formatGeneratedModule = __webpack_require__(105);
|
17064 |
|
17065 | var _require = __webpack_require__(106),
|
17066 | find = _require.find;
|
17067 |
|
17068 | module.exports = function () {
|
17069 | return {
|
17070 | inputExtensions: ['js', 'jsx'],
|
17071 | outputExtension: 'js',
|
17072 | typeGenerator: RelayFlowGenerator,
|
17073 | formatModule: formatGeneratedModule,
|
17074 | findGraphQLTags: find
|
17075 | };
|
17076 | };
|
17077 |
|
17078 | /***/ }),
|
17079 | /* 105 */
|
17080 | /***/ (function(module, exports, __webpack_require__) {
|
17081 |
|
17082 | "use strict";
|
17083 | /**
|
17084 | * Copyright (c) Facebook, Inc. and its affiliates.
|
17085 | *
|
17086 | * This source code is licensed under the MIT license found in the
|
17087 | * LICENSE file in the root directory of this source tree.
|
17088 | *
|
17089 | *
|
17090 | * @format
|
17091 | */
|
17092 |
|
17093 |
|
17094 | var formatGeneratedModule = function formatGeneratedModule(_ref) {
|
17095 | var moduleName = _ref.moduleName,
|
17096 | documentType = _ref.documentType,
|
17097 | docText = _ref.docText,
|
17098 | concreteText = _ref.concreteText,
|
17099 | typeText = _ref.typeText,
|
17100 | hash = _ref.hash,
|
17101 | sourceHash = _ref.sourceHash;
|
17102 | var documentTypeImport = documentType ? "import type { ".concat(documentType, " } from 'relay-runtime';") : '';
|
17103 | var docTextComment = docText ? '\n/*\n' + docText.trim() + '\n*/\n' : '';
|
17104 | var hashText = hash ? "\n * ".concat(hash) : '';
|
17105 | return "/**\n * ".concat('@', "flow", hashText, "\n */\n\n/* eslint-disable */\n\n'use strict';\n\n/*::\n").concat(documentTypeImport, "\n").concat(typeText || '', "\n*/\n\n").concat(docTextComment, "\nconst node/*: ").concat(documentType || 'empty', "*/ = ").concat(concreteText, ";\n// prettier-ignore\n(node/*: any*/).hash = '").concat(sourceHash, "';\nmodule.exports = node;\n");
|
17106 | };
|
17107 |
|
17108 | module.exports = formatGeneratedModule;
|
17109 |
|
17110 | /***/ }),
|
17111 | /* 106 */
|
17112 | /***/ (function(module, exports, __webpack_require__) {
|
17113 |
|
17114 | "use strict";
|
17115 | /**
|
17116 | * Copyright (c) Facebook, Inc. and its affiliates.
|
17117 | *
|
17118 | * This source code is licensed under the MIT license found in the
|
17119 | * LICENSE file in the root directory of this source tree.
|
17120 | *
|
17121 | *
|
17122 | * @format
|
17123 | */
|
17124 |
|
17125 |
|
17126 | var Profiler = __webpack_require__(6);
|
17127 |
|
17128 | var babylon = __webpack_require__(107);
|
17129 |
|
17130 | var util = __webpack_require__(47);
|
17131 |
|
17132 | // Attempt to be as inclusive as possible of source text.
|
17133 | var BABYLON_OPTIONS = {
|
17134 | allowImportExportEverywhere: true,
|
17135 | allowReturnOutsideFunction: true,
|
17136 | allowSuperOutsideMethod: true,
|
17137 | sourceType: 'module',
|
17138 | plugins: [// Previously "*"
|
17139 | 'asyncGenerators', 'classProperties', ['decorators', {
|
17140 | decoratorsBeforeExport: true
|
17141 | }], 'doExpressions', 'dynamicImport', 'exportExtensions', 'flow', 'functionBind', 'functionSent', 'jsx', 'nullishCoalescingOperator', 'objectRestSpread', 'optionalChaining', 'optionalCatchBinding'],
|
17142 | strictMode: false
|
17143 | };
|
17144 |
|
17145 | function find(text) {
|
17146 | var result = [];
|
17147 | var ast = babylon.parse(text, BABYLON_OPTIONS);
|
17148 | var visitors = {
|
17149 | CallExpression: function CallExpression(node) {
|
17150 | var callee = node.callee;
|
17151 |
|
17152 | if (!(callee.type === 'Identifier' && CREATE_CONTAINER_FUNCTIONS[callee.name] || callee.kind === 'MemberExpression' && callee.object.type === 'Identifier' && callee.object.value === 'Relay' && callee.property.type === 'Identifier' && CREATE_CONTAINER_FUNCTIONS[callee.property.name])) {
|
17153 | traverse(node, visitors);
|
17154 | return;
|
17155 | }
|
17156 |
|
17157 | var fragments = node.arguments[1];
|
17158 |
|
17159 | if (fragments.type === 'ObjectExpression') {
|
17160 | fragments.properties.forEach(function (property) {
|
17161 | !(property.type === 'ObjectProperty' && property.key.type === 'Identifier' && property.value.type === 'TaggedTemplateExpression') ? true ? invariant(false, 'FindGraphQLTags: `%s` expects fragment definitions to be ' + '`key: graphql`.', node.callee.name) : undefined : void 0;
|
17162 | !isGraphQLModernOrDeprecatedTag(property.value.tag) ? true ? invariant(false, 'FindGraphQLTags: `%s` expects fragment definitions to be tagged ' + 'with `graphql`, got `%s`.', node.callee.name, getSourceTextForLocation(text, property.value.tag.loc)) : undefined : void 0;
|
17163 |
|
17164 | if (isGraphQLTag(property.value.tag)) {
|
17165 | result.push({
|
17166 | keyName: property.key.name,
|
17167 | template: getGraphQLText(property.value.quasi),
|
17168 | sourceLocationOffset: getSourceLocationOffset(property.value.quasi)
|
17169 | });
|
17170 | }
|
17171 | });
|
17172 | } else {
|
17173 | !(fragments && fragments.type === 'TaggedTemplateExpression') ? true ? invariant(false, 'FindGraphQLTags: `%s` expects a second argument of fragment ' + 'definitions.', node.callee.name) : undefined : void 0;
|
17174 | !isGraphQLModernOrDeprecatedTag(fragments.tag) ? true ? invariant(false, 'FindGraphQLTags: `%s` expects fragment definitions to be tagged ' + 'with `graphql`, got `%s`.', node.callee.name, getSourceTextForLocation(text, fragments.tag.loc)) : undefined : void 0;
|
17175 | result.push({
|
17176 | keyName: null,
|
17177 | template: getGraphQLText(fragments.quasi),
|
17178 | sourceLocationOffset: getSourceLocationOffset(fragments.quasi)
|
17179 | });
|
17180 | } // Visit remaining arguments
|
17181 |
|
17182 |
|
17183 | for (var ii = 2; ii < node.arguments.length; ii++) {
|
17184 | visit(node.arguments[ii], visitors);
|
17185 | }
|
17186 | },
|
17187 | TaggedTemplateExpression: function TaggedTemplateExpression(node) {
|
17188 | if (isGraphQLTag(node.tag)) {
|
17189 | result.push({
|
17190 | keyName: null,
|
17191 | template: node.quasi.quasis[0].value.raw,
|
17192 | sourceLocationOffset: getSourceLocationOffset(node.quasi)
|
17193 | });
|
17194 | }
|
17195 | }
|
17196 | };
|
17197 | visit(ast, visitors);
|
17198 | return result;
|
17199 | }
|
17200 |
|
17201 | var CREATE_CONTAINER_FUNCTIONS = Object.create(null, {
|
17202 | createFragmentContainer: {
|
17203 | value: true
|
17204 | },
|
17205 | createPaginationContainer: {
|
17206 | value: true
|
17207 | },
|
17208 | createRefetchContainer: {
|
17209 | value: true
|
17210 | }
|
17211 | });
|
17212 | var IGNORED_KEYS = {
|
17213 | comments: true,
|
17214 | end: true,
|
17215 | leadingComments: true,
|
17216 | loc: true,
|
17217 | name: true,
|
17218 | start: true,
|
17219 | trailingComments: true,
|
17220 | type: true
|
17221 | };
|
17222 |
|
17223 | function isGraphQLTag(tag) {
|
17224 | return tag.type === 'Identifier' && tag.name === 'graphql';
|
17225 | }
|
17226 |
|
17227 | function isGraphQLModernOrDeprecatedTag(tag) {
|
17228 | return tag.type === 'Identifier' && (tag.name === 'graphql' || tag.name === 'graphql_DEPRECATED');
|
17229 | }
|
17230 |
|
17231 | function getTemplateNode(quasi) {
|
17232 | var quasis = quasi.quasis;
|
17233 | !(quasis && quasis.length === 1) ? true ? invariant(false, 'FindGraphQLTags: Substitutions are not allowed in graphql tags.') : undefined : void 0;
|
17234 | return quasis[0];
|
17235 | }
|
17236 |
|
17237 | function getGraphQLText(quasi) {
|
17238 | return getTemplateNode(quasi).value.raw;
|
17239 | }
|
17240 |
|
17241 | function getSourceLocationOffset(quasi) {
|
17242 | var loc = getTemplateNode(quasi).loc.start;
|
17243 | return {
|
17244 | line: loc.line,
|
17245 | column: loc.column + 1 // babylon is 0-indexed, graphql expects 1-indexed
|
17246 |
|
17247 | };
|
17248 | }
|
17249 |
|
17250 | function getSourceTextForLocation(text, loc) {
|
17251 | if (loc == null) {
|
17252 | return '(source unavailable)';
|
17253 | }
|
17254 |
|
17255 | var lines = text.split('\n').slice(loc.start.line - 1, loc.end.line);
|
17256 | lines[0] = lines[0].slice(loc.start.column);
|
17257 | lines[lines.length - 1] = lines[lines.length - 1].slice(0, loc.end.column);
|
17258 | return lines.join('\n');
|
17259 | }
|
17260 |
|
17261 | function invariant(condition, msg) {
|
17262 | if (!condition) {
|
17263 | for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
17264 | args[_key - 2] = arguments[_key];
|
17265 | }
|
17266 |
|
17267 | throw new Error(util.format.apply(util, [msg].concat(args)));
|
17268 | }
|
17269 | }
|
17270 |
|
17271 | function visit(node, visitors) {
|
17272 | var fn = visitors[node.type];
|
17273 |
|
17274 | if (fn != null) {
|
17275 | fn(node);
|
17276 | return;
|
17277 | }
|
17278 |
|
17279 | traverse(node, visitors);
|
17280 | }
|
17281 |
|
17282 | function traverse(node, visitors) {
|
17283 | for (var key in node) {
|
17284 | if (IGNORED_KEYS[key]) {
|
17285 | continue;
|
17286 | }
|
17287 |
|
17288 | var prop = node[key];
|
17289 |
|
17290 | if (prop && typeof prop === 'object' && typeof prop.type === 'string') {
|
17291 | visit(prop, visitors);
|
17292 | } else if (Array.isArray(prop)) {
|
17293 | prop.forEach(function (item) {
|
17294 | if (item && typeof item === 'object' && typeof item.type === 'string') {
|
17295 | visit(item, visitors);
|
17296 | }
|
17297 | });
|
17298 | }
|
17299 | }
|
17300 | }
|
17301 |
|
17302 | module.exports = {
|
17303 | find: Profiler.instrument(find, 'FindGraphQLTags.find')
|
17304 | };
|
17305 |
|
17306 | /***/ }),
|
17307 | /* 107 */
|
17308 | /***/ (function(module, exports) {
|
17309 |
|
17310 | module.exports = require("@babel/parser");
|
17311 |
|
17312 | /***/ }),
|
17313 | /* 108 */
|
17314 | /***/ (function(module, exports, __webpack_require__) {
|
17315 |
|
17316 | "use strict";
|
17317 | /**
|
17318 | * Copyright (c) Facebook, Inc. and its affiliates.
|
17319 | *
|
17320 | * This source code is licensed under the MIT license found in the
|
17321 | * LICENSE file in the root directory of this source tree.
|
17322 | *
|
17323 | *
|
17324 | * @format
|
17325 | */
|
17326 |
|
17327 |
|
17328 | var _interopRequireDefault = __webpack_require__(0);
|
17329 |
|
17330 | var _toConsumableArray2 = _interopRequireDefault(__webpack_require__(5));
|
17331 |
|
17332 | var ASTCache = __webpack_require__(26);
|
17333 |
|
17334 | var GraphQL = __webpack_require__(7);
|
17335 |
|
17336 | var Profiler = __webpack_require__(6);
|
17337 |
|
17338 | var fs = __webpack_require__(13);
|
17339 |
|
17340 | var invariant = __webpack_require__(4);
|
17341 |
|
17342 | var path = __webpack_require__(8);
|
17343 |
|
17344 | var _require = __webpack_require__(109),
|
17345 | memoizedFind = _require.memoizedFind;
|
17346 |
|
17347 | var parseGraphQL = Profiler.instrument(GraphQL.parse, 'GraphQL.parse');
|
17348 |
|
17349 | module.exports = function (tagFinder) {
|
17350 | var memoizedTagFinder = memoizedFind.bind(null, tagFinder);
|
17351 |
|
17352 | function parseFile(baseDir, file) {
|
17353 | var result = parseFileWithSources(baseDir, file);
|
17354 |
|
17355 | if (result) {
|
17356 | return result.document;
|
17357 | }
|
17358 | } // Throws an error if parsing the file fails
|
17359 |
|
17360 |
|
17361 | function parseFileWithSources(baseDir, file) {
|
17362 | var filePath = path.join(baseDir, file.relPath);
|
17363 | var text = '';
|
17364 |
|
17365 | try {
|
17366 | text = fs.readFileSync(filePath, 'utf8');
|
17367 | } catch (_unused) {
|
17368 | true ? true ? invariant(false, 'RelaySourceModuleParser: Files should be filtered before passed to the ' + 'parser, got unfiltered file `%s`.', file.relPath) : undefined : undefined;
|
17369 | }
|
17370 |
|
17371 | var astDefinitions = [];
|
17372 | var sources = [];
|
17373 | memoizedTagFinder(text, baseDir, file).forEach(function (template) {
|
17374 | var source = new GraphQL.Source(template, file.relPath);
|
17375 | var ast = parseGraphQL(source);
|
17376 | !ast.definitions.length ? true ? invariant(false, 'RelaySourceModuleParser: Expected GraphQL text to contain at least one ' + 'definition (fragment, mutation, query, subscription), got `%s`.', template) : undefined : void 0;
|
17377 | sources.push(source.body);
|
17378 | astDefinitions.push.apply(astDefinitions, (0, _toConsumableArray2["default"])(ast.definitions));
|
17379 | });
|
17380 | return {
|
17381 | document: {
|
17382 | kind: 'Document',
|
17383 | definitions: astDefinitions
|
17384 | },
|
17385 | sources: sources
|
17386 | };
|
17387 | }
|
17388 |
|
17389 | function getParser(baseDir) {
|
17390 | return new ASTCache({
|
17391 | baseDir: baseDir,
|
17392 | parse: parseFile
|
17393 | });
|
17394 | }
|
17395 |
|
17396 | function getFileFilter(baseDir) {
|
17397 | return function (file) {
|
17398 | var filePath = path.join(baseDir, file.relPath);
|
17399 | var text = '';
|
17400 |
|
17401 | try {
|
17402 | text = fs.readFileSync(filePath, 'utf8');
|
17403 | } catch (_unused2) {
|
17404 | // eslint-disable no-console
|
17405 | console.warn("RelaySourceModuleParser: Unable to read the file \"".concat(filePath, "\". Looks like it was removed."));
|
17406 | return false;
|
17407 | }
|
17408 |
|
17409 | return text.indexOf('graphql') >= 0;
|
17410 | };
|
17411 | }
|
17412 |
|
17413 | return {
|
17414 | getParser: getParser,
|
17415 | getFileFilter: getFileFilter,
|
17416 | parseFile: parseFile,
|
17417 | parseFileWithSources: parseFileWithSources
|
17418 | };
|
17419 | };
|
17420 |
|
17421 | /***/ }),
|
17422 | /* 109 */
|
17423 | /***/ (function(module, exports, __webpack_require__) {
|
17424 |
|
17425 | "use strict";
|
17426 | /**
|
17427 | * Copyright (c) Facebook, Inc. and its affiliates.
|
17428 | *
|
17429 | * This source code is licensed under the MIT license found in the
|
17430 | * LICENSE file in the root directory of this source tree.
|
17431 | *
|
17432 | *
|
17433 | * @format
|
17434 | */
|
17435 |
|
17436 |
|
17437 | var RelayCompilerCache = __webpack_require__(110);
|
17438 |
|
17439 | var getModuleName = __webpack_require__(112);
|
17440 |
|
17441 | var graphql = __webpack_require__(7);
|
17442 |
|
17443 | var path = __webpack_require__(8);
|
17444 |
|
17445 | var util = __webpack_require__(47);
|
17446 |
|
17447 | var cache = new RelayCompilerCache('RelayFindGraphQLTags', 'v1');
|
17448 |
|
17449 | function memoizedFind(tagFinder, text, baseDir, file) {
|
17450 | !file.exists ? true ? invariant(false, 'RelayFindGraphQLTags: Called with non-existent file `%s`', file.relPath) : undefined : void 0;
|
17451 | return cache.getOrCompute(file.hash, find.bind(null, tagFinder, text, path.join(baseDir, file.relPath)));
|
17452 | }
|
17453 |
|
17454 | function find(tagFinder, text, absPath) {
|
17455 | var tags = tagFinder(text, absPath);
|
17456 | var moduleName = getModuleName(absPath);
|
17457 | tags.forEach(function (tag) {
|
17458 | return validateTemplate(tag, moduleName, absPath);
|
17459 | });
|
17460 | return tags.map(function (tag) {
|
17461 | return tag.template;
|
17462 | });
|
17463 | }
|
17464 |
|
17465 | function validateTemplate(_ref, moduleName, filePath) {
|
17466 | var template = _ref.template,
|
17467 | keyName = _ref.keyName,
|
17468 | sourceLocationOffset = _ref.sourceLocationOffset;
|
17469 | var ast = graphql.parse(new graphql.Source(template, filePath, sourceLocationOffset));
|
17470 | ast.definitions.forEach(function (def) {
|
17471 | if (def.kind === 'OperationDefinition') {
|
17472 | !(def.name != null) ? true ? invariant(false, 'RelayFindGraphQLTags: In module `%s`, an operation requires a name.', moduleName, def.kind) : undefined : void 0;
|
17473 | var definitionName = def.name.value;
|
17474 | var operationNameParts = definitionName.match(/^(.*)(Mutation|Query|Subscription)$/);
|
17475 | !(operationNameParts && definitionName.startsWith(moduleName)) ? true ? invariant(false, 'RelayFindGraphQLTags: Operation names in graphql tags must be prefixed ' + 'with the module name and end in "Mutation", "Query", or ' + '"Subscription". Got `%s` in module `%s`.', definitionName, moduleName) : undefined : void 0;
|
17476 | } else if (def.kind === 'FragmentDefinition') {
|
17477 | var _definitionName = def.name.value;
|
17478 |
|
17479 | if (keyName != null) {
|
17480 | !(_definitionName === moduleName + '_' + keyName) ? true ? invariant(false, 'RelayFindGraphQLTags: Container fragment names must be ' + '`<ModuleName>_<propName>`. Got `%s`, expected `%s`.', _definitionName, moduleName + '_' + keyName) : undefined : void 0;
|
17481 | } else {
|
17482 | !_definitionName.startsWith(moduleName) ? true ? invariant(false, 'RelayFindGraphQLTags: Fragment names in graphql tags must be prefixed ' + 'with the module name. Got `%s` in module `%s`.', _definitionName, moduleName) : undefined : void 0;
|
17483 | }
|
17484 | }
|
17485 | });
|
17486 | } // TODO: Not sure why this is defined here rather than imported, is it so that it doesn’t get stripped in prod?
|
17487 |
|
17488 |
|
17489 | function invariant(condition, msg) {
|
17490 | if (!condition) {
|
17491 | for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
17492 | args[_key - 2] = arguments[_key];
|
17493 | }
|
17494 |
|
17495 | throw new Error(util.format.apply(util, [msg].concat(args)));
|
17496 | }
|
17497 | }
|
17498 |
|
17499 | module.exports = {
|
17500 | find: find,
|
17501 | // Exported for testing only.
|
17502 | memoizedFind: memoizedFind
|
17503 | };
|
17504 |
|
17505 | /***/ }),
|
17506 | /* 110 */
|
17507 | /***/ (function(module, exports, __webpack_require__) {
|
17508 |
|
17509 | "use strict";
|
17510 | /**
|
17511 | * Copyright (c) Facebook, Inc. and its affiliates.
|
17512 | *
|
17513 | * This source code is licensed under the MIT license found in the
|
17514 | * LICENSE file in the root directory of this source tree.
|
17515 | *
|
17516 | *
|
17517 | * @format
|
17518 | */
|
17519 |
|
17520 |
|
17521 | var _interopRequireDefault = __webpack_require__(0);
|
17522 |
|
17523 | var _defineProperty2 = _interopRequireDefault(__webpack_require__(23));
|
17524 |
|
17525 | var Profiler = __webpack_require__(6);
|
17526 |
|
17527 | var crypto = __webpack_require__(12);
|
17528 |
|
17529 | var fs = __webpack_require__(13);
|
17530 |
|
17531 | var os = __webpack_require__(111);
|
17532 |
|
17533 | var path = __webpack_require__(8);
|
17534 | /**
|
17535 | * A file backed cache. Values are JSON encoded on disk, so only JSON
|
17536 | * serializable values should be used.
|
17537 | */
|
17538 |
|
17539 |
|
17540 | var RelayCompilerCache =
|
17541 | /*#__PURE__*/
|
17542 | function () {
|
17543 | /**
|
17544 | * @param name Human readable identifier for the cache
|
17545 | * @param cacheBreaker This should be changed in order to invalidate existing
|
17546 | * caches.
|
17547 | */
|
17548 | function RelayCompilerCache(name, cacheBreaker) {
|
17549 | (0, _defineProperty2["default"])(this, "_dir", null);
|
17550 | this._name = name;
|
17551 | this._cacheBreaker = cacheBreaker;
|
17552 | }
|
17553 |
|
17554 | var _proto = RelayCompilerCache.prototype;
|
17555 |
|
17556 | _proto._getFile = function _getFile(key) {
|
17557 | if (this._dir == null) {
|
17558 | // Include username in the cache dir to avoid issues with directories being
|
17559 | // owned by a different user.
|
17560 | var username = os.userInfo().username;
|
17561 | var cacheID = crypto.createHash('md5').update(this._cacheBreaker).update(username).digest('hex');
|
17562 | var dir = path.join(os.tmpdir(), "".concat(this._name, "-").concat(cacheID));
|
17563 |
|
17564 | if (!fs.existsSync(dir)) {
|
17565 | try {
|
17566 | fs.mkdirSync(dir);
|
17567 | } catch (error) {
|
17568 | if (error.code !== 'EEXIST') {
|
17569 | throw error;
|
17570 | }
|
17571 | }
|
17572 | }
|
17573 |
|
17574 | this._dir = dir;
|
17575 | }
|
17576 |
|
17577 | return path.join(this._dir, key);
|
17578 | };
|
17579 |
|
17580 | _proto.getOrCompute = function getOrCompute(key, compute) {
|
17581 | var _this = this;
|
17582 |
|
17583 | return Profiler.run('RelayCompilerCache.getOrCompute', function () {
|
17584 | var cacheFile = _this._getFile(key);
|
17585 |
|
17586 | if (fs.existsSync(cacheFile)) {
|
17587 | try {
|
17588 | return JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
|
17589 | } catch (_unused) {// ignore
|
17590 | }
|
17591 | }
|
17592 |
|
17593 | var value = compute();
|
17594 |
|
17595 | try {
|
17596 | // $FlowFixMe(>=0.95.0) JSON.stringify can return undefined
|
17597 | fs.writeFileSync(cacheFile, JSON.stringify(value), 'utf8');
|
17598 | } catch (_unused2) {// ignore
|
17599 | }
|
17600 |
|
17601 | return value;
|
17602 | });
|
17603 | };
|
17604 |
|
17605 | return RelayCompilerCache;
|
17606 | }();
|
17607 |
|
17608 | module.exports = RelayCompilerCache;
|
17609 |
|
17610 | /***/ }),
|
17611 | /* 111 */
|
17612 | /***/ (function(module, exports) {
|
17613 |
|
17614 | module.exports = require("os");
|
17615 |
|
17616 | /***/ }),
|
17617 | /* 112 */
|
17618 | /***/ (function(module, exports, __webpack_require__) {
|
17619 |
|
17620 | "use strict";
|
17621 | /**
|
17622 | * Copyright (c) Facebook, Inc. and its affiliates.
|
17623 | *
|
17624 | * This source code is licensed under the MIT license found in the
|
17625 | * LICENSE file in the root directory of this source tree.
|
17626 | *
|
17627 | *
|
17628 | * @format
|
17629 | */
|
17630 |
|
17631 |
|
17632 | var path = __webpack_require__(8);
|
17633 |
|
17634 | function getModuleName(filePath) {
|
17635 | // index.js -> index
|
17636 | // index.js.flow -> index.js
|
17637 | var filename = path.basename(filePath, path.extname(filePath)); // index.js -> index (when extension has multiple segments)
|
17638 |
|
17639 | filename = filename.replace(/(?:\.\w+)+/, ''); // /path/to/button/index.js -> button
|
17640 |
|
17641 | var moduleName = filename === 'index' ? path.basename(path.dirname(filePath)) : filename; // Example.ios -> Example
|
17642 | // Example.product.android -> Example
|
17643 |
|
17644 | moduleName = moduleName.replace(/(?:\.\w+)+/, ''); // foo-bar -> fooBar
|
17645 | // Relay compatibility mode splits on _, so we can't use that here.
|
17646 |
|
17647 | moduleName = moduleName.replace(/[^a-zA-Z0-9]+(\w?)/g, function (match, next) {
|
17648 | return next.toUpperCase();
|
17649 | });
|
17650 | return moduleName;
|
17651 | }
|
17652 |
|
17653 | module.exports = getModuleName;
|
17654 |
|
17655 | /***/ }),
|
17656 | /* 113 */
|
17657 | /***/ (function(module, exports) {
|
17658 |
|
17659 | module.exports = require("fast-glob");
|
17660 |
|
17661 | /***/ })
|
17662 | /******/ ]); |
\ | No newline at end of file |