With a GraphQL schema similar to below, containing a many-to-one relation, I have a resolver UDF that I want to return a page of Review
documents that:
- Are filtered by their
user
field, and… - Are filtered by the inclusion of at least one
Tag
in theirtags
field that has a giventext
subfield, and… - Are sorted by their
created
field
(Basically, I need sorted reviews for a given user and tag)
type Review {
user: User!
created: Time!
text: String!
tags: [Tag] @relation
}
type Tag {
review: Review! @relation
text: String!
}
I tried to use a couple indexes like these…
CreateIndex({
name: "recent_reviews_by_user",
source: Collection("Review"),
terms: [
{ field: ["data", "user"] }
],
values: [
{ field: ["data", "created"], reverse: true },
{ field: ["ref"] }
]
})
CreateIndex({
name: "tag_reviews_by_review_and_tag",
source: Collection("Tag"),
terms: [
{ field: ["data", "review"] },
{ field: ["data", "text"] }
],
values: [
{ field: ["data", "review"] }
]
})
and Join
the indexes together, like…
Paginate(
Join(
Match(
Index("recent_reviews_by_user"),
Ref(Collection("User"), "some user ID")
),
Lambda(
["created", "reviewRef"],
Match(Index("tag_reviews_by_review_and_tag"), [Var("reviewRef"), "some tag"])
)
)
)
but I’m guessing since the tag_reviews_by_review_and_tag
index only returns a default ref
value, the sorting performed by the recent_reviews_by_user
index is lost in the Join
If someone has a suggestion for a better approach to achieve the result I’m after, it’d be greatly appreciated! Currently I’m feeling quite stuck unfortunately…