According to the GraphQL spec, comments can be added to queries using #
(like in R). Unfortunately, adding comments within the string results in an error "unexpected end of document" when executing the query (adding the query to the Query object works). I tried the reprex queries with and without comments in the GitHub Explorer respectively the GitLab GraphiQL Explorer where they work.
I also ran the following query (adapted from the GitLab Get started) in my zsh shell with curl and it worked.
GRAPHQL_TOKEN="mytoken"
curl "https://gitlab.com/api/graphql" --header "Authorization: Bearer $GRAPHQL_TOKEN" --header "Content-Type
: application/json" --request POST --data "{\"query\": \"query {currentUser {name}}\n #a comment\"}"
Why do I think this is an important feature given comments are not really necessary to the functionality of this package? Well, I wrote a blog post with ghql
and wanted to explain the increasingly complex queries in-code (see especially the query for step 2 in the blog post).
If you think this is a good idea, I'd be happy to have a look myself and try to fix this :)
If i overlooked a function argument that would have enabled this, please let me know. ๐
Session Info
devtools::session_info()
#> โ Session info โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#> setting value
#> version R version 4.0.3 (2020-10-10)
#> os macOS Catalina 10.15.7
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Berlin
#> date 2021-01-22
#>
#> โ Packages โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.2)
#> callr 3.5.1 2020-10-13 [1] CRAN (R 4.0.2)
#> cli 2.2.0 2020-11-20 [1] CRAN (R 4.0.2)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.2)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.2)
#> devtools 2.3.2 2020-09-18 [1] CRAN (R 4.0.2)
#> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.2)
#> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.2)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.1)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.2)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2)
#> highr 0.8 2019-03-20 [1] CRAN (R 4.0.2)
#> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.2)
#> knitr 1.30 2020-09-22 [1] CRAN (R 4.0.2)
#> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.2)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.2)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.2)
#> pkgbuild 1.1.0 2020-07-13 [1] CRAN (R 4.0.2)
#> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.2)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.2)
#> processx 3.4.4 2020-09-03 [1] CRAN (R 4.0.2)
#> ps 1.4.0 2020-10-07 [1] CRAN (R 4.0.2)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.2)
#> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.2)
#> remotes 2.2.0 2020-07-21 [1] CRAN (R 4.0.2)
#> rlang 0.4.10 2020-12-30 [1] CRAN (R 4.0.2)
#> rmarkdown 2.6.4 2020-12-23 [1] Github (rstudio/rmarkdown@5c0aeb0)
#> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.0.2)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.2)
#> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.2)
#> testthat 3.0.0 2020-10-31 [1] CRAN (R 4.0.2)
#> usethis 2.0.0 2020-12-10 [1] CRAN (R 4.0.2)
#> withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.2)
#> xfun 0.20 2021-01-06 [1] CRAN (R 4.0.2)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.2)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
Created on 2021-01-22 by the reprex package (v0.3.0)
library(ghql)
token <- Sys.getenv("GITHUB_GRAPHQL_TOKEN")
con_gh <- GraphqlClient$new(
url = "https://api.github.com/graphql",
headers = list(Authorization = paste0("Bearer ", token))
)
con_gh$load_schema()
# without comment - works
qry_gh <- Query$new()
qry_gh$query('mydata', '{
repositoryOwner(login:"friep") {
repositories(first: 5, orderBy: {field:PUSHED_AT,direction:DESC}, isFork:false) {
edges {
node {
name
stargazers {
totalCount
}
}
}
}
}
}')
(x <- con_gh$exec(qry_gh$queries$mydata))
#> [1] "{\"data\":{\"repositoryOwner\":{\"repositories\":{\"edges\":[{\"node\":{\"name\":\"correlaid-utils\",\"stargazers\":{\"totalCount\":2}}},{\"node\":{\"name\":\"correlaid_md-ii\",\"stargazers\":{\"totalCount\":0}}},{\"node\":{\"name\":\"vaccc19de\",\"stargazers\":{\"totalCount\":4}}},{\"node\":{\"name\":\"vaccc19de_dashboard\",\"stargazers\":{\"totalCount\":6}}},{\"node\":{\"name\":\"hugo-website\",\"stargazers\":{\"totalCount\":0}}}]}}}}\n"
jsonlite::fromJSON(x)
#> $data
#> $data$repositoryOwner
#> $data$repositoryOwner$repositories
#> $data$repositoryOwner$repositories$edges
#> node.name node.totalCount
#> 1 correlaid-utils 2
#> 2 correlaid_md-ii 0
#> 3 vaccc19de 4
#> 4 vaccc19de_dashboard 6
#> 5 hugo-website 0
# with comment(s) - unexpected end of document
qry_gh$query('mydata_with_comment', '{
repositoryOwner(login:"friep") {
# lets get all the repositories
repositories(first: 5, orderBy: {field:PUSHED_AT,direction:DESC}, isFork:false) {
edges {
node {
name
stargazers {
totalCount
}
}
}
}
}
}')
(x <- con_gh$exec(qry_gh$queries$mydata_with_comment))
#> [1] "{\"errors\":[{\"message\":\"Unexpected end of document\"}]}\n"
jsonlite::fromJSON(x)
#> $errors
#> message
#> 1 Unexpected end of document
# GITLAB
token_gl <- Sys.getenv("GITLAB_GRAPHQL_TOKEN")
con_gl <- GraphqlClient$new(
url = "https://gitlab.com/api/graphql",
headers = list(Authorization = paste0("Bearer ", token_gl))
)
# without comment - works
qry_gl <- Query$new()
qry_gl$query('user_gitlab', '{
user(username:"friep") {
id
name
username
}
}')
(x <- con_gl$exec(qry_gl$queries$user_gitlab))
#> [1] "{\"data\":{\"user\":{\"id\":\"gid://gitlab/User/2373431\",\"name\":\"Frie\",\"username\":\"friep\"}}}"
jsonlite::fromJSON(x)
#> $data
#> $data$user
#> $data$user$id
#> [1] "gid://gitlab/User/2373431"
#>
#> $data$user$name
#> [1] "Frie"
#>
#> $data$user$username
#> [1] "friep"
# with comment - again, unexpected document
qry_gl$query('user_gitlab_comments', '{
# lets get the current user
user(username:"friep") {
id
name
username
}
}')
(x <- con_gl$exec(qry_gl$queries$user_gitlab_comments))
#> [1] "{\"errors\":[{\"message\":\"Unexpected end of document\",\"locations\":[]}]}"
jsonlite::fromJSON(x)
#> $errors
#> message locations
#> 1 Unexpected end of document NULL
# inline comments also don't work :(
qry_gl$query('user_gitlab_comments_2', '{
user(username:"friep") {
id
name # inline comment
username
}
}')
(x <- con_gl$exec(qry_gl$queries$user_gitlab_comments_2))
#> [1] "{\"errors\":[{\"message\":\"Unexpected end of document\",\"locations\":[]}]}"
jsonlite::fromJSON(x)
#> $errors
#> message locations
#> 1 Unexpected end of document NULL
Created on 2021-01-22 by the reprex package (v0.3.0)