@@ -122,11 +122,9 @@ export async function generateTemplate(templateQueryToExecute, templateObject, u
|
|||||||
// Parse the query and apply the filters and sorters
|
// Parse the query and apply the filters and sorters
|
||||||
const ast = parseQuery(templateQueryToExecute);
|
const ast = parseQuery(templateQueryToExecute);
|
||||||
|
|
||||||
let filterFields = [];
|
|
||||||
|
|
||||||
if (templateObject?.filters && templateObject?.filters?.length) {
|
if (templateObject?.filters && templateObject?.filters?.length) {
|
||||||
applyFilters(ast, templateObject.filters, filterFields);
|
applyFilters(ast, templateObject.filters);
|
||||||
wrapFiltersInAnd(ast, filterFields);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (templateObject?.sorters && templateObject?.sorters?.length) {
|
if (templateObject?.sorters && templateObject?.sorters?.length) {
|
||||||
@@ -412,31 +410,4 @@ function getGraphQLKind(value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrap filters in an 'and' object
|
|
||||||
* @param ast
|
|
||||||
* @param filterFields
|
|
||||||
*/
|
|
||||||
export function wrapFiltersInAnd(ast, filterFields) {
|
|
||||||
visit(ast, {
|
|
||||||
OperationDefinition: {
|
|
||||||
enter(node) {
|
|
||||||
node.selectionSet.selections.forEach((selection) => {
|
|
||||||
let whereArg = selection.arguments.find(arg => arg.name.value === 'where');
|
|
||||||
if (filterFields.length > 1) {
|
|
||||||
const andFilter = {
|
|
||||||
kind: Kind.OBJECT_FIELD,
|
|
||||||
name: {kind: Kind.NAME, value: '_and'},
|
|
||||||
value: {kind: Kind.LIST, values: filterFields}
|
|
||||||
};
|
|
||||||
whereArg.value.fields.push(andFilter);
|
|
||||||
} else if (filterFields.length === 1) {
|
|
||||||
whereArg.value.fields.push(filterFields[0].fields[0]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/* eslint-enable no-loop-func */
|
/* eslint-enable no-loop-func */
|
||||||
|
|||||||
Reference in New Issue
Block a user