UNPKG

1.77 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 *
8 * @format
9 */
10// flowlint ambiguous-object-type:error
11'use strict';
12
13var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
14
15var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
17var _require = require('relay-runtime'),
18 getSelector = _require.getSelector;
19
20function getRootVariablesForFragments(fragments, props) {
21 var rootVariables = {}; // NOTE: For extra safety, we make sure the rootVariables include the
22 // variables from all owners in this fragmentSpec, even though they
23 // should all point to the same owner
24
25 Object.keys(fragments).forEach(function (key) {
26 var _selector$selectors$, _selector$selectors$2, _selector$owner$varia;
27
28 var fragmentNode = fragments[key];
29 var fragmentRef = props[key];
30 var selector = getSelector(fragmentNode, fragmentRef);
31 var fragmentOwnerVariables = selector != null && selector.kind === 'PluralReaderSelector' ? (_selector$selectors$ = (_selector$selectors$2 = selector.selectors[0]) === null || _selector$selectors$2 === void 0 ? void 0 : _selector$selectors$2.owner.variables) !== null && _selector$selectors$ !== void 0 ? _selector$selectors$ : {} : (_selector$owner$varia = selector === null || selector === void 0 ? void 0 : selector.owner.variables) !== null && _selector$owner$varia !== void 0 ? _selector$owner$varia : {};
32 rootVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, rootVariables), fragmentOwnerVariables);
33 });
34 return rootVariables;
35}
36
37module.exports = getRootVariablesForFragments;
\No newline at end of file