Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function graphQlQueryToMongoJoinQuery(query) {
const _query = {
...query.where,
...mapKeyNames(
// Grab all the modifiers
pick(query, ['search', 'orderBy', 'skip', 'first']),
// and prefix with a dollar symbol so they can be picked out by the
// query builder tokeniser
key => `$${key}`
),
};
return mapKeys(_query, field => {
if (getType(field) !== 'Object' || !field.where) {
return field;
}
// recurse on object (ie; relationship) types
return graphQlQueryToMongoJoinQuery(field);
});