@graphql-mesh/serve-runtime
Version: 
32 lines (31 loc) • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkIfDataSatisfiesSelectionSet = checkIfDataSatisfiesSelectionSet;
function checkIfDataSatisfiesSelectionSet(selectionSet, data) {
    if (Array.isArray(data)) {
        return data.every(item => checkIfDataSatisfiesSelectionSet(selectionSet, item));
    }
    for (const selection of selectionSet.selections) {
        if (selection.kind === 'Field') {
            const field = selection;
            const responseKey = field.alias?.value || field.name.value;
            if (data[responseKey] != null) {
                if (field.selectionSet) {
                    if (!checkIfDataSatisfiesSelectionSet(field.selectionSet, data[field.name.value])) {
                        return false;
                    }
                }
            }
            else {
                return false;
            }
        }
        else if (selection.kind === 'InlineFragment') {
            const inlineFragment = selection;
            if (!checkIfDataSatisfiesSelectionSet(inlineFragment.selectionSet, data)) {
                return false;
            }
        }
    }
    return true;
}