UNPKG

2.15 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'use strict';
11
12/**
13 * Generates an identifier that is unique to a given selection: the alias for
14 * fields, the type for inline fragments, and a summary of the condition
15 * variable and passing value for conditions.
16 */
17function getIdentifierForSelection(node) {
18 if (node.kind === 'LinkedField' || node.kind === 'ScalarField') {
19 return node.directives.length === 0 ? node.alias || node.name : (node.alias || node.name) + require("./GraphQLIRPrinter").printDirectives(node.directives);
20 } else if (node.kind === 'FragmentSpread') {
21 return node.args.length === 0 ? '...' + node.name : '...' + node.name + require("./GraphQLIRPrinter").printArguments(node.args);
22 } else if (node.kind === 'MatchField') {
23 var _node$metadata;
24
25 var storageKey = (_node$metadata = node.metadata) === null || _node$metadata === void 0 ? void 0 : _node$metadata.storageKey;
26 !(typeof storageKey === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'getIdentifierForSelection: Expected MatchField `%s` to have a precomputed storageKey.', node.name) : require("fbjs/lib/invariant")(false) : void 0;
27 return 'M:' + storageKey;
28 } else if (node.kind === 'MatchBranch') {
29 return 'B:' + node.name + '$' + node.module;
30 } else if (node.kind === 'Defer') {
31 return 'D:' + node.label;
32 } else if (node.kind === 'Stream') {
33 return 'S:' + node.label;
34 } else if (node.kind === 'InlineFragment') {
35 return 'I:' + node.typeCondition.name;
36 } else if (node.kind === 'Condition') {
37 return 'C:' + (node.condition.kind === 'Variable' ? '$' + node.condition.variableName : String(node.condition.value)) + String(node.passingValue);
38 } else {
39 !false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'getIdentifierForSelection: Unexpected kind `%s`.', node.kind) : require("fbjs/lib/invariant")(false) : void 0;
40 }
41}
42
43module.exports = getIdentifierForSelection;
\No newline at end of file