Deep filtering on both CMA and CDA

No sorry, we are working on some infrastructure changes on the DB side to gain performance and scalability. Once everything is settled there we’ll start considering this and the inverse relationships request.

1 Like

One more up-vote for this issue. Thanks.

+1 for this,

In the meantime: does anyone has an example doing two queries to 1. fetch the ID of a category to use in 2. filter posts query by category ID from the first? I’m using request from “@/lib/datocms” in NextJS

Hello @timvandevelde1 , for the meantime, i’ve discussed a bit of the options to split this into multiple queries in my first reply to this thread right here: Multiple graphQL queries?

1 Like

Thanks for the nudge in the right direction @m.finamor. Managed to get it working using request from the datocms library. For anyone interested: here’s my workaround in NextJS for doing two requests and merging them together to use with useQuerySubscription:

in getStaticProps

...

const categoryRequest = {
  query: `
      query CategoryBySlug($slug: String) {
        category(filter: {slug: {eq: $slug}}) {
          id
          name
        }      
      }
    `,
  preview,
  variables: {
    slug: params.slug,
  },
};
const categoryResults = await request(categoryRequest);
const categoryID = categoryResults.category.id;

const postsRequest = {
  query: `
      query PostsByCategory($category: ItemId) {
        allPosts (filter: {category: {eq: $category}}) {
          title
          category {
            name
            slug
          }
        }
      }
    `,
  preview,
  variables: {
    category: categoryID,
  },
};
const postResults = await request(postsRequest);

let mergedRequests = {
  ...categoryResults,
  ...postResults,
};

...
2 Likes

Another +1 from my side, it would be really helpful!

Voted :+1:

Deep / nested filtering would be amazing!

+1 vote

+1 vote

+∞ vote

1 Like

Any updates? This would be super helpful!

+1

Hello everyone interested in deep filtering :slight_smile:

We are again trying to tackle this feature and we would like to have some recent use cases for this. Since we have released the inverse relationships we feel like the basic use case of retrieving a linked model by a filtered property is solved.

In the classic example of blog posts and categories, where the category is linked from the post, you can filter the category by name and then get all the referencing posts.

So, this use case is solved (we think), what else do you need this for? What are your blockers here exactly?

/cc @rislam1 @DatoUser @primoz.rome @jevgenijs.metelovs @luke.michals @timvandevelde1 @moritz.jacobs @anton.stjernquist @Dan @website @mordonez.sanchez @benjamincbialy @kaptankorkut

Hi Matteo, thanks for the update.

I consult a company that hosts events for students at companies. Event is a separate entity and can have multiple hosts. On a company page I want to list all upcoming events and therefore I need advanced filters on the inverse relations function, because I don’t want to list all events related to the company but only the upcoming ones.

Nice feature, thank you.

Hey @kaptankorkut we have just released this. You can now use the filter argument on inverse relationships. Let us know how this works for you :slight_smile:

1 Like

Hey @fabrizio this is great news. Once I have tested this feature, I will write some feedback here.

Hey @fabrizio, great feature. It allows me to get the data I need but for nested relationships it can get quite messy

This is what I am doing

query GetSneakers {
  allBrands(filter: {slug: {eq: "new-balance" }}) {
    _allReferencingSneakers {
      name
    }
    _allReferencingCollections(filter: { slug: { eq: "327" }}) {
      _allReferencingSneakers {
        name
      }
      _allReferencingSilhouettes(filter: { slug: { eq:"3"} }) {
        _allReferencingSneakers {
          name
        }
      }
    }
  }  
}

This is what I would like to do

query GetSneakers {
  allSneakers(filter: { 
    brand: { slug: { eq: "new-balance"}},
    collection: { slug: { eq: "327"}},
    silhouette: { slug: { eq: "3"}}
  }) {
   name
  }  
}

The first method will return duplicate data and I will need to process the results to decide what to show to the user. Also I am not sure whether I will face any issues with pagination

Any suggestions/recommendations is appreciated

Hey @nuurcodes thanks for your feedback, much appreciated :pray:

Yeah, I think that in your case (having multiple filtering conditions) using inverse relationships would not be optimal.

Also I am not sure whether I will face any issues with pagination

Probably you will face them, because each _allReferencing<Model> query is paginated, so it might happen that the same sneaker appears in different pages, and you won’t be able to identify the snakers matching both three conditions.

Adding filter to the inverse relationship field did not take too much effort and it was worth a try. We will discuss internally on how to deal with your scenario

1 Like

Hello @fabrizio, thanks for the hard work in DatoCMS, I’m wondering if is there any update about Adding filter to the inverse relationship field, that feature would be really helpful