Nested filter always returns all entries
I try to filter by a nested field of type boolean. Autosuggestion works fine, but the filter does nothing. All records where shown in the results.
{
pages(filter:{response:{hasErrors:true}}) {
projectID
url
session
response {
hasErrors
status
headers
}
}
}
schemaComposer looks like that:
schemaComposer.Query.addFields({
pages: PagesTC.mongooseResolvers.findMany(),
page: PagesTC.mongooseResolvers.findOne(),
})
const graphqlSchema = schemaComposer.buildSchema()
export default graphqlSchema
I was banging my head against nested operators last night before realizing this morning that it's really a nested filter issue. FWIW, it appears that filters on nested objects within arrays work. Any luck digging around to see where the issue might be?
After digging around in the code, I discovered that nested filters (and thus nested operators) work if you use subdocuments versus nested paths (https://mongoosejs.com/docs/subdocs.html#subdocuments-versus-nested-paths). I was looking at https://github.com/graphql-compose/graphql-compose-mongoose/blob/master/src/resolvers/helpers/filter.ts#L147 and discovered that:
- subdocuments leave their parent field names in
modelFields(e.g.pages) and fall into that else case - nested paths leave their dot-qualified names in
modelField(e.g.pages.projectID) and fall out of all the cases
Hope this helps!
I likewise spent quite some time smashing my head into my keyboard working out this exact issue.
Turns out after also sleuthing through the repo, it looks like this issue has been fixed. Updating to 9.2.2 solved the problem for me.
Seems to be a duplicate of #304 which was then tweaked for #315
Should be good to close?