UNPKG

simple-graphql

Version:

The simple way to generates GraphQL schemas and Sequelize models from your models definition.

27 lines 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function parseSelections(fragments, selections, base) { const result = []; if (selections) { selections.forEach((selection) => { if (selection.kind === 'Field') { const selectionSet = selection.selectionSet; result.push(Object.assign(Object.assign({}, (base || {})), { name: selection.name.value, selections: selectionSet && parseSelections(fragments, selectionSet.selections) })); } else if (selection.kind === 'FragmentSpread') { const fragment = fragments[selection.name.value]; parseSelections(fragments, fragment.selectionSet && fragment.selectionSet.selections).forEach((r) => result.push(r)); } else if (selection.kind === 'InlineFragment') { if (selection.typeCondition && selection.typeCondition.kind === 'NamedType') { const namedType = selection.typeCondition.name.value; parseSelections(fragments, selection.selectionSet && selection.selectionSet.selections, { namedType: namedType }).forEach((r) => result.push(r)); } } }); } return result; } exports.default = parseSelections; //# sourceMappingURL=parseSelections.js.map