UNPKG

1.59 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 * strict-local
8 * @format
9 */
10'use strict';
11
12/**
13 * Helpers to retieve the name of the document from which the input derives:
14 * this is either the name of the input itself (if it is not a derived node)
15 * or the metadata.derivedFrom property for derived nodes.
16 */
17// Version for generated nodes
18function getReaderSourceDefinitionName(node) {
19 var _node$params$metadata, _node$metadata;
20
21 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],
22 name = _ref[0],
23 derivedFrom = _ref[1];
24
25 return typeof derivedFrom === 'string' ? derivedFrom : name;
26} // Version for IR
27
28
29function getSourceDefinitionName(node) {
30 var _node$metadata2;
31
32 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;
33 return typeof derivedFrom === 'string' ? derivedFrom : node.name;
34}
35
36module.exports = {
37 getReaderSourceDefinitionName: getReaderSourceDefinitionName,
38 getSourceDefinitionName: getSourceDefinitionName
39};
\No newline at end of file