1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.pathsFromSelectionSet = void 0;
|
4 | const graphql_1 = require("graphql");
|
5 | function pathsFromSelectionSet(selectionSet, path = []) {
|
6 | var _a;
|
7 | const paths = [];
|
8 | for (const selection of selectionSet.selections) {
|
9 | const additions = (_a = pathsFromSelection(selection, path)) !== null && _a !== void 0 ? _a : [];
|
10 | for (const addition of additions) {
|
11 | paths.push(addition);
|
12 | }
|
13 | }
|
14 | return paths;
|
15 | }
|
16 | exports.pathsFromSelectionSet = pathsFromSelectionSet;
|
17 | function pathsFromSelection(selection, path) {
|
18 | var _a, _b;
|
19 | if (selection.kind === graphql_1.Kind.FIELD) {
|
20 | const responseKey = (_b = (_a = selection.alias) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : selection.name.value;
|
21 | if (selection.selectionSet) {
|
22 | return pathsFromSelectionSet(selection.selectionSet, path.concat([responseKey]));
|
23 | }
|
24 | else {
|
25 | return [path.concat([responseKey])];
|
26 | }
|
27 | }
|
28 | else if (selection.kind === graphql_1.Kind.INLINE_FRAGMENT) {
|
29 | return pathsFromSelectionSet(selection.selectionSet, path);
|
30 | }
|
31 | }
|