Name: ghql
Owner: rOpenSci
Description: General purpose GraphQL R client
Created: 2016-09-15 20:27:02.0
Updated: 2017-11-22 21:08:27.0
Pushed: 2017-12-14 16:44:37.0
Size: 34
Language: R
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
ghql
- general purpose GraphQL client
GraphQL - http://graphql.org
Examples of GraphQL APIs:
See https://developer.github.com/early-access/graphql/guides/accessing-graphql/ for getting an OAuth token.
Store the token in a env var called GITHUB_GRAPHQL_TOKEN
before trying this pkg.
Development version
ools::install_github("ropensci/ghql")
ary("ghql")
ary("jsonlite")
ary("httr")
n <- Sys.getenv("GITHUB_GRAPHQL_TOKEN")
<- GraphqlClient$new(
l = "https://api.github.com/graphql",
aders = add_headers(Authorization = paste0("Bearer ", token))
Since not every GraphQL server has a schema at the base URL, have to manually load the schema in this case
load_schema()
Make a Query
class object
<- Query$new()
query('myquery', 'query { }')
ghql: query>
queries:
myquery
queries
myquery
query { }
queries$myquery
query { }
exec(qry$queries$myquery)
data
amed list()
Gives back no result, as we didn't ask for anything :)
query('getdozedata', '{
positoryOwner(login:"sckott") {
repositories(first: 5, orderBy: {field:PUSHED_AT,direction:DESC}, isFork:false) {
edges {
node {
name
stargazers {
totalCount
}
}
}
}
ghql: query>
queries:
myquery
getdozedata
queries$getdozedata
{
repositoryOwner(login:"sckott") {
repositories(first: 5, orderBy: {field:PUSHED_AT,direction:DESC}, isFork:false) {
edges {
node {
name
stargazers {
totalCount
}
}
}
}
}
exec(qry$queries$getdozedata)
data
data$repositoryOwner
data$repositoryOwner$repositories
data$repositoryOwner$repositories$edges
node.name node.totalCount
sckott.github.com 8
usdaplantsapistatus 0
usdaplantsapi 19
rforcats 34
soylocs 2
server.js
file from this package located at inst/server.js
somewhere on your machine. Can locate it on your machine like system.file("js/server.js", package = "ghql")
. Or you can run the file from where it's at, up to you.node server.js
<- GraphqlClient$new("http://localhost:4000/graphql"))
ghql client>
url: http://localhost:4000/graphql
<- Query$new()
query('query', '{
schema {
queryType {
name,
fields {
name,
description
}
}
exec(xxx$queries$query)
data
data$`__schema`
data$`__schema`$queryType
data$`__schema`$queryType$name
1] "Query"
data$`__schema`$queryType$fields
name description
hello
name