queries.hx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. QUERY CreateUser(name: String, age: U32, email: String) =>
  2. user <- AddN<User>({name: name, age: age, email: email})
  3. RETURN user
  4. QUERY CreateFollow(follower_id: ID, followed_id: ID) =>
  5. follower <- N<User>(follower_id)
  6. followed <- N<User>(followed_id)
  7. AddE<Follows>::From(follower)::To(followed) // don't need to specify the `since` property because it has a default value
  8. RETURN "success"
  9. QUERY CreatePost(user_id: ID, content: String) =>
  10. user <- N<User>(user_id)
  11. post <- AddN<Post>({content: content})
  12. AddE<Created>::From(user)::To(post) // don't need to specify the `created_at` property because it has a default value
  13. RETURN post
  14. QUERY GetUsers() =>
  15. users <- N<User>
  16. RETURN users
  17. QUERY GetPosts() =>
  18. posts <- N<Post>
  19. RETURN posts
  20. QUERY GetPostsByUser(user_id: ID) =>
  21. posts <- N<User>(user_id)::Out<Created>
  22. RETURN posts
  23. QUERY GetFollowedUsers(user_id: ID) =>
  24. followed <- N<User>(user_id)::Out<Follows>
  25. RETURN followed
  26. QUERY GetFollowedUsersPosts(user_id: ID) =>
  27. followers <- N<User>(user_id)::Out<Follows>
  28. posts <- followers::Out<Created>::RANGE(0, 40)
  29. RETURN posts::{
  30. post: _::{content},
  31. creatorID: _::In<Created>::ID,
  32. }