-
Notifications
You must be signed in to change notification settings - Fork 641
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
Unexpected behaviour when using GraphQL relatedTo vs relatedToCategories #7954
Comments
That’s actually working as expected. That query is generating the GraphQL equivalant of this element query in Twig: {% set entries = craft.entries()
.relatedTo(craft.categories().id(null))
.all() %} Keep in mind that element queries’ What you’re really asking for is a way to make the entire |
@brandonkelly sorry for commenting on this super old issue but has anything in this area of Craft been updated to allow for this? Just from a "keeping codebase tidy" point of view having to conditional send queries is not nice. It would be awesome if somehow you could just do the following and by doing so the filter is just skipped. No filter.... newsPostEntries(status: "live", relatedToCategories: null, limit: $limit, offset: $offset) { ... Filter... newsPostEntries(status: "live", relatedToCategories: {slug: "my-category-slug"}, limit: $limit, offset: $offset) { ... |
@mediabeastnz That’s a little different from the OP, where only the I just added support for setting the entire |
Craft 4.5.0 is out with that change. |
Description
I am trying to filter a GraphQL entries query using
relatedToCategories
andrelatedToTags
. If I set the variable to null for these parameters, results are only returned if entries contain any data at all for the category and tag fields.For clarity:
With
$category
set to null, the following query returns eight results, which is the total number available:This seems correct to me, as I'm effectively saying, "don't match against any category in this case, show everything"
However, changing the query to the following produces only 7 results - the missing entry has no category selected:
Why don't these produce the same results?
Is there a way to pass
null
and return all results when usingrelatedToCategories
andrelatedToTags
?Additional info
The text was updated successfully, but these errors were encountered: