directus / v8-archive

Directus Database API — Wraps Custom SQL Databases with a REST/GraphQL API
https://docs.directus.io/api/reference.html
507 stars 204 forks source link

graphql - relationed collection do not allow filters #1401

Open Wendenburg opened 4 years ago

Wendenburg commented 4 years ago

Bug Report

Steps to Reproduce

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

query {
    teaser {
        data {
            domain {
                domain
            }        
        }
    }
}
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

Owlree commented 4 years ago

Working on this already.

https://github.com/directus/api/issues/1167

Wendenburg commented 4 years ago

love to hear that, thanks!

Owlree commented 4 years ago

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.

flayks commented 4 years ago

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

rijkvanzanten commented 4 years ago

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

@Owlree are you looking into it?

samgranger commented 4 years ago

I'd love to have this functionality too

stouch commented 4 years ago

I really need this feature ! :'(

benhaynes commented 4 years ago

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

rijkvanzanten commented 4 years ago

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

stouch commented 4 years ago

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

EugenioSantos commented 4 years ago

any news about this problem/feature?

rijkvanzanten commented 4 years ago

@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

EugenioSantos commented 4 years ago

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

rijkvanzanten commented 4 years ago

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!

donni106 commented 4 years ago

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.

alvarogardev commented 4 years ago

any news about this problem/feature? thnks!