Skip to content

Commit 168a763

Browse files
committed
Return all operation names for batch requests
1 parent c6eb3b4 commit 168a763

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

Diff for: juniper_rocket/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# master
22

3-
- Expose the operation name from `GraphQLRequest`.
3+
- Expose the operation names from `GraphQLRequest`.
44
- Compatibility with the latest `juniper`.
55

66
# [0.2.0] 2018-12-17

Diff for: juniper_rocket/src/lib.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,11 @@ where
108108
}
109109
}
110110

111-
pub fn operation_name(&self) -> Option<&str> {
111+
pub fn operation_names(&self) -> Vec<Option<&str>> {
112112
match self {
113-
GraphQLBatchRequest::Single(req) => req.operation_name(),
113+
GraphQLBatchRequest::Single(req) => vec![req.operation_name()],
114114
GraphQLBatchRequest::Batch(reqs) => {
115-
if reqs.len() == 1 {
116-
reqs.get(0).and_then(|req| req.operation_name())
117-
} else {
118-
None
119-
}
115+
reqs.iter().map(|req| req.operation_name()).collect()
120116
}
121117
}
122118
}
@@ -187,9 +183,11 @@ where
187183
GraphQLResponse(status, json)
188184
}
189185

190-
/// Returns the `operation_name` associated with this request.
191-
pub fn operation_name(&self) -> Option<&str> {
192-
self.0.operation_name()
186+
/// Returns the operation names associated with this request.
187+
///
188+
/// For batch requests there will be multiple names.
189+
pub fn operation_names(&self) -> Vec<Option<&str>> {
190+
self.0.operation_names()
193191
}
194192
}
195193

0 commit comments

Comments
 (0)