Skip to content

Commit

Permalink
Fixed bug in .makeAndEvalQuery
Browse files Browse the repository at this point in the history
Function now receives environment from calling
function.
  • Loading branch information
daynefiler committed Dec 3, 2021
1 parent 2495105 commit 51f7517
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/convertVariantIds.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ convertVariantIds <- function(varids, genomes) {
}}
}}
'
rsp <- .makeAndEvalQuery(qfmt)
rsp <- .makeAndEvalQuery(qfmt, environment())
if (is(rsp, 'try-error')) return(rsp)
res <- fromJSON(rsp, flatten = TRUE)$data
res
Expand Down
4 changes: 2 additions & 2 deletions R/getVariantPopData.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ getVariantPopData <- function(varids, genomes) {
gmCon <- GraphqlClient$new(url = apiUrl())
datasets <- getDatasets(genomes)
qfmt <-
'
'
{genomes}_{gsub("-", "_", varids)}:
variant(variantId: "{varids}", dataset: {datasets}) {{
variantId
Expand All @@ -38,7 +38,7 @@ getVariantPopData <- function(varids, genomes) {
}}
}}
'
rsp <- .makeAndEvalQuery(qfmt)
rsp <- .makeAndEvalQuery(qfmt, environment())
if (is(rsp, 'try-error')) return(rsp)
resLst <- fromJSON(rsp, flatten = TRUE)$data
procPopData <- function(x) {
Expand Down
2 changes: 1 addition & 1 deletion R/getVariantsFromRegion.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ getVariantsFromRegion <- function(genomes, chroms, starts, stops = starts) {
}}
}}
'
rsp <- .makeAndEvalQuery(qfmt)
rsp <- .makeAndEvalQuery(qfmt, environment())
if (is(rsp, 'try-error')) return(rsp)
res <- lapply(fromJSON(rsp)$data, "[[", 1)
res
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ getLiftoverIdName <- function(genomes) {
#' @importFrom glue glue glue_collapse
#' @import ghql

.makeAndEvalQuery <- function(qfmt, maxTries = 3) {
.makeAndEvalQuery <- function(qfmt, genv, maxTries = 3) {
gmCon <- GraphqlClient$new(url = apiUrl())
qryBody <- glue_collapse(glue(qfmt), sep = "\n")
qryBody <- glue_collapse(glue(qfmt, .envir = genv), sep = "\n")
qry <- Query$new()$query('q', glue('query {{ {qryBody} }}'))
tries <- 1
repeat {
Expand Down

0 comments on commit 51f7517

Please sign in to comment.