I am trying to find a way to use Custom DQL with a count (or aggregate), but use my same type.
type Post {
id: ID!
name: String!
likes: [User]
...
}
and I want to sort them by something, so I have a custom query like so:
type Query {
querySorted: [Post] @custom(dql: """
query {
var(func: type(Post)) {
totalLikes as count(Post.likes)
}
q(func: type(post), orderdesc: val(totalLikes) {
id: uid
name: Post.name
likes: Post.likes {
...
}
...
aggregateLikes {
count: count(Post.likes)
}
}
}
""")
}
I figured the aggregate likes would simulate what happens in GraphQL, but I get a null value. This kind of makes sense because there is no value for it.
I tried aggregateLikes: Post.likes {
, but this doesn’t work and gives an error. I also thought about an interface, but then I saw this post:
Is there anyway to simplify this so I don’t have to create a bunch of remote types for a type I already have?
Thanks,
J