Skip to content

Commit c3fc33c

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

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

josh-core/src/query.rs

+26-7
Original file line numberDiff line numberDiff line change
@@ -159,31 +159,50 @@ 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_mirror = cache::Transaction::open(transaction.repo().path(), None)?;
173+
let transaction = cache::Transaction::open(
174+
&transaction
175+
.repo()
176+
.path()
177+
.parent()
178+
.ok_or(josh_error("parent"))?
179+
.join("overlay"),
180+
None,
181+
)?;
182+
transaction.repo().odb()?.add_disk_alternate(
183+
transaction
184+
.repo()
185+
.path()
186+
.parent()
187+
.ok_or(josh_error("parent"))?
188+
.join("mirror")
189+
.join("objects")
190+
.to_str()
191+
.unwrap(),
192+
)?;
174193
let (res, _errors) = juniper::execute_sync(
175-
template,
194+
file,
176195
None,
177196
&graphql::commit_schema(commit_id),
178197
&variables,
179-
&graphql::context(transaction, transaction_overlay),
198+
&graphql::context(transaction, transaction_mirror),
180199
)?;
181200

182201
let j = serde_json::to_string_pretty(&res)?;
183202
return Ok(Some(j));
184203
}
185204
if cmd == "render" {
186-
template.to_string()
205+
file.to_string()
187206
} else {
188207
return Err(josh_error("no such cmd"));
189208
}

tests/proxy/query.t

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
> {{ /with }}
3636
> EOF
3737

38+
Jenkinsfile
3839
$ git add x.graphql
3940
$ git add tmpl_file
4041
$ git commit -m "add tmpl_file" 1> /dev/null
@@ -66,6 +67,15 @@ Now render still works (used to fail if filtered previously)
6667
sha: 890148bbaa6a797bac8aef672a437f2b08635f15
6768
filter_sha: ffe8d082c1034053534ea8068f4205ac72a1098e
6869

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

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

0 commit comments

Comments
 (0)