-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_graphql.r
More file actions
47 lines (38 loc) 路 1.07 KB
/
Copy pathgithub_graphql.r
File metadata and controls
47 lines (38 loc) 路 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Removing currently stored variables (ex.: from previous sessions)
rm(list=ls())
# Importing Libraries
library("ghql")
library("jsonlite")
library("dplyr")
# Private GitHub Token ( create your own here: https://github.com/settings/tokens/new )
token <- "<token>"
# GraphQL Connection Object (GitHub)
connection <- GraphqlClient$new(
url = "https://api.github.com/graphql",
headers = list(Authorization = paste0("Bearer ", token))
)
# GitHub Server doesn't has a schema at the base URL, have to manually load the schema in this case
connection$load_schema()
# Creating new Query
new_query <- Query$new()
# GraphQL Query
new_query$query('mydata', '{
repositoryOwner(login:"Luzkan") {
repositories(first: 5, orderBy: {field:PUSHED_AT,direction:DESC}, isFork:false) {
edges {
node {
name
stargazers {
totalCount
}
}
}
}
}
}')
# Execute Query
(result <- connection$exec(new_query$queries$mydata))
# Parse to more human readable form
jsonlite::fromJSON(result)
# Writing to file
write(result, "output.json")