I'm planning to use SQL Server 2019 graph features for one of my project. The data scheme would look something like the picture below.
Given the user (Id: 2356, name: Mark), I would want to retrieve all the Posts and the Tweets done by the user's follower ordered by when it was posted or when it was tweeted together with a limit/pagination on the overall result.
As of now, I don't know of a better way other than doing 2 separate queries & manually handling pagination, which makes it inefficient & also cumbersome if we add another new edge type in future in addition to Posted/Tweeted.
Are there better ways to address such usecases in SQL Server graph ?
SELECT mainUser.*, followingUser.*, followerPost.*
FROM
User mainUser, Follows userFollows, User followingUser, Posted followerPosted, Post followerPost
WHERE
MATCH (mainUser-(userFollows)->followingUser-(followerPosted)->followerPost)
AND
mainUser.id=2356
ORDER BY
followerPosted.posted_on desc
SELECT mainUser.*, followingUser.*, followerTweet.*
FROM
User mainUser, Follows userFollows, User followingUser, Tweeted tweeted, Tweet followerTweet
WHERE
MATCH (mainUser-(userFollows)->followingUser-(tweeted)->followerTweet)
AND
mainUser.id=2356
ORDER BY
tweeted.tweeted_on desc