-
Notifications
You must be signed in to change notification settings - Fork 7
/
schema.graphql
204 lines (192 loc) · 4.72 KB
/
schema.graphql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
type Tweet {
created_at: DateTime
favorites: Int
id: ID!
id_str: String
import_method: String
text: String
using: [Source] @relationship(type: "USING", direction: OUT)
tags: [Hashtag] @relationship(type: "TAGS", direction: OUT)
retweets: [Tweet] @relationship(type: "RETWEETS", direction: OUT)
reply_to: [Tweet] @relationship(type: "REPLY_TO", direction: OUT)
contains: [Link] @relationship(type: "CONTAINS", direction: OUT)
posted_by: User @relationship(type: "POSTS", direction: IN)
}
type Me {
followers: Int!
following: Int!
location: String!
name: String!
profile_image_url: String!
screen_name: ID!
posts: [Tweet] @relationship(type: "POSTS", direction: OUT)
users: [User] @relationship(type: "FOLLOWS", direction: IN)
tweets: [Tweet] @relationship(type: "MENTIONS", direction: IN)
}
type Hashtag {
name: String!
tweets: [Tweet] @relationship(type: "TAGS", direction: IN)
num_tweets: Int @cypher(statement: "RETURN SIZE( (this)<-[:TAGS]-(:Tweet) )")
}
type Link {
url: String!
tweets: [Tweet] @relationship(type: "CONTAINS", direction: IN)
}
type Source {
name: String!
tweets: [Tweet] @relationship(type: "USING", direction: IN)
}
type User {
followers: Int
following: Int
location: String
name: String!
profile_image_url: String
screen_name: String!
statuses: Int
url: String
posts: [Tweet] @relationship(type: "POSTS", direction: OUT)
tweets: [Tweet] @relationship(type: "MENTIONS", direction: IN)
}
type UserCount {
count: Int
user: User
}
type HashtagCount {
count: Int
name: String
}
type UserTweet {
screen_name: String
name: String
profile_pic: String
created_at: DateTime
text: String
}
extend type Me {
topMentions(first: Int = 5): [UserCount]
@cypher(
statement: """
MATCH (this)-[:POSTS]->(t:Tweet)-[:MENTIONS]->(m:User)
WITH m, COUNT(m.screen_name) AS count
ORDER BY count DESC
LIMIT $first
RETURN {
user: m { .* },
count: count
}
"""
)
topHashtags(first: Int = 5): [HashtagCount]
@cypher(
statement: """
MATCH (this:Me)-[:POSTS]->(t:Tweet)-[:TAGS]->(h:Hashtag)
WITH h, COUNT(h) AS count
ORDER BY count DESC
LIMIT $first
RETURN {
name: h.name,
count: count
}
"""
)
followbackCount: Int
@cypher(
statement: """
MATCH (me:Me)-[:FOLLOWS]->(f:User)
WHERE (f)-[:FOLLOWS]->(me)
RETURN count(f)
"""
)
recommended(first: Int = 10): [UserCount]
@cypher(
statement: """
MATCH (u:User)-[:POSTS]->(t:Tweet)-[:MENTIONS]->(me:Me)
WITH DISTINCT u, me, count(t) as count
WHERE (u)-[:FOLLOWS]->(me)
AND NOT (me)-[:FOLLOWS]->(u)
RETURN {
user: u { .* },
count: count
}
ORDER BY count DESC
LIMIT $first
"""
)
priorityFeed: [UserTweet]
@cypher(
statement: """
MATCH (t:Tweet) WHERE t.created_at IS NOT NULL
WITH max(t.created_at) - duration('P3D') as recentDate
CALL {
WITH recentDate
MATCH (this:Me)-[r:SIMILAR_TO]-(u:User)
WITH u, recentDate
ORDER BY r.score DESC
LIMIT 10
MATCH (u)-[:POSTS]->(t:Tweet)
WHERE t.created_at >= recentDate
WITH u, t
ORDER BY t.created_at DESC
LIMIT 50
RETURN {
screen_name: u.screen_name,
name: u.name,
profile_pic: u.profile_image_url,
created_at: t.created_at,
text: t.text
} as tweets
UNION
WITH recentDate
MATCH (u:User)-[r:POSTS]->(t:Tweet)
WHERE t.created_at >= recentDate AND NOT u:Me
WITH u, t
ORDER BY t.created_at DESC
LIMIT 50
RETURN {
screen_name: u.screen_name,
name: u.name,
profile_pic: u.profile_image_url,
created_at: t.created_at,
text: t.text
} as tweets
ORDER BY t.created_at DESC
LIMIT 50
}
RETURN tweets
"""
)
}
extend type User {
topMentions: UserCount
@cypher(
statement: """
MATCH (this)-[:POSTS]->(t:Tweet)-[:MENTIONS]->(m:User)
WITH m, COUNT(m.screen_name) AS count
ORDER BY count DESC
LIMIT 1
RETURN {
user: m {.*},
count: count
}
"""
)
}
extend type Tweet {
mentions: [User] @relationship(type: "MENTIONS", direction: OUT)
}
extend type Hashtag {
trendingTags(first: Int = 5): [HashtagCount]
@cypher(
statement: """
MATCH (t:Tweet)-[:TAGS]->(h:Hashtag)
WITH h, count(h) as count
ORDER BY count DESC
LIMIT $first
RETURN {
name: h.name,
count: count
}
"""
)
}