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 Forbidden Error When Using _or Condition in Entries Query #1286

Open
emran-alhaddad opened this issue Dec 17, 2024 · 6 comments
Open
Labels

Comments

@emran-alhaddad
Copy link

Bug description

What happened? What did you expect to happen?

When using an _or condition in a GraphQL query to filter entries, the query returns a "Forbidden" error. I expected the query to return entries matching either of the conditions specified.

Error Message:
Forbidden for _or condition.

How to reproduce

  1. Create a collection named articles with fields title and short_description.
  2. Run the following GraphQL query:
query Entries {
    entries(
        collection: "articles"
        filter: {
            _or: {
                title: { matches: ".*emran.*" }
                short_description: { matches: ".*emran1.*" }
            }
        }
    ) {
        data {
            ... on Entry_Articles_Article {
                title
                short_description
                date(format: "D-M-Y")
            }
        }
    }
}
  1. The query fails with the error message:
{
    "errors": [
        {
            "message": "validation",
            "locations": [
                {
                    "line": 2,
                    "column": 5
                }
            ],
            "path": [
                "entries"
            ],
            "extensions": {
                "category": "validation",
                "validation": {
                    "filter": [
                        "Forbidden: _or"
                    ]
                }
            }
        }
    ],
    "data": {
        "entries": null
    }
}

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 11.35.0
PHP Version: 8.2.22
Composer Version: 2.5.5
Environment: local
Debug Mode: ENABLED
URL: ####
Maintenance Mode: OFF
Timezone: UTC
Locale: en

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

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Statamic
Addons: 3
Sites: 2 (English, Arabic)
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.42.0 PRO

Statamic Addons
isaadsalman/headless-refresh: 1.0.0
mitydigital/statamic-tinymce-cloud: 3.1.0
ndx/statamic-bard-color-picker: 2.0.0

Installation

Fresh statamic/statamic site via CLI

Additional details

Is there any current way to use _or conditions in GraphQL? If not, is there an alternative or a planned fix for this issue?

Thank you for your help!

@duncanmcclean
Copy link
Member

Have you enabled the filter in your GraphQL config file?

@jasonvarga
Copy link
Member

jasonvarga commented Dec 17, 2024

Also, _or conditions like you've used isn't a thing in Statamic, nor is it a GraphQL standard.

It looks like it's a platform specific feature. Maybe you've used a service like Hasura or Strapi in the past which has support for an _or keyword.

I'll move this issue to the ideas repo.

@jasonvarga jasonvarga transferred this issue from statamic/cms Dec 17, 2024
@emran-alhaddad
Copy link
Author

Have you enabled the filter in your GraphQL config file?

Yes I have enabled all selected filters

@emran-alhaddad
Copy link
Author

Also, _or conditions like you've used isn't a thing in Statamic, nor is it a GraphQL standard.

It looks like it's a platform specific feature. Maybe you've used a service like Hasura or Strapi in the past which has support for an _or keyword.

I'll move this issue to the ideas repo.

Ok, So Statamic supports logical conditions like "or" in graphql ? or will this be in the upcoming versions ?

@jasonvarga
Copy link
Member

It doesn't support it right now.

@emran-alhaddad
Copy link
Author

@jasonvarga @jackmcdade We work on over 25 projects annually using Statamic, and this feature is essential for our workflow. Could you let us know if there's an expected timeline for its implementation? This would help us avoid resorting to building a RESTful API as an alternative.

Thank you!

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

3 participants