ropensci/ghql

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

Homepage:

Size: 34

Language: R

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ghql

Build Status codecov.io

ghql - general purpose GraphQL client

GraphQL - http://graphql.org

Examples of GraphQL APIs:

Github Authentication

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.

Install

Development version

ools::install_github("ropensci/ghql")

ary("ghql")
ary("jsonlite")
initialize client
ary("httr")
n <- Sys.getenv("GITHUB_GRAPHQL_TOKEN")
<- GraphqlClient$new(
l = "https://api.github.com/graphql",
aders = add_headers(Authorization = paste0("Bearer ", token))

load schema

Since not every GraphQL server has a schema at the base URL, have to manually load the schema in this case

load_schema()
basic query

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 :)

Get some actual data
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
run a local GraphQL server
 <- 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 
Meta

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.