GraphQL & Nuxt blog starter : How to filter categories only used in Post

Hello !

From the queries based on the Dato Starter Nuxtjs Blog repo, I’m trying to filter a simple model of categories.
What I want is to retrieve only the categories which are used at last once in any BlogPost model.
The Category model has only 2 fields (name and slug) and is used in the BlogPost model with a multiple relationnal field.
I’m sure it is possible but I’m lacking so much XP in graphql, how will do you handle that filter request ?



Hello @jeremy1 and welcome to Community!

Sorry for the late reply but I don’t think you can only retrieve the categories used at least once in blog posts specifically.

You can do that in your code by fetching all the blog posts and filtering the categories that are used. But I don’t know if there’s a way to get exactly what you want.

No, I’m sorry there is no way to do that with graphql

Hello guys !

Thanks you for your reply.
I was pretty sure it was impossible, but since we can get the “links” in Dato from admin panel ( = where a category model is used for), I thought maybe I was missing something :slight_smile:
But I imagine you get it only from a frontend fetching and filtering all models to catch if there is any reference.

Thank you for your help again !

Yes, it’s now a REST API feature, but it’s still undocumented. It will be eventually, not there yet!