Skip to content

Instantly share code, notes, and snippets.

@maxgfr
Last active January 2, 2022 19:02
Show Gist options
  • Save maxgfr/af22762bb2259426481da86cc9fdc3fd to your computer and use it in GitHub Desktop.
Save maxgfr/af22762bb2259426481da86cc9fdc3fd to your computer and use it in GitHub Desktop.
Fetch graphql twitch by game
const fetch = require('node-fetch')
const QUERY = (name) => `
query {
game(name: "${name}") {
id
name
streams(first: 50) {
edges {
node {
id
viewersCount
broadcaster {
id
displayName
broadcastSettings {
title
}
}
}
}
}
}
}
`;
const SECOND_QUERY = () => `
query {
directory(name: "dofus", type: GAME) {
id
name
broadcastersCount
viewersCount
streams {
edges {
node {
broadcaster {
login
}
viewersCount
}
}
}
}
}
`;
const THIRD_QUERY = () => `
query {
searchCategories(query: "", first: 50, after: "MTA1") {
totalCount
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
cursor
node {
id
name
}
}
}
}
`;
async function root() {
const response = await fetch('https://gql.twitch.tv/gql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
"Authorization": "OAuth ",
"Client-Id": "",
},
body: JSON.stringify({
query: QUERY('call of duty: warzone'),
}),
});
const body = await response.json();
for (let i = 0; i < body.data.game.streams.edges.length; i++) {
const obj = body.data.game.streams.edges[i]
console.log(obj)
}
}
root()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment