Created
April 23, 2021 17:00
-
-
Save josmanperez/c59fb498e42d33d1ee038901d5e62968 to your computer and use it in GitHub Desktop.
GraphQL Custom Resolver linked function with parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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