Skip to content

Instantly share code, notes, and snippets.

@josmanperez
Created April 23, 2021 17:00
Show Gist options
  • Save josmanperez/c59fb498e42d33d1ee038901d5e62968 to your computer and use it in GitHub Desktop.
Save josmanperez/c59fb498e42d33d1ee038901d5e62968 to your computer and use it in GitHub Desktop.
GraphQL Custom Resolver linked function with parameters
exports = async function({imdbRating, genres, rated, languages}) {
const request = context.services.get('mongodb-atlas').db('sample_mflix').collection('movies');
const lang = languages === undefined ? ["English", "Japanese"] : languages;
const pipeline = [
{
$match: {
"imdb.rating": { "$gte": imdbRating },
"genres": { "$nin": genres } ,
"rated": { "$in": rated },
"languages": { "$all": lang }
}
}];
return await request.aggregate(pipeline).toArray()
.then(data => {
console.log(data.length);
return data;
})
.catch(err => {
console.log(err.toString());
return err.toString();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment