Skip to content

Commit e0d037c

Browse files
Introduce "rev" method on GraphQL mutations (#1146)
This makes the mutations API more similar to the query API Change: graphql-mut-rev
1 parent 13e7565 commit e0d037c

File tree

3 files changed

+176
-131
lines changed

3 files changed

+176
-131
lines changed

src/graphql.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -871,33 +871,17 @@ fn format_marker(input: &str) -> JoshResult<String> {
871871
Ok(format!("{}:{}", &hash, &line))
872872
}
873873

874-
#[graphql_object(context = Context)]
875-
impl RepositoryMut {
876-
fn meta(
877-
&self,
878-
commit: String,
879-
topic: String,
880-
add: Vec<MarkersInput>,
881-
context: &Context,
882-
) -> FieldResult<bool> {
883-
{
884-
let mut allow_refs = context.allow_refs.lock()?;
885-
if !*allow_refs {
886-
*allow_refs = true;
887-
return Err(josh_error("ref query not allowed").into());
888-
};
889-
}
890-
let transaction_mirror = context.transaction_mirror.lock()?;
891-
892-
// Just check that the commit exists
893-
transaction_mirror
894-
.repo()
895-
.find_commit(git2::Oid::from_str(&commit)?)?;
874+
struct RevMut {
875+
at: String,
876+
}
896877

878+
#[graphql_object(context = Context)]
879+
impl RevMut {
880+
fn meta(&self, topic: String, add: Vec<MarkersInput>, context: &Context) -> FieldResult<bool> {
897881
if let Ok(mut meta_add) = context.meta_add.lock() {
898882
for mm in add {
899883
let path = mm.path;
900-
let path = &marker_path(&commit, &topic).join(path);
884+
let path = &marker_path(&self.at, &topic).join(path);
901885
let mut lines = meta_add.get(path).unwrap_or(&vec![]).clone();
902886

903887
let mm = mm
@@ -919,6 +903,27 @@ impl RepositoryMut {
919903
}
920904
}
921905

906+
#[graphql_object(context = Context)]
907+
impl RepositoryMut {
908+
fn rev(at: String, context: &Context) -> FieldResult<RevMut> {
909+
{
910+
let mut allow_refs = context.allow_refs.lock()?;
911+
if !*allow_refs {
912+
*allow_refs = true;
913+
return Err(josh_error("ref query not allowed").into());
914+
};
915+
}
916+
let transaction_mirror = context.transaction_mirror.lock()?;
917+
918+
// Just check that the commit exists
919+
transaction_mirror
920+
.repo()
921+
.find_commit(git2::Oid::from_str(&at)?)?;
922+
923+
Ok(RevMut { at: at })
924+
}
925+
}
926+
922927
#[graphql_object(context = Context)]
923928
impl Repository {
924929
fn name(&self) -> &str {

tests/proxy/graphql_schema.t

Lines changed: 121 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,7 @@
119119
{
120120
"defaultValue": null,
121121
"description": null,
122-
"name": "commit",
123-
"type": {
124-
"kind": "NON_NULL",
125-
"name": null,
126-
"ofType": {
127-
"kind": "SCALAR",
128-
"name": "String",
129-
"ofType": null
130-
}
131-
}
132-
},
133-
{
134-
"defaultValue": null,
135-
"description": null,
136-
"name": "topic",
122+
"name": "at",
137123
"type": {
138124
"kind": "NON_NULL",
139125
"name": null,
@@ -143,40 +129,18 @@
143129
"ofType": null
144130
}
145131
}
146-
},
147-
{
148-
"defaultValue": null,
149-
"description": null,
150-
"name": "add",
151-
"type": {
152-
"kind": "NON_NULL",
153-
"name": null,
154-
"ofType": {
155-
"kind": "LIST",
156-
"name": null,
157-
"ofType": {
158-
"kind": "NON_NULL",
159-
"name": null,
160-
"ofType": {
161-
"kind": "INPUT_OBJECT",
162-
"name": "MarkersInput",
163-
"ofType": null
164-
}
165-
}
166-
}
167-
}
168132
}
169133
],
170134
"deprecationReason": null,
171135
"description": null,
172136
"isDeprecated": false,
173-
"name": "meta",
137+
"name": "rev",
174138
"type": {
175139
"kind": "NON_NULL",
176140
"name": null,
177141
"ofType": {
178-
"kind": "SCALAR",
179-
"name": "Boolean",
142+
"kind": "OBJECT",
143+
"name": "RevMut",
180144
"ofType": null
181145
}
182146
}
@@ -1583,6 +1547,80 @@
15831547
"name": "Document",
15841548
"possibleTypes": null
15851549
},
1550+
{
1551+
"description": null,
1552+
"enumValues": null,
1553+
"fields": [
1554+
{
1555+
"args": [
1556+
{
1557+
"defaultValue": null,
1558+
"description": null,
1559+
"name": "topic",
1560+
"type": {
1561+
"kind": "NON_NULL",
1562+
"name": null,
1563+
"ofType": {
1564+
"kind": "SCALAR",
1565+
"name": "String",
1566+
"ofType": null
1567+
}
1568+
}
1569+
},
1570+
{
1571+
"defaultValue": null,
1572+
"description": null,
1573+
"name": "add",
1574+
"type": {
1575+
"kind": "NON_NULL",
1576+
"name": null,
1577+
"ofType": {
1578+
"kind": "LIST",
1579+
"name": null,
1580+
"ofType": {
1581+
"kind": "NON_NULL",
1582+
"name": null,
1583+
"ofType": {
1584+
"kind": "INPUT_OBJECT",
1585+
"name": "MarkersInput",
1586+
"ofType": null
1587+
}
1588+
}
1589+
}
1590+
}
1591+
}
1592+
],
1593+
"deprecationReason": null,
1594+
"description": null,
1595+
"isDeprecated": false,
1596+
"name": "meta",
1597+
"type": {
1598+
"kind": "NON_NULL",
1599+
"name": null,
1600+
"ofType": {
1601+
"kind": "SCALAR",
1602+
"name": "Boolean",
1603+
"ofType": null
1604+
}
1605+
}
1606+
}
1607+
],
1608+
"inputFields": null,
1609+
"interfaces": [],
1610+
"kind": "OBJECT",
1611+
"name": "RevMut",
1612+
"possibleTypes": null
1613+
},
1614+
{
1615+
"description": null,
1616+
"enumValues": null,
1617+
"fields": null,
1618+
"inputFields": null,
1619+
"interfaces": null,
1620+
"kind": "SCALAR",
1621+
"name": "Int",
1622+
"possibleTypes": null
1623+
},
15861624
{
15871625
"description": null,
15881626
"enumValues": null,
@@ -1682,16 +1720,6 @@
16821720
"name": "__Schema",
16831721
"possibleTypes": null
16841722
},
1685-
{
1686-
"description": null,
1687-
"enumValues": null,
1688-
"fields": null,
1689-
"inputFields": null,
1690-
"interfaces": null,
1691-
"kind": "SCALAR",
1692-
"name": "Int",
1693-
"possibleTypes": null
1694-
},
16951723
{
16961724
"description": null,
16971725
"enumValues": null,
@@ -1701,13 +1729,13 @@
17011729
"deprecationReason": null,
17021730
"description": null,
17031731
"isDeprecated": false,
1704-
"name": "name",
1732+
"name": "path",
17051733
"type": {
17061734
"kind": "NON_NULL",
17071735
"name": null,
17081736
"ofType": {
1709-
"kind": "SCALAR",
1710-
"name": "String",
1737+
"kind": "OBJECT",
1738+
"name": "Path",
17111739
"ofType": null
17121740
}
17131741
}
@@ -1717,25 +1745,48 @@
17171745
"deprecationReason": null,
17181746
"description": null,
17191747
"isDeprecated": false,
1720-
"name": "description",
1748+
"name": "matches",
17211749
"type": {
1722-
"kind": "SCALAR",
1723-
"name": "String",
1724-
"ofType": null
1750+
"kind": "NON_NULL",
1751+
"name": null,
1752+
"ofType": {
1753+
"kind": "LIST",
1754+
"name": null,
1755+
"ofType": {
1756+
"kind": "NON_NULL",
1757+
"name": null,
1758+
"ofType": {
1759+
"kind": "OBJECT",
1760+
"name": "SearchMatch",
1761+
"ofType": null
1762+
}
1763+
}
1764+
}
17251765
}
1726-
},
1766+
}
1767+
],
1768+
"inputFields": null,
1769+
"interfaces": [],
1770+
"kind": "OBJECT",
1771+
"name": "SearchResult",
1772+
"possibleTypes": null
1773+
},
1774+
{
1775+
"description": null,
1776+
"enumValues": null,
1777+
"fields": [
17271778
{
17281779
"args": [],
17291780
"deprecationReason": null,
17301781
"description": null,
17311782
"isDeprecated": false,
1732-
"name": "isDeprecated",
1783+
"name": "name",
17331784
"type": {
17341785
"kind": "NON_NULL",
17351786
"name": null,
17361787
"ofType": {
17371788
"kind": "SCALAR",
1738-
"name": "Boolean",
1789+
"name": "String",
17391790
"ofType": null
17401791
}
17411792
}
@@ -1745,36 +1796,25 @@
17451796
"deprecationReason": null,
17461797
"description": null,
17471798
"isDeprecated": false,
1748-
"name": "deprecationReason",
1799+
"name": "description",
17491800
"type": {
17501801
"kind": "SCALAR",
17511802
"name": "String",
17521803
"ofType": null
17531804
}
1754-
}
1755-
],
1756-
"inputFields": null,
1757-
"interfaces": [],
1758-
"kind": "OBJECT",
1759-
"name": "__EnumValue",
1760-
"possibleTypes": null
1761-
},
1762-
{
1763-
"description": null,
1764-
"enumValues": null,
1765-
"fields": [
1805+
},
17661806
{
17671807
"args": [],
17681808
"deprecationReason": null,
17691809
"description": null,
17701810
"isDeprecated": false,
1771-
"name": "path",
1811+
"name": "isDeprecated",
17721812
"type": {
17731813
"kind": "NON_NULL",
17741814
"name": null,
17751815
"ofType": {
1776-
"kind": "OBJECT",
1777-
"name": "Path",
1816+
"kind": "SCALAR",
1817+
"name": "Boolean",
17781818
"ofType": null
17791819
}
17801820
}
@@ -1784,30 +1824,18 @@
17841824
"deprecationReason": null,
17851825
"description": null,
17861826
"isDeprecated": false,
1787-
"name": "matches",
1827+
"name": "deprecationReason",
17881828
"type": {
1789-
"kind": "NON_NULL",
1790-
"name": null,
1791-
"ofType": {
1792-
"kind": "LIST",
1793-
"name": null,
1794-
"ofType": {
1795-
"kind": "NON_NULL",
1796-
"name": null,
1797-
"ofType": {
1798-
"kind": "OBJECT",
1799-
"name": "SearchMatch",
1800-
"ofType": null
1801-
}
1802-
}
1803-
}
1829+
"kind": "SCALAR",
1830+
"name": "String",
1831+
"ofType": null
18041832
}
18051833
}
18061834
],
18071835
"inputFields": null,
18081836
"interfaces": [],
18091837
"kind": "OBJECT",
1810-
"name": "SearchResult",
1838+
"name": "__EnumValue",
18111839
"possibleTypes": null
18121840
},
18131841
{

0 commit comments

Comments
 (0)