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

Can't use blueprint as GraphQL filter #289

Closed
meandersen opened this issue May 13, 2024 · 4 comments
Closed

Can't use blueprint as GraphQL filter #289

meandersen opened this issue May 13, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@meandersen
Copy link

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 duncanmcclean changed the title Can't us blueprint as graphql filter Can't use blueprint as GraphQL filter May 13, 2024
@duncanmcclean
Copy link
Member

duncanmcclean commented May 14, 2024

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
Copy link
Author

meandersen commented May 15, 2024

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
Copy link
Member

duncanmcclean commented May 15, 2024

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 duncanmcclean transferred this issue from statamic/cms May 15, 2024
@duncanmcclean duncanmcclean added bug Something isn't working and removed needs more info labels May 15, 2024
@duncanmcclean
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants