deno.land / x / obsidian@v8.0.0 / src / mapSelections.js
12345678910111213141516171819202122232425262728293031323334/** @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;}
Version Info