For example, in a classic article/blog site, we have tags related to articles.
Article {
...
tags: Tag[];
}
Tag {
id: string;
slug: string;
name: string;
}
And we have a tag page showing all the articles with this tag like this: https://getjerry.com/tag/driver-licenses
In this page, I need to query the tag.id
from tag.slug
first and then use the tag.id
to query articles.
Is it possible to query articles with tag.slug
directly?
I think this is a common feature that other CMS like contentful supports.
Yes, this is possible! Right now, it's only possible in the REST API and Local APIs due to how complex the query types would get in GraphQL (lots of query possibilities) but in REST you can do:
/api/articles?where[tag.slug][in]=some-tag
I think in your case you probably have many tags, which is why I used in
rather than equals
.
But this should work great!
Aha, it's not doable through graphql then.
I'm trying to achieve this by using slug as id with custom id feature directly.
I'm wondering if this solution has any defects?
@jmikrut Any suggestions?
Hey @Stupidism this would work very well. Custom IDs are pretty cool.
You should totally give that a shot and let me know how it works, but note, that at some point in the future we will certainly be supporting "nested queries" in GraphQL as well. Probably soon-ish. Can't guarantee, but it's a commonly requested feature.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.