statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
104 stars 71 forks source link

Can't use `blueprint` as GraphQL filter #289

Closed meandersen closed 1 month ago

meandersen commented 1 month ago

Bug description

After we have updated from Statamic 3.4 to 4.0, we got an issue with graphql. When we call entries and uses blueprint as a filter, we are ending up with an empty array of entries. Status, collection and parent works fine when we use them in filters.

How to reproduce

graphql.php

'resources' => [
        'collections' => [
            '*' => [
                'enabled' => true, // All collection queries enabled
                'allowed_filters' => ['status', 'collection', 'parent', 'blueprint'], // With filters enabled for all
            ],
        ],
        'navs' => true,
        'taxonomies' => true,
        'assets' => true,
        'globals' => true,
        'sites' => true,
        'users' => false,
    ],

Query

query myQuery {
  entries(
    collection: "basic_pages"
    filter: {
      status: { in: "published" }
      blueprint: "blueprint_one"
    }
    sort: "publication_date desc"
  ) {
    data {
      __typename
      blueprint
      title
      status
    }
}

Result with blueprint

{
  "data": {
    "entries": {
      "data": []
    }
  }
}

Result without blueprint

{
  "data": {
    "entries": {
      "data": [
        {
          "__typename": "Entry_BasicPages_BlueprintOne",
          "blueprint": "blueprint_one",
          "title": "Foo",
          "status": "published"
        },
        {
          "__typename": "Entry_BasicPages_BlueprintTwo",
          "blueprint": "blueprint_two",
          "title": "Bar",
          "status": "published"
        },
        {
          "__typename": "Entry_BasicPages_BlueprintOne",
          "blueprint": "blueprint_one",
          "title": "Foo two",
          "status": "published"
        },
...

Logs

No response

Environment

Statamic version: 4.48.0
Laravel Version: 9.52.16
PHP Version: 8.1.26
Composer Version: 2.7.6

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

duncanmcclean commented 1 month ago

I've just copied the query you provided into my site and changed the collection and it works as expected 🤔

CleanShot 2024-05-14 at 11 06 57

Are you able to provide the full output of php please support:details?

meandersen commented 1 month ago

Hi @duncanmcclean The full support details

Environment
Application Name: Test Site
Laravel Version: 9.52.16
PHP Version: 8.1.26
Composer Version: 2.7.6
Environment: local
Debug Mode: ENABLED
URL: testsite.test
Maintenance Mode: OFF

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

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

Sentry
Enabled: YES
Environment: local
Laravel SDK Version: 3.8.2
PHP SDK Version: 3.22.1
Release: NOT SET
Sample Rate Errors: 100%
Sample Rate Performance Monitoring: 100%
Sample Rate Profiling: NOT SET
Send Default PII: DISABLED

Statamic
Addons: 3
Antlers: runtime
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.48.0 PRO

Statamic Addons
rias/statamic-redirect: 3.7.1
statamic-rad-pack/meilisearch: 3.2.1
statamic/eloquent-driver: 3.1.2

Statamic Eloquent Driver
Asset Containers: file
Assets: eloquent
Blueprints: eloquent
Collection Trees: file
Collections: eloquent
Entries: eloquent
Forms: eloquent
Global Sets: eloquent
Global Variables: file
Navigation Trees: file
Navigations: eloquent
Revisions: eloquent
Taxonomies: eloquent
Terms: eloquent
duncanmcclean commented 1 month ago

Ah, I was using the Stache and it was working fine. When I switch to the Eloquent Driver, I see the issue.

I'm going to transfer this issue to the eloquent-driver repository since it's not a core issue.

duncanmcclean commented 1 month ago

I've just taken a look into this, using the latest version of Statamic and the Eloquent Driver.

In my testing, it actually seems like its the status filter causing issues, not the blueprint filter. When I comment out the blueprint filter in my query, I still get no results returned.

I believe this may be happening due to the fact you're querying the status using the in condition, rather than the equals condition, which we'd recommend for querying statuses.

Obviously, by using the equals condition, it does mean you can only query a single status at a time. From your example, it doesn't look like you need to query multiple statuses at once, but if you do, you'd have to split each status into it's own GraphQL query and use equals.