Is there a way to pass a filter option to MongoDB using GraphQL? I attempted to do it in a certain way, but encountered an error that stated:
"message": "Parameter \"filter\" to find() must be an object, got {email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93e7f6e0e7d3e7f6e0e7bdf0fcfe">[email protected]</a>"}",
Here is my query type:
users: {
type: new GraphQLList(UserType),
args: {
filter: { type: GraphQLString }
},
resolve(_, { filter }, { req, res }) {
// I have tried multiple methods to extract the query string and convert it into an object for MongoDB
JSONFilter = JSON.parse(JSON.stringify(filter));
return UserSchema.find(JSONFilter);
}
}
Below is how my query is structured:
query myReferrals {
users(filter: "{email: \"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f4b5a4c4b7f4b5a4c4b115c5052">[email protected]</a>\"}"){ //I thought this should suffice, but it did not!
referrals{
user{
email
}
}
}
}