rettiwt-api 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/.dockerignore +2 -0
  2. package/.gitattributes +3 -0
  3. package/Dockerfile +9 -0
  4. package/README.md +38 -0
  5. package/dist/config/env.d.ts +5 -0
  6. package/dist/config/env.js +9 -0
  7. package/dist/config/env.js.map +1 -0
  8. package/dist/index.d.ts +10 -0
  9. package/dist/index.js +23 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/models/graphql/Global.d.ts +4 -0
  12. package/dist/models/graphql/Global.js +13 -0
  13. package/dist/models/graphql/Global.js.map +1 -0
  14. package/dist/models/graphql/TweetTypes.d.ts +6 -0
  15. package/dist/models/graphql/TweetTypes.js +156 -0
  16. package/dist/models/graphql/TweetTypes.js.map +1 -0
  17. package/dist/models/graphql/UserTypes.d.ts +3 -0
  18. package/dist/models/graphql/UserTypes.js +139 -0
  19. package/dist/models/graphql/UserTypes.js.map +1 -0
  20. package/dist/queries/RootQuery.d.ts +4 -0
  21. package/dist/queries/RootQuery.js +59 -0
  22. package/dist/queries/RootQuery.js.map +1 -0
  23. package/dist/resolvers/ResolverBase.d.ts +5 -0
  24. package/dist/resolvers/ResolverBase.js +11 -0
  25. package/dist/resolvers/ResolverBase.js.map +1 -0
  26. package/dist/resolvers/TweetResolver.d.ts +54 -0
  27. package/dist/resolvers/TweetResolver.js +328 -0
  28. package/dist/resolvers/TweetResolver.js.map +1 -0
  29. package/dist/resolvers/UserResolver.d.ts +47 -0
  30. package/dist/resolvers/UserResolver.js +302 -0
  31. package/dist/resolvers/UserResolver.js.map +1 -0
  32. package/dist/server.d.ts +1 -0
  33. package/dist/server.js +75 -0
  34. package/dist/server.js.map +1 -0
  35. package/dist/services/AuthService.d.ts +17 -0
  36. package/dist/services/AuthService.js +103 -0
  37. package/dist/services/AuthService.js.map +1 -0
  38. package/dist/services/CacheService.d.ts +25 -0
  39. package/dist/services/CacheService.js +141 -0
  40. package/dist/services/CacheService.js.map +1 -0
  41. package/dist/services/FetcherService.d.ts +30 -0
  42. package/dist/services/FetcherService.js +171 -0
  43. package/dist/services/FetcherService.js.map +1 -0
  44. package/dist/services/data/TweetService.d.ts +43 -0
  45. package/dist/services/data/TweetService.js +229 -0
  46. package/dist/services/data/TweetService.js.map +1 -0
  47. package/dist/services/data/UserAccountService.d.ts +49 -0
  48. package/dist/services/data/UserAccountService.js +250 -0
  49. package/dist/services/data/UserAccountService.js.map +1 -0
  50. package/dist/services/helper/Deserializers.d.ts +19 -0
  51. package/dist/services/helper/Deserializers.js +115 -0
  52. package/dist/services/helper/Deserializers.js.map +1 -0
  53. package/dist/services/helper/Extractors.d.ts +101 -0
  54. package/dist/services/helper/Extractors.js +409 -0
  55. package/dist/services/helper/Extractors.js.map +1 -0
  56. package/dist/services/helper/Headers.d.ts +9 -0
  57. package/dist/services/helper/Headers.js +47 -0
  58. package/dist/services/helper/Headers.js.map +1 -0
  59. package/dist/services/helper/Parser.d.ts +28 -0
  60. package/dist/services/helper/Parser.js +104 -0
  61. package/dist/services/helper/Parser.js.map +1 -0
  62. package/dist/services/helper/Urls.d.ts +74 -0
  63. package/dist/services/helper/Urls.js +114 -0
  64. package/dist/services/helper/Urls.js.map +1 -0
  65. package/dist/test/Test.js +2 -0
  66. package/dist/test/Test.js.map +1 -0
  67. package/dist/types/Authentication.d.ts +15 -0
  68. package/dist/types/Authentication.js +5 -0
  69. package/dist/types/Authentication.js.map +1 -0
  70. package/dist/types/HTTP.d.ts +22 -0
  71. package/dist/types/HTTP.js +30 -0
  72. package/dist/types/HTTP.js.map +1 -0
  73. package/dist/types/Service.d.ts +27 -0
  74. package/dist/types/Service.js +19 -0
  75. package/dist/types/Service.js.map +1 -0
  76. package/dist/types/Tweet.d.ts +40 -0
  77. package/dist/types/Tweet.js +5 -0
  78. package/dist/types/Tweet.js.map +1 -0
  79. package/dist/types/UserAccount.d.ts +19 -0
  80. package/dist/types/UserAccount.js +4 -0
  81. package/dist/types/UserAccount.js.map +1 -0
  82. package/dist/types/graphql/Errors.d.ts +15 -0
  83. package/dist/types/graphql/Errors.js +23 -0
  84. package/dist/types/graphql/Errors.js.map +1 -0
  85. package/dist/types/raw/auth/Cookie.d.ts +16 -0
  86. package/dist/types/raw/auth/Cookie.js +3 -0
  87. package/dist/types/raw/auth/Cookie.js.map +1 -0
  88. package/dist/types/raw/tweet/Favouriters.d.ts +164 -0
  89. package/dist/types/raw/tweet/Favouriters.js +3 -0
  90. package/dist/types/raw/tweet/Favouriters.js.map +1 -0
  91. package/dist/types/raw/tweet/Retweeters.d.ts +171 -0
  92. package/dist/types/raw/tweet/Retweeters.js +3 -0
  93. package/dist/types/raw/tweet/Retweeters.js.map +1 -0
  94. package/dist/types/raw/tweet/Tweet.d.ts +746 -0
  95. package/dist/types/raw/tweet/Tweet.js +3 -0
  96. package/dist/types/raw/tweet/Tweet.js.map +1 -0
  97. package/dist/types/raw/tweet/Tweets.d.ts +386 -0
  98. package/dist/types/raw/tweet/Tweets.js +3 -0
  99. package/dist/types/raw/tweet/Tweets.js.map +1 -0
  100. package/dist/types/raw/user/Followers.d.ts +176 -0
  101. package/dist/types/raw/user/Followers.js +3 -0
  102. package/dist/types/raw/user/Followers.js.map +1 -0
  103. package/dist/types/raw/user/Following.d.ts +176 -0
  104. package/dist/types/raw/user/Following.js +3 -0
  105. package/dist/types/raw/user/Following.js.map +1 -0
  106. package/dist/types/raw/user/Likes.d.ts +1059 -0
  107. package/dist/types/raw/user/Likes.js +3 -0
  108. package/dist/types/raw/user/Likes.js.map +1 -0
  109. package/dist/types/raw/user/Tweets.d.ts +2428 -0
  110. package/dist/types/raw/user/Tweets.js +3 -0
  111. package/dist/types/raw/user/Tweets.js.map +1 -0
  112. package/dist/types/raw/user/User.d.ts +117 -0
  113. package/dist/types/raw/user/User.js +3 -0
  114. package/dist/types/raw/user/User.js.map +1 -0
  115. package/dist/types/raw/user/Users.d.ts +120 -0
  116. package/dist/types/raw/user/Users.js +3 -0
  117. package/dist/types/raw/user/Users.js.map +1 -0
  118. package/environment.d.ts +11 -0
  119. package/package.json +40 -0
  120. package/src/config/env.ts +5 -0
  121. package/src/index.ts +19 -0
  122. package/src/models/graphql/Global.ts +10 -0
  123. package/src/models/graphql/TweetTypes.ts +154 -0
  124. package/src/models/graphql/UserTypes.ts +137 -0
  125. package/src/queries/RootQuery.ts +56 -0
  126. package/src/resolvers/ResolverBase.ts +12 -0
  127. package/src/resolvers/TweetResolver.ts +257 -0
  128. package/src/resolvers/UserResolver.ts +239 -0
  129. package/src/server.ts +36 -0
  130. package/src/services/AuthService.ts +58 -0
  131. package/src/services/CacheService.ts +70 -0
  132. package/src/services/FetcherService.ts +84 -0
  133. package/src/services/data/TweetService.ts +163 -0
  134. package/src/services/data/UserAccountService.ts +187 -0
  135. package/src/services/helper/Deserializers.ts +95 -0
  136. package/src/services/helper/Extractors.ts +455 -0
  137. package/src/services/helper/Headers.ts +45 -0
  138. package/src/services/helper/Parser.ts +108 -0
  139. package/src/services/helper/Urls.ts +109 -0
  140. package/src/types/Authentication.ts +16 -0
  141. package/src/types/HTTP.ts +23 -0
  142. package/src/types/Service.ts +36 -0
  143. package/src/types/Tweet.ts +44 -0
  144. package/src/types/UserAccount.ts +21 -0
  145. package/src/types/graphql/Errors.ts +16 -0
  146. package/src/types/raw/auth/Cookie.ts +16 -0
  147. package/src/types/raw/tweet/Favouriters.ts +193 -0
  148. package/src/types/raw/tweet/Retweeters.ts +201 -0
  149. package/src/types/raw/tweet/Tweet.ts +882 -0
  150. package/src/types/raw/tweet/Tweets.ts +444 -0
  151. package/src/types/raw/user/Followers.ts +208 -0
  152. package/src/types/raw/user/Following.ts +208 -0
  153. package/src/types/raw/user/Likes.ts +1247 -0
  154. package/src/types/raw/user/Tweets.ts +2847 -0
  155. package/src/types/raw/user/User.ts +135 -0
  156. package/tsconfig.json +95 -0
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ //# sourceMappingURL=Tweets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tweets.js","sourceRoot":"","sources":["../../../../src/types/raw/user/Tweets.ts"],"names":[],"mappings":""}
@@ -0,0 +1,117 @@
1
+ export default interface Root {
2
+ data: Data;
3
+ }
4
+ export interface Data {
5
+ user: User;
6
+ }
7
+ export interface User {
8
+ result: Result;
9
+ }
10
+ export interface Result {
11
+ __typename: string;
12
+ id: string;
13
+ rest_id: string;
14
+ affiliates_highlighted_label: AffiliatesHighlightedLabel;
15
+ has_nft_avatar: boolean;
16
+ legacy: Legacy;
17
+ smart_blocked_by: boolean;
18
+ smart_blocking: boolean;
19
+ super_follow_eligible: boolean;
20
+ super_followed_by: boolean;
21
+ super_following: boolean;
22
+ legacy_extended_profile: LegacyExtendedProfile;
23
+ is_profile_translatable: boolean;
24
+ }
25
+ export interface AffiliatesHighlightedLabel {
26
+ }
27
+ export interface Legacy {
28
+ blocked_by: boolean;
29
+ blocking: boolean;
30
+ can_dm: boolean;
31
+ can_media_tag: boolean;
32
+ created_at: string;
33
+ default_profile: boolean;
34
+ default_profile_image: boolean;
35
+ description: string;
36
+ entities: Entities;
37
+ fast_followers_count: number;
38
+ favourites_count: number;
39
+ follow_request_sent: boolean;
40
+ followed_by: boolean;
41
+ followers_count: number;
42
+ following: boolean;
43
+ friends_count: number;
44
+ has_custom_timelines: boolean;
45
+ is_translator: boolean;
46
+ listed_count: number;
47
+ location: string;
48
+ media_count: number;
49
+ muting: boolean;
50
+ name: string;
51
+ normal_followers_count: number;
52
+ notifications: boolean;
53
+ pinned_tweet_ids_str: any[];
54
+ possibly_sensitive: boolean;
55
+ profile_banner_extensions: ProfileBannerExtensions;
56
+ profile_banner_url: string;
57
+ profile_image_extensions: ProfileImageExtensions;
58
+ profile_image_url_https: string;
59
+ profile_interstitial_type: string;
60
+ protected: boolean;
61
+ screen_name: string;
62
+ statuses_count: number;
63
+ translator_type: string;
64
+ verified: boolean;
65
+ want_retweets: boolean;
66
+ withheld_in_countries: any[];
67
+ }
68
+ export interface Entities {
69
+ description: Description;
70
+ }
71
+ export interface Description {
72
+ urls: any[];
73
+ }
74
+ export interface ProfileBannerExtensions {
75
+ mediaColor: MediaColor;
76
+ }
77
+ export interface MediaColor {
78
+ r: R;
79
+ }
80
+ export interface R {
81
+ ok: Ok;
82
+ }
83
+ export interface Ok {
84
+ palette: Palette[];
85
+ }
86
+ export interface Palette {
87
+ percentage: number;
88
+ rgb: Rgb;
89
+ }
90
+ export interface Rgb {
91
+ blue: number;
92
+ green: number;
93
+ red: number;
94
+ }
95
+ export interface ProfileImageExtensions {
96
+ mediaColor: MediaColor2;
97
+ }
98
+ export interface MediaColor2 {
99
+ r: R2;
100
+ }
101
+ export interface R2 {
102
+ ok: Ok2;
103
+ }
104
+ export interface Ok2 {
105
+ palette: Palette2[];
106
+ }
107
+ export interface Palette2 {
108
+ percentage: number;
109
+ rgb: Rgb2;
110
+ }
111
+ export interface Rgb2 {
112
+ blue: number;
113
+ green: number;
114
+ red: number;
115
+ }
116
+ export interface LegacyExtendedProfile {
117
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ //# sourceMappingURL=User.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"User.js","sourceRoot":"","sources":["../../../../src/types/raw/user/User.ts"],"names":[],"mappings":""}
@@ -0,0 +1,120 @@
1
+ export default interface Root {
2
+ data: Data;
3
+ }
4
+ export interface Data {
5
+ users: User[];
6
+ }
7
+ export interface User {
8
+ result: Result;
9
+ }
10
+ export interface Result {
11
+ __typename: string;
12
+ id: string;
13
+ rest_id: string;
14
+ affiliates_highlighted_label: AffiliatesHighlightedLabel;
15
+ has_graduated_access: boolean;
16
+ has_nft_avatar: boolean;
17
+ is_blue_verified: boolean;
18
+ legacy: Legacy;
19
+ smart_blocked_by: boolean;
20
+ smart_blocking: boolean;
21
+ super_follow_eligible: boolean;
22
+ super_followed_by: boolean;
23
+ super_following: boolean;
24
+ verified_phone_status: boolean;
25
+ legacy_extended_profile: LegacyExtendedProfile;
26
+ is_profile_translatable: boolean;
27
+ }
28
+ export interface AffiliatesHighlightedLabel {
29
+ }
30
+ export interface Legacy {
31
+ blocked_by: boolean;
32
+ blocking: boolean;
33
+ can_dm: boolean;
34
+ can_media_tag: boolean;
35
+ created_at: string;
36
+ default_profile: boolean;
37
+ default_profile_image: boolean;
38
+ description: string;
39
+ entities: Entities;
40
+ fast_followers_count: number;
41
+ favourites_count: number;
42
+ follow_request_sent: boolean;
43
+ followed_by: boolean;
44
+ followers_count: number;
45
+ following: boolean;
46
+ friends_count: number;
47
+ has_custom_timelines: boolean;
48
+ is_translator: boolean;
49
+ listed_count: number;
50
+ location: string;
51
+ media_count: number;
52
+ muting: boolean;
53
+ name: string;
54
+ normal_followers_count: number;
55
+ notifications: boolean;
56
+ pinned_tweet_ids_str: string[];
57
+ possibly_sensitive: boolean;
58
+ profile_banner_extensions: ProfileBannerExtensions;
59
+ profile_banner_url: string;
60
+ profile_image_extensions: ProfileImageExtensions;
61
+ profile_image_url_https: string;
62
+ profile_interstitial_type: string;
63
+ protected: boolean;
64
+ screen_name: string;
65
+ statuses_count: number;
66
+ translator_type: string;
67
+ verified: boolean;
68
+ want_retweets: boolean;
69
+ withheld_in_countries: any[];
70
+ }
71
+ export interface Entities {
72
+ description: Description;
73
+ }
74
+ export interface Description {
75
+ urls: any[];
76
+ }
77
+ export interface ProfileBannerExtensions {
78
+ mediaColor: MediaColor;
79
+ }
80
+ export interface MediaColor {
81
+ r: R;
82
+ }
83
+ export interface R {
84
+ ok: Ok;
85
+ }
86
+ export interface Ok {
87
+ palette: Palette[];
88
+ }
89
+ export interface Palette {
90
+ percentage: number;
91
+ rgb: Rgb;
92
+ }
93
+ export interface Rgb {
94
+ blue: number;
95
+ green: number;
96
+ red: number;
97
+ }
98
+ export interface ProfileImageExtensions {
99
+ mediaColor: MediaColor2;
100
+ }
101
+ export interface MediaColor2 {
102
+ r: R2;
103
+ }
104
+ export interface R2 {
105
+ ok: Ok2;
106
+ }
107
+ export interface Ok2 {
108
+ palette: Palette2[];
109
+ }
110
+ export interface Palette2 {
111
+ percentage: number;
112
+ rgb: Rgb2;
113
+ }
114
+ export interface Rgb2 {
115
+ blue: number;
116
+ green: number;
117
+ red: number;
118
+ }
119
+ export interface LegacyExtendedProfile {
120
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ //# sourceMappingURL=Users.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Users.js","sourceRoot":"","sources":["../../../../src/types/raw/user/Users.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ // Declaring the environment variables
2
+ declare global {
3
+ namespace NodeJS {
4
+ interface ProcessEnv {
5
+ DEVELOPMENT: string; // To store whether environment is production or development
6
+ APP_PORT: string // To store the port on which this app runs
7
+ }
8
+ }
9
+ }
10
+
11
+ export {};
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "rettiwt-api",
3
+ "version": "1.0.1",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "description": "An API for fetching data from TwitterAPI, without any rate limits!",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "start": "node ./dist/server.js",
10
+ "debug": "nodemon ./dist/server.js --inspect=0.0.0.0:9229"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/Rishikant181/twitter-api.git"
15
+ },
16
+ "author": {
17
+ "email": "rishikantsahu181@gmail.com",
18
+ "name": "Rishikant Sahu"
19
+ },
20
+ "license": "ISC",
21
+ "bugs": {
22
+ "url": "https://github.com/Rishikant181/Rettiwt-API/issues"
23
+ },
24
+ "homepage": "https://github.com/Rishikant181/Rettiwt-API#readme",
25
+ "dependencies": {
26
+ "axios": "^1.3.2",
27
+ "express": "^4.18.2",
28
+ "express-graphql": "0.12.0",
29
+ "graphql": "14.7.0",
30
+ "node-cache": "5.1.2",
31
+ "node-libcurl": "3.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/express": "4.17.13",
35
+ "@types/graphql": "14.5.0",
36
+ "@types/node": "17.0.24",
37
+ "nodemon": "2.0.20",
38
+ "typescript": "4.6.4"
39
+ }
40
+ }
@@ -0,0 +1,5 @@
1
+ export const config = {
2
+ port: Number(process.env.APP_PORT),
3
+ is_development: (process.env.DEVELOPMENT == 'true'),
4
+ twitter_auth_token: 'Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA'
5
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ // SERVICES
2
+ import { AuthService } from "./services/AuthService";
3
+ import { UserAccountService } from "./services/data/UserAccountService";
4
+ import { TweetService } from "./services/data/TweetService";
5
+
6
+ /**
7
+ * @param cookie The cookies string to use to fetch data
8
+ * @returns The API for fetching user and tweet data
9
+ */
10
+ export const Rettiwt = (cookie: string = '') => {
11
+ // Creating new auth service instance using the given cookie string
12
+ const auth: AuthService = new AuthService(cookie);
13
+
14
+ // Using the auth service instance to create data services instances
15
+ return {
16
+ users: new UserAccountService(auth),
17
+ tweets: new TweetService(auth)
18
+ };
19
+ }
@@ -0,0 +1,10 @@
1
+ // PACKAGE
2
+ import { GraphQLString, GraphQLObjectType, } from "graphql";
3
+
4
+ export const Cursor = new GraphQLObjectType({
5
+ name: 'Cursor',
6
+ description: 'Cursor data for the next batch of list data',
7
+ fields: () => ({
8
+ value: { type: GraphQLString }
9
+ })
10
+ });
@@ -0,0 +1,154 @@
1
+ // PACKAGE
2
+ import { GraphQLList, GraphQLString, GraphQLObjectType, GraphQLInt, GraphQLBoolean, GraphQLUnionType } from "graphql";
3
+
4
+ // TYPES
5
+ import { User, UserList } from './UserTypes';
6
+ import { Cursor } from './Global';
7
+
8
+ // RESOLVERS
9
+ import TweetResolver from '../../resolvers/TweetResolver';
10
+ import UserResolver from "../../resolvers/UserResolver";
11
+
12
+ //@ts-ignore
13
+ export const TweetTokens = new GraphQLObjectType({
14
+ name: 'TweetTokens',
15
+ description: 'Additional extracted tokens from the tweet like mentions, hashtags, etc',
16
+ fields: () => ({
17
+ hashtags: { type: new GraphQLList(GraphQLString) },
18
+ urls: { type: new GraphQLList(GraphQLString) },
19
+ mentionedUsers: {
20
+ type: UserList,
21
+ resolve: (parent, args, context) => parent.mentionedUsers.map((user: string) => new UserResolver(context).resolveUserDetails('', user))
22
+ },
23
+ media: { type: new GraphQLList(GraphQLString) },
24
+ })
25
+ });
26
+
27
+ //@ts-ignore
28
+ export const Tweet = new GraphQLObjectType({
29
+ name: 'Tweet',
30
+ description: 'The details of single tweet',
31
+ fields: () => ({
32
+ id: { type: GraphQLString },
33
+ tweetBy: {
34
+ type: User,
35
+ resolve: (parent, args, context) => new UserResolver(context).resolveUserDetails('', parent.tweetBy)
36
+ },
37
+ createdAt: { type: GraphQLString },
38
+ entities: { type: TweetTokens },
39
+ quoted: {
40
+ type: Tweet,
41
+ resolve: (parent, args, context) => parent.quoted ? new TweetResolver(context).resolveTweet(parent.quoted) : undefined
42
+ },
43
+ fullText: { type: GraphQLString },
44
+ replyTo: {
45
+ type: Tweet,
46
+ resolve: (parent, args, context) => parent.replyTo ? new TweetResolver(context).resolveTweet(parent.replyTo) : undefined
47
+ },
48
+ lang: { type: GraphQLString },
49
+ quoteCount: { type: GraphQLInt },
50
+ quotes: {
51
+ type: TweetList,
52
+ args: {
53
+ count: {
54
+ type: GraphQLInt,
55
+ description: "The number of quotes to fetch",
56
+ defaultValue: 10
57
+ },
58
+ all: {
59
+ type: GraphQLBoolean,
60
+ description: "Whether to fetch all quotes",
61
+ defaultValue: false
62
+ },
63
+ cursor: {
64
+ type: GraphQLString,
65
+ description: 'The cursor to the batch of quotes list to fetch',
66
+ defaultValue: ''
67
+ }
68
+ },
69
+ resolve: (parent, args, context) => new TweetResolver(context).resolveTweetQuotes(parent.id, args.count, args.all, args.cursor, parent.quoteCount)
70
+ },
71
+ likeCount: { type: GraphQLInt },
72
+ likers: {
73
+ type: UserList,
74
+ args: {
75
+ count: {
76
+ type: GraphQLInt,
77
+ description: "The number of likers to fetch",
78
+ defaultValue: 10
79
+ },
80
+ all: {
81
+ type: GraphQLBoolean,
82
+ description: "Whether to fetch all likers",
83
+ defaultValue: false
84
+ },
85
+ cursor: {
86
+ type: GraphQLString,
87
+ description: 'The cursor to the batch of likers list to fetch',
88
+ defaultValue: ''
89
+ }
90
+ },
91
+ resolve: (parent, args, context) => new TweetResolver(context).resolveTweetLikers(parent.id, args.count, args.all, args.cursor, parent.likeCount)
92
+ },
93
+ retweetCount: { type: GraphQLInt },
94
+ retweeters: {
95
+ type: UserList,
96
+ args: {
97
+ count: {
98
+ type: GraphQLInt,
99
+ description: "The number of retweeters to fetch",
100
+ defaultValue: 10
101
+ },
102
+ all: {
103
+ type: GraphQLBoolean,
104
+ description: "Whether to fetch all likers",
105
+ defaultValue: false
106
+ },
107
+ cursor: {
108
+ type: GraphQLString,
109
+ description: 'The cursor to the batch of retweeters list to fetch',
110
+ defaultValue: ''
111
+ }
112
+ },
113
+ resolve: (parent, args, context) => new TweetResolver(context).resolveTweetRetweeters(parent.id, args.count, args.all, args.cursor, parent.retweetCount)
114
+ },
115
+ replyCount: { type: GraphQLInt },
116
+ replies: {
117
+ type: TweetList,
118
+ args: {
119
+ count: {
120
+ type: GraphQLInt,
121
+ description: "The number of replies to fetch",
122
+ defaultValue: 10
123
+ },
124
+ all: {
125
+ type: GraphQLBoolean,
126
+ description: "Whether to fetch all replies",
127
+ defaultValue: false
128
+ },
129
+ cursor: {
130
+ type: GraphQLString,
131
+ description: 'The cursor to the batch of replies list to fetch',
132
+ defaultValue: ''
133
+ }
134
+ },
135
+ resolve: (parent, args, context) => new TweetResolver(context).resolveTweetReplies(parent.id, args.count, args.all, args.cursor, parent.replyCount)
136
+ }
137
+ })
138
+ });
139
+
140
+ export const TweetList = new GraphQLList(new GraphQLUnionType({
141
+ name: 'TweetCursorUnion',
142
+ description: 'A union type which can either be a Tweet or a Cursor, used in cursored tweet lists',
143
+ types: [Tweet, Cursor],
144
+ resolveType: (data) => {
145
+ // If it has fullText field => this is a Tweet object
146
+ if(data.fullText) {
147
+ return Tweet;
148
+ }
149
+ // If it has a value field => this is a cursor object
150
+ else if(data.value) {
151
+ return Cursor;
152
+ }
153
+ }
154
+ }));
@@ -0,0 +1,137 @@
1
+ // PACKAGE
2
+ import { GraphQLBoolean, GraphQLObjectType, GraphQLString, GraphQLInt, GraphQLList, GraphQLUnionType } from 'graphql';
3
+
4
+ // TYPES
5
+ import { Tweet, TweetList } from './TweetTypes'
6
+ import { Cursor } from './Global';
7
+ import { TweetFilter } from '../../types/Tweet';
8
+
9
+ // RESOLVERS
10
+ import UserResolver from '../../resolvers/UserResolver';
11
+ import TweetResolver from '../../resolvers/TweetResolver';
12
+
13
+ //@ts-ignore
14
+ export const User = new GraphQLObjectType({
15
+ name: 'User',
16
+ description: 'The details of a single target twitter user',
17
+ fields: () => ({
18
+ id: { type: GraphQLString },
19
+ userName: { type: GraphQLString },
20
+ fullName: { type: GraphQLString },
21
+ createdAt: { type: GraphQLString },
22
+ description: { type: GraphQLString },
23
+ isVerified: { type: GraphQLBoolean },
24
+ location: { type: GraphQLString },
25
+ pinnedTweet: {
26
+ type: Tweet,
27
+ resolve: (parent, args, context) => (parent.pinnedTweet) ? new TweetResolver(context).resolveTweet(parent.pinnedTweet) : undefined
28
+ },
29
+ profileBanner: { type: GraphQLString },
30
+ profileImage: { type: GraphQLString },
31
+ favouritesCount: { type: GraphQLInt },
32
+ likes: {
33
+ type: TweetList,
34
+ args: {
35
+ count: {
36
+ description: "The number of liked tweets to fetch",
37
+ type: GraphQLInt,
38
+ defaultValue: 10
39
+ },
40
+ all: {
41
+ description: "Whether to fetch all tweets liked by user",
42
+ type: GraphQLBoolean,
43
+ defaultValue: false
44
+ },
45
+ cursor: {
46
+ type: GraphQLString,
47
+ description: 'The cursor to the batch of likes list to fetch',
48
+ defaultValue: ''
49
+ }
50
+ },
51
+ resolve: (parent, args, context) => new UserResolver(context).resolveUserLikes(parent.id, args.count, args.all, args.cursor, parent.favouritesCount)
52
+ },
53
+ followersCount: { type: GraphQLInt },
54
+ followers: {
55
+ type: UserList,
56
+ args: {
57
+ count: {
58
+ description: "The number of followers to fetch",
59
+ type: GraphQLInt,
60
+ defaultValue: 20
61
+ },
62
+ all: {
63
+ description: "Whether to fetch all followers list",
64
+ type: GraphQLBoolean,
65
+ defaultValue: false
66
+ },
67
+ cursor: {
68
+ type: GraphQLString,
69
+ description: 'The cursor to the batch of followers list to fetch',
70
+ defaultValue: ''
71
+ }
72
+ },
73
+ resolve: (parent, args, context) => new UserResolver(context).resolveUserFollowers(parent.id, args.count, args.all, args.cursor, parent.followersCount)
74
+ },
75
+ followingsCount: { type: GraphQLInt },
76
+ following: {
77
+ type: UserList,
78
+ args: {
79
+ count: {
80
+ type: GraphQLInt,
81
+ description: "The number of followings to fetch",
82
+ defaultValue: 20
83
+ },
84
+ all: {
85
+ description: "Whether to fetch all followings list",
86
+ type: GraphQLBoolean,
87
+ defaultValue: false
88
+ },
89
+ cursor: {
90
+ type: GraphQLString,
91
+ description: 'The cursor to the batch of followers list to fetch',
92
+ defaultValue: ''
93
+ }
94
+ },
95
+ resolve: (parent, args, context) => new UserResolver(context).resolveUserFollowing(parent.id, args.count, args.all, args.cursor, parent.followingsCount)
96
+ },
97
+ statusesCount: { type: GraphQLInt },
98
+ tweets: {
99
+ type: TweetList,
100
+ args: {
101
+ count: {
102
+ description: "The number of tweets to fetch",
103
+ type: GraphQLInt,
104
+ defaultValue: 10
105
+ },
106
+ all: {
107
+ description: "Whether to fetch all tweets made by user",
108
+ type: GraphQLBoolean,
109
+ defaultValue: false
110
+ },
111
+ cursor: {
112
+ type: GraphQLString,
113
+ description: 'The cursor to the batch of tweets list to fetch',
114
+ defaultValue: ''
115
+ }
116
+ },
117
+ resolve: (parent, args, context) => new TweetResolver(context).resolveTweets({ fromUsers: [parent.userName] } as TweetFilter, args.count, args.cursor)
118
+ }
119
+ })
120
+ });
121
+
122
+ //@ts-ignore
123
+ export const UserList = new GraphQLList(new GraphQLUnionType({
124
+ name: 'UserCursorUnion',
125
+ description: 'A union type which can either be a User or a Cursor, used in cursored User lists',
126
+ types: [User, Cursor],
127
+ resolveType: (data) => {
128
+ // If it has a userName field => this is a User object
129
+ if(data.userName) {
130
+ return User;
131
+ }
132
+ // If it has a value field => this is a Cursor object
133
+ else if(data.value) {
134
+ return Cursor;
135
+ }
136
+ }
137
+ }));