V8-archive: graphql - relationed collection do not allow filters

Created on 7 Nov 2019  路  16Comments  路  Source: directus/v8-archive

Bug Report

Steps to Reproduce

Actually i am not sure if this should be a feature request or a bug issue

  • create any collection containing a relation like many to one, here with domains
  • query your data - it works:
query {
    teaser {
        data {
            domain {
                domain
            }        
        }
    }
}
  • now add a filter to the query like:
query {
    teaser(filter: {
        domain: {
            domain_eq: "mydomain"
        }
    }) {
        data {
            domain {
                domain
            }        
        }
    }
}

Expected Behavior

response should contain only filtered items

Actual Behavior

unexpected response like:

{
    "errors": [
        {
            "message": "Field \"domain\" is not defined by type TeaserFilter.",
            "extensions": {
                "category": "graphql"
            },
            "locations": [
                {
                    "line": 3,
                    "column": 9
                }
            ]
        }
    ]
}

Other Context & Screenshots

In a simple collection filtering works as expected. Here we just have to input fields for country and term and no relations:

query {
    terms(filter: {
        country_eq: "de"
    }) {
    data {
      country
      term
    }
  }
}

Technical Details

  • Device: desktop
  • OS: Mac OS 10.13.6
  • Web Server: Apache, Mamp
  • PHP Version: 7.3.8
  • Database: 5.7.26
  • Install Method: cloned master branch
bug api

Most helpful comment

Hey, sorry about this, but I misread your issue (possibly out of tiredness). I was not actually planning to implement this, but I can definitely look into it.

At first glance, it looks like it's not a bug, but relation filters simply were not implemented.

@rijkvanzanten @bjgajjar Should we add this? My guess is that it's not technically hard to do.

All 16 comments

love to hear that, thanks!

Hey, sorry about this, but I misread your issue (possibly out of tiredness). I was not actually planning to implement this, but I can definitely look into it.

At first glance, it looks like it's not a bug, but relation filters simply were not implemented.

@rijkvanzanten @bjgajjar Should we add this? My guess is that it's not technically hard to do.

I second that, exactly in the same situation and can't really get items filtered from a nested field.

My guess is that it's not technically hard to do.

@Owlree are you looking into it?

I'd love to have this functionality too

I really need this feature ! :'(

We prioritize feature requests by 馃憤 on the ticket (not sure if sub-comments count too), and if they are sponsored:

https://docs.directus.io/getting-started/supporting-directus.html#commissioned-features

Also, seeing it's an open source project, feel free to open a PR for things like this @stouch 馃檪

Yeah thank you guys for your responsiveness, I'll do this

any news about this problem/feature?

@EugenioSantos we're moving the API to a Laravel / GraphQL powered codebase over on https://github.com/directus/api-next. While this is not an immediate short term solution, we'll be fully supporting graphql in the next major version

@rijkvanzanten
Thanks for the reply 馃憤. Do you have a release forecast for the next major version?

Hard to pinpoint exactly. I'd rather not make any promises I can't keep 馃檪 We're a small team working for free, so the best I can say is keep an eye on github.com/directus/directus/releases. We're trying to have an alpha out pretty soon!

I am also looking forward for an ability to filter on nested attributes.
For now I made it happen with the _contains filter for a nested model.

service(filter: {community_contains: "${special_id}"}) {
  data {
    id
    name
    teaser
    community {
      special_id
    }
  }
}

This somehow returns me only service data for the correct community. The special_id needs to be a string.
You need to be sure, that the value of special_id cannot be the value of another field of community. It looks like, that the _contains searches in every field of a model.

any news about this problem/feature? thnks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gitlabisbetterthangithub picture gitlabisbetterthangithub  路  3Comments

jwkellyiii picture jwkellyiii  路  3Comments

ondronix picture ondronix  路  3Comments

rijkvanzanten picture rijkvanzanten  路  3Comments

vuhrmeister picture vuhrmeister  路  3Comments