What I want to do
I’m working on a social media app, and my Dgraph schema has Feed
and Post
types that look like this (simplified):
type Feed {
feedPostTypes
}
type Post {
postType
}
feedPostTypes: [string] .
postType: string .
The postType
predicate can be one of "TEXT"
, "PHOTO"
, or "VIDEO"
, indicating the type of content contained in the post.
The feedPostTypes
predicate contains a list of the post types that are enabled in the feed. For example, if feedPostTypes
is ["PHOTO", "VIDEO"]
, then the user doesn’t want to see posts containing only text.
My question is: When I’m querying for posts to show in the feed, how can I filter out posts whose type doesn’t match the types enabled in the feed?
What I did
I’m using DQL, so I tried multiple query blocks and a variable, but this doesn’t work:
{
var(func: uid("0x1")) {
types as feedPostTypes
}
posts(func: type(Post)) @filter(anyofterms(postType, val(types)) {
...
}
}