Skip to content

Unable to use _operator while filtering a connection  #412

Open
@ziedHamdi

Description

@ziedHamdi

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,
	},
//...
})

Activity

ziedHamdi

ziedHamdi commented on Aug 3, 2022

@ziedHamdi
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ziedHamdi

        Issue actions

          Unable to use _operator while filtering a connection · Issue #412 · graphql-compose/graphql-compose-mongoose