Skip to content

Custom filters breaks mongo queries with 9.0.1 #315

@fklingler

Description

@fklingler

Hello, I encountered a bug with the newer versions of graphql-compose-mongoose.

I have this custom filter added to my findMany resolver:

    .addFilterArg({
        name: 'from',
        type: GraphQLDate,
        description: 'Appointment date should be after the provided date.',
        query: (rawQuery: any, value: Date) => {
            rawQuery.date = {
                $gte: value,
                ...(rawQuery.date && typeof(rawQuery.date) != 'object'
                    ? { $eq: rawQuery.date }
                    : (rawQuery.date ?? {}))
            };
        }
    })

When using this filter, the mongo query should be like this (and was like this up to 9.0.0):

appointments.find({ date: { '$gte': new Date("Fri, 01 Jan 2021 23:00:00 GMT") }}, { limit: 100, projection: { _id: true, name: true }})

Now it is like this:

appointments.find({ from: new Date("Fri, 01 Jan 2021 23:00:00 GMT"), date: { '$gte': new Date("Fri, 01 Jan 2021 23:00:00 GMT") }}, { limit: 100, projection: { _id: true, name: true }})

Note the added from field in the find query, that makes it return no document.

This bug has been introduced in 9.0.1, the faulty commit is probably this one 313ea1f

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions