Created
December 10, 2019 13:29
-
-
Save lucas-moraes/1df6e7c4905f6d0502f302598f97945b to your computer and use it in GitHub Desktop.
Consuming GraphQL API v4 from Github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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