Skip to content

Instantly share code, notes, and snippets.

@lucas-moraes
Created December 10, 2019 13:29
Show Gist options
  • Save lucas-moraes/1df6e7c4905f6d0502f302598f97945b to your computer and use it in GitHub Desktop.
Save lucas-moraes/1df6e7c4905f6d0502f302598f97945b to your computer and use it in GitHub Desktop.
Consuming GraphQL API v4 from Github
# Before deploying, you need generate a Personal Access Token from Github
const token = gitpass;
fetch("https://api.github.com/graphql", {
method: "POST",
body: JSON.stringify({
query: `query{ viewer { repositories(first:100 isFork:false privacy:PUBLIC) { nodes { name } } } }`
}),
headers: {
Authorization: `Bearer ${token}`
}
})
.then(res => res.text())
.then(body => {
const base = JSON.parse(body);
let projects = base.data.viewer.repositories.nodes;
console.log(projects);
})
.catch(error => console.error(error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment