statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.58k stars 489 forks source link

GraphQL filter not working as intended #10290

Open JelmerOT opened 3 weeks ago

JelmerOT commented 3 weeks ago

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 commented 2 weeks ago

You can filter entries by taxonomies like this:

query MyQuery {
  entries(
    collection: "articles"
    filter: {article_categories: {contains: "slapen"}}
  ) {
    data {
      id
      title
    }
  }
}
JelmerOT commented 2 weeks ago

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 commented 2 weeks ago

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