improved schema

This commit is contained in:
Grzegorz Leoniec 2018-10-16 09:46:21 +02:00
parent 2105b4d4aa
commit 81216f52c6

View File

@ -15,6 +15,10 @@ type WrittenPost @relation(name: "WROTE") {
to: Post to: Post
timestamp: Int # TODO: change that to custom Date Type timestamp: Int # TODO: change that to custom Date Type
} }
# type WrittenPost2 {
# Post: Post!
# timestamp: Int # TODO: change that to custom Date Type
# }
type WrittenComment @relation(name: "WROTE") { type WrittenComment @relation(name: "WROTE") {
from: User from: User
to: Comment to: Comment
@ -23,30 +27,41 @@ type WrittenComment @relation(name: "WROTE") {
type User { type User {
id: ID! id: ID!
name: String! name: String @default(to: "Anonymus")
email: String email: String
slug: String slug: String
password: String! password: String!
avatar: String avatar: String
deleted: Boolean @default(to: false)
disabled: Boolean @default(to: false) disabled: Boolean @default(to: false)
role: UserGroupEnum role: UserGroupEnum
friends: [User]! @relation(name: "FRIENDS", direction: "BOTH") friends: [User]! @relation(name: "FRIENDS", direction: "BOTH")
friendsCount: Int! @cypher(statement: "MATCH (this)<-[:FRIENDS]->(r:User) RETURN COUNT(r)") friendsCount: Int! @cypher(statement: "MATCH (this)<-[:FRIENDS]->(r:User) RETURN COUNT(r)")
following: [User]! @relation(name: "FOLLOWING", direction: "OUT") following: [User]! @relation(name: "FOLLOWS", direction: "OUT")
followingCount: Int! @cypher(statement: "MATCH (this)-[:FOLLOWING]->(r:User) RETURN COUNT(r)") followingCount: Int! @cypher(statement: "MATCH (this)-[:FOLLOWS]->(r:User) RETURN COUNT(r)")
followedBy: [User]! @relation(name: "FOLLOWING", direction: "IN") followedBy: [User]! @relation(name: "FOLLOWS", direction: "IN")
followedByCount: Int! @cypher(statement: "MATCH (this)<-[:FOLLOWING]-(r:User) RETURN COUNT(r)") followedByCount: Int! @cypher(statement: "MATCH (this)<-[:FOLLOWS]-(r:User) RETURN COUNT(r)")
contributions: [WrittenPost]! contributions: [WrittenPost]!
contributionsCount: Int! @cypher(statement: "MATCH (this)-[:WROTE]->(r:Post) RETURN COUNT(r)") #contributions2(first: Int = 10, offset: Int = 0): [WrittenPost2]!
# @cypher(
# statement: "MATCH (this)-[w:WROTE]->(p:Post) RETURN p as Post, w.timestamp as timestamp"
# )
contributionsCount: Int! @cypher(statement: """
MATCH (this)-[:WROTE]->(r:Post)
WHERE (NOT exists(r.deleted) OR r.deleted = false)
AND (NOT exists(r.disabled) OR r.disabled = false)
RETURN COUNT(r)"""
)
comments: [WrittenComment]! comments: [WrittenComment]!
commentsCount: Int! @cypher(statement: "MATCH (this)-[:WROTE]->(r:Comment) RETURN COUNT(r)") commentsCount: Int! @cypher(statement: "MATCH (this)-[:WROTE]->(r:Comment) RETURN COUNT(r)")
shouted: [Post]! @relation(name: "SHOUTED", direction: "OUT") shouted: [Post]! @relation(name: "SHOUTED", direction: "OUT")
shoutedCount: Int! @cypher(statement: "MATCH (this)-[:SHOUTED]->(r:Post) RETURN COUNT(r)")
organizationsCreated: [Organization] @relation(name: "CREATED_ORGA", direction: "OUT") organizationsCreated: [Organization] @relation(name: "CREATED_ORGA", direction: "OUT")
organizationsOwned: [Organization] @relation(name: "OWNING_ORGA", direction: "OUT") organizationsOwned: [Organization] @relation(name: "OWNING_ORGA", direction: "OUT")
@ -66,16 +81,19 @@ type Post {
contentExcerpt: String contentExcerpt: String
image: String image: String
visibility: VisibilityEnum visibility: VisibilityEnum
disabled: Boolean @default(to: false) deleted: Boolean @default(to: false)
# relatedContributions: [Post]! @cypher(statement: "MATCH (this)-[:TAGGED]->(t:Tag)<-[:TAGGED]-(p1:Post) MATCH (this)-[:CATEGORIZED]->(t:Category)<-[:CATEGORIZED]-(p2:Post) RETURN collect(distinct p2) + p1") relatedContributions: [Post]! @cypher(statement: """
relatedContributions: [Post]! @cypher(statement: "MATCH (this)-[:TAGGED]->(t:Tag)<-[:TAGGED]-(p:Post) return p") MATCH (this)-[:TAGGED|CATEGORIZED]->(categoryOrTag)<-[:TAGGED|CATEGORIZED]-(post:Post)
RETURN DISTINCT post
LIMIT 10
""")
tags: [Tag]! @relation(name: "TAGGED", direction: "OUT") tags: [Tag]! @relation(name: "TAGGED", direction: "OUT")
categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT") categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT")
comments: [Comment]! @relation(name: "COMMENT", direction: "IN") comments: [Comment]! @relation(name: "COMMENTS", direction: "IN")
commentsCount: Int! @cypher(statement: "MATCH (this)<-[:COMMENT]-(r:Comment) RETURN COUNT(r)") commentsCount: Int! @cypher(statement: "MATCH (this)<-[:COMMENTS]-(r:Comment) RETURN COUNT(r)")
shoutedBy: [User]! @relation(name: "SHOUTED", direction: "IN") shoutedBy: [User]! @relation(name: "SHOUTED", direction: "IN")
shoutedCount: Int! @cypher(statement: "MATCH (this)<-[:SHOUTED]-(r:User) RETURN COUNT(r)") shoutedCount: Int! @cypher(statement: "MATCH (this)<-[:SHOUTED]-(r:User) RETURN COUNT(r)")
@ -87,7 +105,7 @@ type Comment {
content: String! content: String!
contentExcerpt: String contentExcerpt: String
post: Post @relation(name: "COMMENT", direction: "OUT") post: Post @relation(name: "COMMENT", direction: "OUT")
disabled: Boolean @default(to: false) deleted: Boolean @default(to: false)
} }
type Category { type Category {
@ -95,6 +113,8 @@ type Category {
name: String! name: String!
slug: String slug: String
icon: String! icon: String!
posts: [Post]! @relation(name: "CATEGORIZED", direction: "IN")
postCount: Int! @cypher(statement: "MATCH (this)<-[:CATEGORIZED]-(r:Post) RETURN COUNT(r)")
} }
type Badge { type Badge {
@ -124,7 +144,7 @@ type Organization {
slug: String slug: String
description: String! description: String!
descriptionExcerpt: String descriptionExcerpt: String
disabled: Boolean @default(to: false) deleted: Boolean @default(to: false)
tags: [Tag]! @relation(name: "TAGGED", direction: "OUT") tags: [Tag]! @relation(name: "TAGGED", direction: "OUT")
categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT") categories: [Category]! @relation(name: "CATEGORIZED", direction: "OUT")
@ -136,5 +156,5 @@ type Tag {
taggedPosts: [Post]! @relation(name: "TAGGED", direction: "IN") taggedPosts: [Post]! @relation(name: "TAGGED", direction: "IN")
taggedOrganizations: [Organization]! @relation(name: "TAGGED", direction: "IN") taggedOrganizations: [Organization]! @relation(name: "TAGGED", direction: "IN")
taggedCount: Int! @cypher(statement: "MATCH (this)<-[:TAGGED]-(r) RETURN COUNT(r)") taggedCount: Int! @cypher(statement: "MATCH (this)<-[:TAGGED]-(r) RETURN COUNT(r)")
disabled: Boolean @default(to: false) deleted: Boolean @default(to: false)
} }