Skip to content

Commit 6413f1e

Browse files
authored
Fix missing alternates in graphql endpoint (#1228)
The GET endpoint for graphql was broken Change: graphql-alternate
1 parent c0a170a commit 6413f1e

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

josh-core/src/query.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,31 +159,59 @@ pub fn render(
159159
}
160160

161161
let template = if let Ok(blob) = obj.peel_to_blob() {
162-
let template = std::str::from_utf8(blob.content())?;
162+
let file = std::str::from_utf8(blob.content())?;
163163
if cmd == "get" {
164-
return Ok(Some(template.to_string()));
164+
return Ok(Some(file.to_string()));
165165
}
166166
if cmd == "graphql" {
167167
let mut variables = juniper::Variables::new();
168168

169169
for (k, v) in params {
170170
variables.insert(k.to_string(), juniper::InputValue::scalar(v));
171171
}
172-
let transaction = cache::Transaction::open(transaction.repo().path(), None)?;
173-
let transaction_overlay = cache::Transaction::open(transaction.repo().path(), None)?;
172+
let (transaction, transaction_mirror) = if let Ok(to) = cache::Transaction::open(
173+
&transaction
174+
.repo()
175+
.path()
176+
.parent()
177+
.ok_or(josh_error("parent"))?
178+
.join("overlay"),
179+
None,
180+
) {
181+
to.repo().odb()?.add_disk_alternate(
182+
&transaction
183+
.repo()
184+
.path()
185+
.parent()
186+
.ok_or(josh_error("parent"))?
187+
.join("mirror")
188+
.join("objects")
189+
.to_str()
190+
.unwrap(),
191+
)?;
192+
(
193+
to,
194+
cache::Transaction::open(&transaction.repo().path(), None)?,
195+
)
196+
} else {
197+
(
198+
cache::Transaction::open(transaction.repo().path(), None)?,
199+
cache::Transaction::open(transaction.repo().path(), None)?,
200+
)
201+
};
174202
let (res, _errors) = juniper::execute_sync(
175-
template,
203+
file,
176204
None,
177205
&graphql::commit_schema(commit_id),
178206
&variables,
179-
&graphql::context(transaction, transaction_overlay),
207+
&graphql::context(transaction, transaction_mirror),
180208
)?;
181209

182210
let j = serde_json::to_string_pretty(&res)?;
183211
return Ok(Some(j));
184212
}
185213
if cmd == "render" {
186-
template.to_string()
214+
file.to_string()
187215
} else {
188216
return Err(josh_error("no such cmd"));
189217
}

tests/proxy/query.t

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ Now render still works (used to fail if filtered previously)
6666
sha: 890148bbaa6a797bac8aef672a437f2b08635f15
6767
filter_sha: ffe8d082c1034053534ea8068f4205ac72a1098e
6868

69+
Graphql works
70+
$ curl -s http://localhost:8002/real_repo.git?graphql=x.graphql
71+
{
72+
"hash": "890148bbaa6a797bac8aef672a437f2b08635f15",
73+
"rev": {
74+
"hash": "ffe8d082c1034053534ea8068f4205ac72a1098e"
75+
}
76+
} (no-eol)
77+
6978

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

0 commit comments

Comments
 (0)