There's a way to pass a filter option to Mongo via GraphQL? because I tried this way but I had an error "message": "Parameter \\"filter\\" to find() must be an object, got {email: \\"test@test.com\\"}",
This is my query type
users: {
type: new GraphQLList(UserType),
args: {
filter: { type: GraphQLString }
},
resolve(_, { filter }, { req, res }) {
// I tried several ways to get query string and give it to mongo into a object
JSONFilter = JSON.parse(JSON.stringify(filter));
return UserSchema.find(JSONFilter);
}
}
and my query looks like this
query myReferrals {
users(filter: "{email: \"test@test.com\"}"){ //I though this should be enough, but no!
referrals{
user{
email
}
}
}
}
It was a "typo", on my query should be this way:
query myReferrals {
users(filter: "{\"email\": \"test@test.com\"}"){ // Just Add `\"key\"` to key
referrals{
user{
email
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.