Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use _operator while filtering a connection #412

Open
ziedHamdi opened this issue Jul 29, 2022 · 1 comment
Open

Unable to use _operator while filtering a connection #412

ziedHamdi opened this issue Jul 29, 2022 · 1 comment

Comments

@ziedHamdi
Copy link

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
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant