Skip to content

Commit fc9fbd9

Browse files
committed
Fix missing alternates in graphql endpoint
The GET endpoint for graphql was broken Change: graphql-alternate
1 parent c0a170a commit fc9fbd9

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

josh-core/src/query.rs

+44-7
Original file line numberDiff line numberDiff line change
@@ -159,31 +159,68 @@ 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(
195+
&transaction
196+
.repo()
197+
.path()
198+
.parent()
199+
.ok_or(josh_error("parent"))?
200+
.join("mirror")
201+
.join("objects"),
202+
None,
203+
)?,
204+
)
205+
} else {
206+
(
207+
cache::Transaction::open(transaction.repo().path(), None)?,
208+
cache::Transaction::open(transaction.repo().path(), None)?,
209+
)
210+
};
174211
let (res, _errors) = juniper::execute_sync(
175-
template,
212+
file,
176213
None,
177214
&graphql::commit_schema(commit_id),
178215
&variables,
179-
&graphql::context(transaction, transaction_overlay),
216+
&graphql::context(transaction, transaction_mirror),
180217
)?;
181218

182219
let j = serde_json::to_string_pretty(&res)?;
183220
return Ok(Some(j));
184221
}
185222
if cmd == "render" {
186-
template.to_string()
223+
file.to_string()
187224
} else {
188225
return Err(josh_error("no such cmd"));
189226
}

tests/proxy/query.t

+9
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)