Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing alternates in graphql endpoint #1228

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions josh-core/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,31 +159,59 @@ pub fn render(
}

let template = if let Ok(blob) = obj.peel_to_blob() {
let template = std::str::from_utf8(blob.content())?;
let file = std::str::from_utf8(blob.content())?;
if cmd == "get" {
return Ok(Some(template.to_string()));
return Ok(Some(file.to_string()));
}
if cmd == "graphql" {
let mut variables = juniper::Variables::new();

for (k, v) in params {
variables.insert(k.to_string(), juniper::InputValue::scalar(v));
}
let transaction = cache::Transaction::open(transaction.repo().path(), None)?;
let transaction_overlay = cache::Transaction::open(transaction.repo().path(), None)?;
let (transaction, transaction_mirror) = if let Ok(to) = cache::Transaction::open(
&transaction
.repo()
.path()
.parent()
.ok_or(josh_error("parent"))?
.join("overlay"),
None,
) {
to.repo().odb()?.add_disk_alternate(
&transaction
.repo()
.path()
.parent()
.ok_or(josh_error("parent"))?
.join("mirror")
.join("objects")
.to_str()
.unwrap(),
)?;
(
to,
cache::Transaction::open(&transaction.repo().path(), None)?,
)
} else {
(
cache::Transaction::open(transaction.repo().path(), None)?,
cache::Transaction::open(transaction.repo().path(), None)?,
)
};
let (res, _errors) = juniper::execute_sync(
template,
file,
None,
&graphql::commit_schema(commit_id),
&variables,
&graphql::context(transaction, transaction_overlay),
&graphql::context(transaction, transaction_mirror),
)?;

let j = serde_json::to_string_pretty(&res)?;
return Ok(Some(j));
}
if cmd == "render" {
template.to_string()
file.to_string()
} else {
return Err(josh_error("no such cmd"));
}
Expand Down
9 changes: 9 additions & 0 deletions tests/proxy/query.t
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ Now render still works (used to fail if filtered previously)
sha: 890148bbaa6a797bac8aef672a437f2b08635f15
filter_sha: ffe8d082c1034053534ea8068f4205ac72a1098e

Graphql works
$ curl -s http://localhost:8002/real_repo.git?graphql=x.graphql
{
"hash": "890148bbaa6a797bac8aef672a437f2b08635f15",
"rev": {
"hash": "ffe8d082c1034053534ea8068f4205ac72a1098e"
}
} (no-eol)


Failing render for lack of variable
$ curl -i -s http://localhost:8002/real_repo.git?render=tmpl_file
Expand Down
Loading