twitch-gql-queries-all
v1.0.4-202610290054
Published
Type-safe requests to twitch public GraphQL API
Downloads
402
Readme
twitch-gql-queries
Type-safe requests to twitch public GraphQL API
Try right in the browser:
Features
- OpenAPI schemas for all queries: Variables and Response
- Autogenerated types from
__typenamefields of real responses - Examples of field values from real responses
- Always up to date - all queries are tested on schedule using real requests
See also: twitch-api-swagger
TypeScript
Installation
npm i twitch-gql-queries
# all queries, including not validated ones, much bigger size
npm i twitch-gql-queries-allUsage
import {
ClipsCardsUserQuery,
FFZRecentBroadcastsQuery,
StreamMetadataQuery,
UseViewCountQuery,
getQuery,
gqlRequest,
} from "twitch-gql-queries";
const [
streamMetadataResponse,
ffzRecentBroadcastsResponse,
clipsCardsUserResponse,
] = await gqlRequest([
getQuery(StreamMetadataQuery, { channelLogin: "xqc" }),
getQuery(FFZRecentBroadcastsQuery, {
id: "71092938",
sort: "time",
limit: 5,
}),
getQuery(ClipsCardsUserQuery, {
login: "xqc",
limit: 30,
criteria: { filter: "LAST_MONTH" },
}),
]);
console.log({
streamMetadataResponse,
ffzRecentBroadcastsResponse,
clipsCardsUserResponse,
});
const channels = await gqlRequest(
["lirik", "forsen"].map((channelLogin) =>
getQuery(UseViewCountQuery, { channelLogin }),
),
);
console.log(channels);Using raw queries:
import {
getRawQuery,
gqlRequest,
type GetRawQueryReturnType,
} from "twitch-gql-queries";
const query = `
query GetVideo($videoId: ID!) {
video(id: $videoId) {
id
title
game {
id
name
}
}
}`;
type GetVideoData = {
video: {
id: string;
title: string;
game: null | {
id: string;
name: string;
};
};
};
const getQueryGetVideo = (variables: { videoId: string }) =>
({ query, variables }) as GetRawQueryReturnType<GetVideoData>;
const responses = await gqlRequest([
getRawQuery<GetVideoData>({
query,
variables: { videoId: "1622426365" },
}),
getQueryGetVideo({ videoId: "1816688726" }),
]);
console.log(responses);Available queries
- BitsConfigContext_Global
- BrowsePage_AllDirectories
- ChannelRoot_AboutPanel
- ChannelShell
- ChannelVideoShelvesQuery
- ChatList_Badges
- ClipsCards__Game
- ClipsCards__User
- ClipsDownloadButton
- DirectoryPage_Game
- FFZ_RecentBroadcasts
- FilterableVideoTower_Videos
- GetPinnedChat
- GetUserID
- GlobalBadges
- PlaybackAccessToken
- SearchResultsPage_SearchResults
- SearchTray_SearchSuggestions
- ShareClipRenderStatus
- StreamMetadata
- UseLive
- UseViewCount
- VideoAccessToken_Clip
- VideoMetadata
- VideoPreviewOverlay
