Query | R Documentation |
ghql query class
a 'Query' class (R6 class)
queries
(list) list of queries
print()
print method for the 'Query' class
Query$print(x, ...)
x
self
...
ignored
query()
define query in a character string
Query$query(name, x)
name
(character) name of the query
x
(character) the query
nothing returned; sets query with 'name' internally
add_fragment()
add a fragment to a query
Query$add_fragment(query_name, fragment)
query_name
(character) the query name to add the fragment to
fragment
(character) the fragment itself
nothing returned; sets the fragment with the query
parse2json()
parse query string with libgraphqlparser and get back JSON
Query$parse2json(query, parse_schema = FALSE)
query
(character) a query to parse
parse_schema
(logical) enable schema definition parsing? default: 'FAlSE'
adf
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
# 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_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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.