graphql-compose / graphql-compose-mongoose

Mongoose model converter to GraphQL types with resolvers for graphql-compose https://github.com/nodkz/graphql-compose
MIT License
708 stars 94 forks source link

Having trouble enabling operators #385

Closed halindraprakoso closed 2 years ago

halindraprakoso commented 3 years ago

Hello, I have been using this great plugin for a while but I'm having a minor hiccup in enabling the operators. I would like to enable the in operator for this particular resolver:

locationSortedUniqueAddress: LocationTC.mongooseResolvers
        .findMany({ lean: true, filter: { operators: true } })
        .addFilterArg({
            name: "geoDistance",
            type: `input GeoDistance {
              lng: Float!
              lat: Float!
            }`,
            description: "Search by distance in meters",
            query: (rawQuery, value) => {

                rawQuery["location"] = {
                    $near: {
                        $geometry: {
                            type: "Point",
                            coordinates: [value.lng, value.lat],
                        },
                        // $maxDistance: value.distance, // <distance in meters>
                    },
                };
            },
        })
        .wrapResolve((next) => (rp) => {
            const resultPromise = next(rp);

            return resultPromise.then((payload) => {
                let filtered = payload.filter((e, i) => {
                    return (
                        payload.findIndex((x) => {
                            return x.userid.toString() == e.userid.toString();
                        }) == i
                    );
                });
                return filtered;
            });
        }),

The problem is that I still can only see _id in _operators, other fields are not showing. I tried to manually create the in operator using another addFilterArgs, but it doesn't work with AND and OR