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

GraphQL filter not working as intended #10290

Open
JelmerOT opened this issue Jun 13, 2024 · 3 comments
Open

GraphQL filter not working as intended #10290

JelmerOT opened this issue Jun 13, 2024 · 3 comments
Labels

Comments

@JelmerOT
Copy link

Bug description

I made a query to fetch articles based on the ID of the taxonomy.

query MyQuery {
  entries(
    collection: "articles"
    site: "nl_nl"
    filter: {
      article_categories: {
        id: { is: "article_categories::slapen" }
      }
    }
  ) {
    from
    to
    data {
      id
      url
      date
      title
      status
      permalink
      ... on Entry_Articles_Article {
        id
        article_categories {
          id
          title
          url
          slug
          uri
        }
      }
    }
  }
}

This is what it returns:

{
  "data": {
    "entries": {
      "from": 1,
      "to": 2,
      "data": [
        {
          "id": "25c76288-e56f-4a08-9265-588012db56b3",
          "url": "/blog/het-slopende-effect-van-insomnia-hoe-het-uw-dagelijks-leven-beinvloedt",
          "date": "2024-06-11 00:00:00",
          "title": "Het slopende effect van insomnia: hoe het uw dagelijks leven beïnvloedt",
          "status": "published",
          "permalink": "http://localhost:3000/blog/het-slopende-effect-van-insomnia-hoe-het-uw-dagelijks-leven-beinvloedt",
          "article_categories": [
            {
              "id": "article_categories::slapen",
              "title": "Slapen",
              "url": "/blog/article-categories/slapen",
              "slug": "slapen",
              "uri": "/blog/article-categories/slapen"
            },
            {
              "id": "article_categories::droomsap",
              "title": "Droomsap",
              "url": "/blog/article-categories/droomsap",
              "slug": "droomsap",
              "uri": "/blog/article-categories/droomsap"
            },
            {
              "id": "article_categories::onderzoek",
              "title": "Onderzoek",
              "url": "/blog/article-categories/onderzoek",
              "slug": "onderzoek",
              "uri": "/blog/article-categories/onderzoek"
            }
          ]
        },
        {
          "id": "35b520ab-e84e-47d5-99e5-c957a23d20b3",
          "url": "/blog/het-slopende-effect-van-insomnia",
          "date": "2024-06-11 00:00:00",
          "title": "Het slopende effect van insomnia",
          "status": "published",
          "permalink": "http://localhost:3000/blog/het-slopende-effect-van-insomnia",
          "article_categories": [
            {
              "id": "article_categories::droomsap",
              "title": "Droomsap",
              "url": "/blog/article-categories/droomsap",
              "slug": "droomsap",
              "uri": "/blog/article-categories/droomsap"
            },
            {
              "id": "article_categories::onderzoek",
              "title": "Onderzoek",
              "url": "/blog/article-categories/onderzoek",
              "slug": "onderzoek",
              "uri": "/blog/article-categories/onderzoek"
            }
          ]
        }
      ]
    }
  }
}

You can see that the second article does not contain a taxonomy with an id of article_categories::slapen.

How to reproduce

Create a new statamic project. Create an articles collection and article_categories taxonomy. Connect these two.

Then query the articles with a filter.

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 11.10.0
PHP Version: 8.3.6
Composer Version: 2.6.5
Environment: local
Debug Mode: ENABLED
URL: api.dromenwinkel.com.test
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Sentry
Enabled: MISSING DSN
Environment: local
Laravel SDK Version: 4.6.0
PHP SDK Version: 4.8.0
Release: NOT SET
Sample Rate Errors: 100%
Sample Rate Performance Monitoring: NOT SET
Sample Rate Profiling: NOT SET
Send Default PII: DISABLED

Statamic
Addons: 7
Sites: 3 (Nederlands, English, Canada)
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.7.2 PRO

Statamic Addons
aryehraber/statamic-logbook: 3.3.0
orangetalent/statamic-graphql-breadcrumbs: dev-main
orangetalent/statamic-graphql-lang: dev-main
ryanmitchell/statamic-translation-manager: 2.0.0
studio1902/statamic-peak-seo: 8.14.0
studio1902/statamic-peak-tools: 6.1.0
webographen/statamic-admin-log: 1.1.0

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@duncanmcclean
Copy link
Member

duncanmcclean commented Jun 19, 2024

You can filter entries by taxonomies like this:

query MyQuery {
  entries(
    collection: "articles"
    filter: {article_categories: {contains: "slapen"}}
  ) {
    data {
      id
      title
    }
  }
}

@JelmerOT
Copy link
Author

That works, but not with another category with a similar name. Seems that contains just looks if the word exists somewhere.

And I can't do something like this, because I get an error:

filter: {
  article_categories: {
    is: "slapen"
  }
}

The error:

strtolower(): Argument #1 ($string) must be of type string, array given

@duncanmcclean duncanmcclean reopened this Jun 20, 2024
@duncanmcclean
Copy link
Member

Ah, yeah. I was just referencing the answer to a previous discussion: #4983

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants