Query: Query

Description Value Public fields Methods Note Examples

Description

ghql query class

Value

a 'Query' class (R6 class)

Public fields

queries

(list) list of queries

Methods

Public methods


Method print()

print method for the 'Query' class

Usage
Query$print(x, ...)
Arguments
x

self

...

ignored


Method query()

define query in a character string

Usage
Query$query(name, x)
Arguments
name

(character) name of the query

x

(character) the query

Returns

nothing returned; sets query with 'name' internally


Method add_fragment()

add a fragment to a query

Usage
Query$add_fragment(query_name, fragment)
Arguments
query_name

(character) the query name to add the fragment to

fragment

(character) the fragment itself

Returns

nothing returned; sets the fragment with the query


Method parse2json()

parse query string with libgraphqlparser and get back JSON

Usage
Query$parse2json(query, parse_schema = FALSE)
Arguments
query

(character) a query to parse

parse_schema

(logical) enable schema definition parsing? default: 'FAlSE'

Returns

adf

Note

we run an internal method 'check_query()' that runs the public method ‘parse2json()' - if the query doesn’t pass the libgraphqlparser parser, we return the error message

Examples

  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
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
# make a client
qry <- Query$new()

## define query
qry$query('query2', '{
  viewer {
    repositories(last: 10, isFork: false, privacy: PUBLIC) {
      edges {
        node {
          isPrivate
          id
          name
        }
      }
    }
  }
}')
qry
qry$queries
qry$queries$query2

# fragments
## by hand
qry$query('querywithfrag', '{
  ropensci: repositoryOwner(login:"ropensci") {
    repositories(first: 3) {
      edges {
        node {
          ...Watchers
        }
      }
    }
  }
  ropenscilabs: repositoryOwner(login:"ropenscilabs") {
    repositories(first: 3) {
      edges {
        node {
          ...Watchers
        }
      }
    }
  }
}
fragment Watchers on Repository {
  watchers(first: 3) {
    edges {
      node {
        name
      }
    }
  }
}')
qry
qry$queries
qry$queries$querywithfrag


## Not run: 
token <- Sys.getenv("GITHUB_GRAPHQL_TOKEN")
con <- GraphqlClient$new(
  url = "https://api.github.com/graphql",
  headers = list(Authorization = paste0("Bearer ", token))
)
jsonlite::fromJSON(con$exec(qry$queries$querywithfrag))

## use Fragment class fragments generator
### define query without fragment, but referring to it
qry$query('queryfrag', '{
  ropensci: repositoryOwner(login:"ropensci") {
    repositories(first: 3) {
      edges {
        node {
          ...Watchers
        }
      }
    }
  }
  ropenscilabs: repositoryOwner(login:"ropenscilabs") {
    repositories(first: 3) {
      edges {
        node {
          ...Watchers
        }
      }
    }
  }
}')

### define a fragment, and use it later
frag <- Fragment$new()
frag$fragment('Watchers', '
  fragment on Repository {
    watchers(first: 3) {
      edges {
        node {
          name
       }
    }
  }
}')
frag$fragments
frag$fragments$Watchers

### add the fragment to the query 'queryfrag'
qry$add_fragment('queryfrag', frag$fragments$Watchers)
qry
qry$queries
qry$queries$queryfrag

## End(Not run)

ghql documentation built on March 26, 2020, 6:26 p.m.