graphql-compose-mongoose icon indicating copy to clipboard operation
graphql-compose-mongoose copied to clipboard

Unable to use _operator while filtering a connection

Open ziedHamdi opened this issue 3 years ago • 1 comments

Hello,

I'm trying to use the _operators feature for filtering, but I can't get it to work: This is my package.json section:

{
    "graphql": "^14.0.2",
    "graphql-compose": "^9.0.7",
    "graphql-compose-connection": "^8.2.1",
    "graphql-compose-mongoose": "^9.7.1",
}

My query looks like this: trendingComplaintConnection:complaintConnection(after:$after, filter: { viewer: "TRENDING", kind: $kind, category: $categoryName, _operators: {user: {exists: true}} }, first: 6, sort:POPULARITY_DESC) {/*...*/}

I get the error: graphQl error : Field "exists" is not defined by type FilterFindManyComplaintUserOperatorsInput.

It is very hard for me to google this issue as the error message is specific to my case, there's no generic message coming from the graphql-compose-mongoose lib that I could google. So I've read the docs and can't help further

Here's my connection and findMany resolver definition:

const complaintFindMany = ComplaintTC.mongooseResolvers.findMany({
    filter: {
        // enables operators for fields
        operators: {
            user:true
        },
    }
});
const complaintCountResolver = ComplaintTC.mongooseResolvers.count();
let complaintConnection = ComplaintTC.mongooseResolvers.connection({
    filter: {
        // enables operators for fields
        operators: {
            user: true
        },
    },
    sort: {
        POPULARITY_DESC: {
            value: {popularity: -1},
            cursorFields: ['popularity'],
            beforeCursorQuery: (rawQuery, cursorData, resolveParams) => {
                if (!rawQuery.popularity) rawQuery.popularity = {};
                rawQuery.popularity.$gt = cursorData.popularity;
            },
            afterCursorQuery: (rawQuery, cursorData, resolveParams) => {
                if (!rawQuery.popularity) rawQuery.popularity = {};
                rawQuery.popularity.$lt = cursorData.popularity;
            },
        },
    }
});

Finally, my mongoose object has nothing special

const ComplaintSchema = new Schema({
	entityGroupId: {type: String},
	entityId: {type: String},
	user: {
		type: UserInfoSchema,
		required: false,
	},
//...
})

ziedHamdi avatar Jul 29 '22 07:07 ziedHamdi

Ok,

So I was able to get it working by changing my query to: _operators: {user: {userId: {exists: true}}}

I'm not closing this issue, as I think we should be able to test if the complex field user exists at all

ziedHamdi avatar Aug 03 '22 09:08 ziedHamdi