R/R6-7-response.R

Defines functions result_as_json

result_as_json <- function(result, ...) {

  ret <- list(data = result$data)

  if (result$error_list$has_any_errors()) {
    # nolint start
    # # should be
    # list(
    #   list(
    #     message = "asdf",
    #     locations = list(
    #       line = 1,
    #       column = 1
    #     )
    #   ),
    #   ...
    # )
    # nolint end
    ret$errors <- lapply(result$error_list$errors, function(e) {
      list(message = e)
    })
  }

  ret %>%
    to_json(...)
}
schloerke/graphqlr documentation built on Dec. 7, 2022, 10:57 a.m.