Skip to content

Commit 114a575

Browse files
author
Jonathan Visser
committed
Update Twitch GraphQL hashes and add API documentation
Updates operation hashes to match Twitch's latest API changes. Adds JSDoc comments for better IDE support and developer experience. Marks deprecated methods with warnings.
1 parent 42c0983 commit 114a575

5 files changed

Lines changed: 99 additions & 12 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules/
1+
node_modules/
2+
outputs

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const TwitchGQL = {
22
client: require("./src/twitch"),
33
isInitialized: false,
44

5-
Init: (ClientID = "kimne78kx3ncx6brgo4mv6wki5h1ko") => {
5+
Init: (ClientID = "ue6666qo983tsx6so1t0vnawi233wa") => {
66
if (TwitchGQL.isInitialized)
77
return TwitchGQL.client;
88

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/graphql.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ const fetch = require("node-fetch");
22
const fs = require("fs");
33

44
const Operation_Hashes = {
5-
'CollectionSideBar': '27111f1b382effad0b6def325caef1909c733fe6a4fbabf54f8d491ef2cf2f14',
6-
'FilterableVideoTower_Videos': 'a937f1d22e269e39a03b509f65a7490f9fc247d7f83d6ac1421523e3b68042cb',
7-
'ClipsCards__User': 'b73ad2bfaecfd30a9e6c28fada15bd97032c83ec77a0440766a56fe0bd632777',
8-
'ChannelCollectionsContent': '07e3691a1bad77a36aba590c351180439a40baefc1c275356f40fc7082419a84',
9-
'StreamMetadata': '1c719a40e481453e5c48d9bb585d971b8b372f8ebb105b17076722264dfa5b3e',
5+
'CollectionSideBar': '016e1e4ccee0eb4698eb3bf1a04dc1c077fb746c78c82bac9a8f0289658fbd1a',
6+
'FilterableVideoTower_Videos': '67004f7881e65c297936f32c75246470629557a393788fb5a69d6d9a25a8fd5f',
7+
'ClipsCards__User': '90c33f5e6465122fba8f9371e2a97076f9ed06c6fed3788d002ab9eba8f91d88',
8+
'ChannelCollectionsContent': '5247910a19b1cd2b760939bf4cba4dcbd3d13bdf8c266decd16956f6ef814077',
9+
'StreamMetadata': 'b57f9b910f8cd1a4659d894fe7550ccc81ec9052c01e438b290fd66a040b9b93',
1010
'ComscoreStreamingQuery': 'e1edae8122517d013405f237ffcc124515dc6ded82480a88daef69c83b53ac01',
11-
'VideoPreviewOverlay': '3006e77e51b128d838fa4e835723ca4dc9a05c5efd4466c1085215c6e437e65c',
11+
'VideoPreviewOverlay': '9515480dee68a77e667cb19de634739d33f243572b007e98e67184b1a5d8369f',
1212
'PlaybackAccessToken': '0828119ded1c13477966434e15800ff57ddacf13ba1911c129dc2200705b0712',
1313
'VideoPreviewCard__VideoMoments': '0094e99aab3438c7a220c0b1897d144be01954f8b4765b884d330d0c0893dbde',
14-
'VideoMetadata': 'cb3b1eb2f2d2b2f65b8389ba446ec521d76c3aa44f5424a1b1d235fe21eb4806',
14+
'VideoMetadata': '45111672eea2e507f8ba44d101a61862f9c56b11dee09a15634cb75cb9b9084d',
1515
'ChatClip': '9aa558e066a22227c5ef2c0a8fded3aaa57d35181ad15f63df25bff516253a90',
1616
'CategoryTags': "5e639384467cb410fda19531971c8856cf937eb69209a6859fa17fddfce7ee07",
1717
'AllChannels_InternationalSection': "b4706651ded417d9a34ae91c049197c016c496bfdfd58aeb4a5d2dfbb0dcc9e1",
18-
'ClipsCards__User': "4eb8f85fc41a36c481d809e8e99b2a32127fdb7647c336d27743ec4a88c4ea44",
1918
'ClipMetadata': '49817470e0129051cd93c86069aee755795f1a952688f0111bac71a49841ece7',
20-
'ShareClipRenderStatus': 'f130048a462a0ac86bb54d653c968c514e9ab9ca94db52368c1179e97b0f16eb'
19+
'ShareClipRenderStatus': '1844261bb449fa51e6167040311da4a7a5f1c34fe71c71a3e0c4f551bc30c698',
20+
'VideoPlayer_ChapterSelectButtonVideo': '71835d5ef425e154bf282453a926d99b328cdc5e32f36d3a209d0f4778b41203'
2121
};
2222

2323
const GraphQL = {
@@ -59,7 +59,9 @@ const GraphQL = {
5959
for (let i = 0; i < errs.length; i++) {
6060
const err = errs[i];
6161
console.log("ERROR!");
62-
console.log(err);
62+
console.log({err});
63+
64+
throw err;
6365
}
6466
}
6567

src/twitch.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
const GraphQL = require("./graphql");
22

33
const Twitch = {
4+
/**
5+
* Set the Twitch Client ID for API requests
6+
* @param {string} ClientID - The Twitch Client ID
7+
*/
48
SetClientID(ClientID) {
59
GraphQL.ClientID = ClientID;
610
},
11+
/**
12+
* Get user information by login name
13+
* @param {string} login - The Twitch username
14+
* @param {Object} [variables={}] - Additional query variables
15+
* @returns {Promise<Object>} User data
16+
*/
717
GetUser(login, variables = {}) {
818
variables = {...variables, login};
919
return GraphQL.SendQuery("GET_USER", variables);
1020
},
21+
/**
22+
* Get top streams on Twitch
23+
* @deprecated Currently unavailable - Twitch has changed their operation hashes
24+
* @param {number} [amount=25] - Number of streams to fetch
25+
* @param {Object} [variables={}] - Additional query variables
26+
* @returns {Promise<Object>} Top streams data
27+
*/
1128
GetTopStreams(amount = 25, variables = {}) {
29+
console.warn("DEPRECATED: GetTopStreams is currently unavailable. Twitch has changed their operation hashes and this function needs to be updated.");
1230
variables = {
1331
limit: amount,
1432
platformType: "all",
@@ -17,6 +35,12 @@ const Twitch = {
1735
};
1836
return GraphQL.SendQuery("AllChannels_InternationalSection", variables, true);
1937
},
38+
/**
39+
* Get videos/VODs from a channel
40+
* @param {string} login - The channel login name
41+
* @param {Object} [variables={}] - Additional query variables (broadcastType, limit, videoSort, etc.)
42+
* @returns {Promise<Object>} Videos data
43+
*/
2044
GetVideos(login, variables = {}) {
2145
let opts = {
2246
broadcastType: "ARCHIVE",
@@ -27,6 +51,12 @@ const Twitch = {
2751
}
2852
return GraphQL.SendQuery("FilterableVideoTower_Videos", opts, true);
2953
},
54+
/**
55+
* Get playback access token for a VOD
56+
* @param {string} vodID - The VOD ID
57+
* @param {Object} [variables={}] - Additional query variables
58+
* @returns {Promise<Object>} Playback access token data
59+
*/
3060
GetPlaybackAccessToken(vodID, variables = {}) {
3161
let opts = {
3262
isLive: false,
@@ -38,13 +68,26 @@ const Twitch = {
3868
};
3969
return GraphQL.SendQuery("PlaybackAccessToken", opts, true);
4070
},
71+
/**
72+
* Get video moments/highlights for a VOD
73+
* @param {string} vodID - The VOD ID
74+
* @param {Object} [variables={}] - Additional query variables
75+
* @returns {Promise<Object>} Video moments data
76+
*/
4177
GetVideoMoments(vodID, variables = {}) {
4278
let opts = {
4379
videoId: vodID,
4480
...variables
4581
};
4682
return GraphQL.SendQuery("VideoPreviewCard__VideoMoments", opts, true);
4783
},
84+
/**
85+
* Get metadata for a specific video
86+
* @param {string} channelLogin - The channel login name
87+
* @param {string} vodID - The VOD ID
88+
* @param {Object} [variables={}] - Additional query variables
89+
* @returns {Promise<Object>} Video metadata
90+
*/
4891
GetVideoMetadata(channelLogin, vodID, variables = {}) {
4992
let opts = {
5093
channelLogin,
@@ -53,21 +96,42 @@ const Twitch = {
5396
};
5497
return GraphQL.SendQuery("VideoMetadata", opts, true);
5598
},
99+
/**
100+
* Get category tags for a game
101+
* @deprecated Currently unavailable - Twitch has changed their operation hashes
102+
* @param {string} gameName - The name of the game
103+
* @param {Object} [variables={}] - Additional query variables
104+
* @returns {Promise<Object>} Category tags data
105+
*/
56106
GetGameCategoryTags(gameName, variables = {}) {
107+
console.warn("DEPRECATED: GetGameCategoryTags is currently unavailable. Twitch has changed their operation hashes and this function needs to be updated.");
57108
let opts = {
58109
gameName,
59110
tagType: "CONTENT",
60111
...variables
61112
};
62113
return GraphQL.SendQuery("CategoryTags", opts, true);
63114
},
115+
/**
116+
* Get chat messages for a clip
117+
* @param {string} clipSlug - The clip slug/ID
118+
* @param {Object} [variables={}] - Additional query variables
119+
* @returns {Promise<Object>} Chat clip data
120+
*/
64121
GetChatClip(clipSlug, variables = {}) {
65122
let opts = {
66123
clipSlug,
67124
...variables
68125
};
69126
return GraphQL.SendQuery("ChatClip", opts, true);
70127
},
128+
/**
129+
* Get clips for a user
130+
* @param {string} login - The user login name
131+
* @param {string} [filter="ALL_TIME"] - Time filter (ALL_TIME, LAST_DAY, LAST_WEEK, LAST_MONTH)
132+
* @param {number} [limit=20] - Number of clips to fetch
133+
* @returns {Promise<Object>} User clips data
134+
*/
71135
GetClipsCardsUser(login, filter = "ALL_TIME", limit = 20) {
72136
const variables = {
73137
login: login,
@@ -80,18 +144,36 @@ const Twitch = {
80144
};
81145
return GraphQL.SendQuery("ClipsCards__User", variables, true);
82146
},
147+
/**
148+
* Get metadata for a specific clip
149+
* @param {string} clipSlug - The clip slug/ID
150+
* @returns {Promise<Object>} Clip metadata
151+
*/
83152
GetClipMetadata(clipSlug) {
84153
const variables = {
85154
clipSlug
86155
};
87156
return GraphQL.SendQuery("ClipMetadata", variables, true);
88157
},
158+
/**
159+
* Get the render status of a shared clip
160+
* @param {string} slug - The clip slug/ID
161+
* @returns {Promise<Object>} Clip render status data
162+
*/
89163
GetShareClipRenderStatus(slug) {
90164
const variables = {
91165
slug
92166
};
93167
return GraphQL.SendQuery("ShareClipRenderStatus", variables, true);
94168
},
169+
/**
170+
* Internal method to send a custom GraphQL query
171+
* @private
172+
* @param {string} QueryName - The name of the query
173+
* @param {Object|null} [variables=null] - Query variables
174+
* @param {boolean} [preset=false] - Whether to use a preset query
175+
* @returns {Promise<Object>} Query result
176+
*/
95177
_SendQuery(QueryName, variables = null, preset = false) {
96178
return GraphQL.SendQuery(QueryName, variables, preset);
97179
}

0 commit comments

Comments
 (0)