deno.land / x / obsidian@v8.0.0 / src / mapSelections.js

mapSelections.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/** @format */
import { gql } from 'https://deno.land/x/oak_graphql/mod.ts';
export function mapSelectionSet(query) { // Gets fields from query and stores all in an array - used to selectively query cache const selectionKeysMap = {}; const ast = gql(query); const selections = ast.definitions[0].selectionSet.selections; const tableName = selections[0].name.value;
const recursiveMap = (recurseSelections) => { for (const selection of recurseSelections) { if (selection.name && selection.name.value) { selectionKeysMap[selection.name.value] = selection.name.value; } if (selection.alias && selection.alias.value) { selectionKeysMap[selection.alias.value] = selection.name.value; }
if (selection.selectionSet && selection.selectionSet.selections) { recursiveMap(selection.selectionSet.selections); } } }; recursiveMap(selections);
// filter out table name from array, leaving only fields const selectedFields = Object.keys(selectionKeysMap).filter( (key) => key !== tableName ); return selectedFields;}
obsidian

Version Info

Tagged at
a year ago