Skip to content

Commit db5eae6

Browse files
committed
Expose the operation name from GraphQLRequest
Measuring the runtime of queries will only tell if there are slow queries. To find out which queries are slow you need the operation name. Getting the operation name was previously not possible from a Rocket request handler. This fixes that.
1 parent dbfcc76 commit db5eae6

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

juniper/src/http/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ where
3636
S: ScalarValue,
3737
{
3838
/// Returns the `operation_name` associated with this request.
39-
fn operation_name(&self) -> Option<&str> {
39+
pub fn operation_name(&self) -> Option<&str> {
4040
self.operation_name.as_ref().map(|oper_name| &**oper_name)
4141
}
4242

juniper_rocket/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# master
22

3-
- No changes yet
3+
- Expose the operation name from `GraphQLRequest`.
44

55
# [0.2.0] 2018-12-17
66

juniper_rocket/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ where
107107
),
108108
}
109109
}
110+
111+
pub fn operation_name(&self) -> Option<&str> {
112+
match self {
113+
GraphQLBatchRequest::Single(req) => {
114+
req.operation_name()
115+
},
116+
GraphQLBatchRequest::Batch(reqs) => {
117+
if reqs.len() == 1 {
118+
reqs.get(0).and_then(|req| req.operation_name())
119+
} else {
120+
None
121+
}
122+
},
123+
}
124+
}
110125
}
111126

112127
impl<'a, S> GraphQLBatchResponse<'a, S>
@@ -173,6 +188,11 @@ where
173188

174189
GraphQLResponse(status, json)
175190
}
191+
192+
/// Returns the `operation_name` associated with this request.
193+
pub fn operation_name(&self) -> Option<&str> {
194+
self.0.operation_name()
195+
}
176196
}
177197

178198
impl GraphQLResponse {

0 commit comments

Comments
 (0)