Skip to content

Expose the operation name from juniper_rocket::GraphQLRequest #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions juniper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
The DirectiveLocation::InlineFragment had an invalid literal value,
which broke third party tools like apollo cli.
- The return type of `value::object::Object::iter/iter_mut` has changed to `impl Iter` [#312](https://github.com/graphql-rust/juniper/pull/312)
- Add `GraphQLRequest::operation_name` [#353](https://github.com/graphql-rust/juniper/pull/353)

# [0.11.1] 2018-12-19

Expand Down
2 changes: 1 addition & 1 deletion juniper/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
S: ScalarValue,
{
/// Returns the `operation_name` associated with this request.
fn operation_name(&self) -> Option<&str> {
pub fn operation_name(&self) -> Option<&str> {
self.operation_name.as_ref().map(|oper_name| &**oper_name)
}

Expand Down
2 changes: 1 addition & 1 deletion juniper_rocket/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# master

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

# [0.2.0] 2018-12-17

Expand Down
18 changes: 18 additions & 0 deletions juniper_rocket/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ where
),
}
}

pub fn operation_name(&self) -> Option<&str> {
match self {
GraphQLBatchRequest::Single(req) => req.operation_name(),
GraphQLBatchRequest::Batch(reqs) => {
if reqs.len() == 1 {
reqs.get(0).and_then(|req| req.operation_name())
} else {
None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't we want a list of operations for batch requests for the same usecase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that is true. Fixed in 168a763

}
}
}
}
}

impl<'a, S> GraphQLBatchResponse<'a, S>
Expand Down Expand Up @@ -173,6 +186,11 @@ where

GraphQLResponse(status, json)
}

/// Returns the `operation_name` associated with this request.
pub fn operation_name(&self) -> Option<&str> {
self.0.operation_name()
}
}

impl GraphQLResponse {
Expand Down