Skip to content

Commit

Permalink
Expose GraphQLRequest fields (#750)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Jul 21, 2021
1 parent d211f4a commit 8a90f86
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
12 changes: 0 additions & 12 deletions integration_tests/juniper_tests/src/api.rs

This file was deleted.

2 changes: 0 additions & 2 deletions integration_tests/juniper_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#[cfg(test)]
mod api;
#[cfg(test)]
mod arc_fields;
#[cfg(test)]
mod codegen;
Expand Down
1 change: 1 addition & 0 deletions juniper/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# master

- Allow spreading interface fragments on unions and other interfaces ([#965](https://github.com/graphql-rust/juniper/pull/965), [#798](https://github.com/graphql-rust/juniper/issues/798))
- Expose `GraphQLRequest` fields ([#750](https://github.com/graphql-rust/juniper/issues/750))

# [[0.15.7] 2021-07-08](https://github.com/graphql-rust/juniper/releases/tag/juniper-v0.15.7)

Expand Down
28 changes: 18 additions & 10 deletions juniper/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,31 @@ pub struct GraphQLRequest<S = DefaultScalarValue>
where
S: ScalarValue,
{
query: String,
/// GraphQL query representing this request.
pub query: String,

/// Optional name of the operation associated with this request.
#[serde(rename = "operationName")]
operation_name: Option<String>,
pub operation_name: Option<String>,

/// Optional variables to execute the GraphQL operation with.
#[serde(bound(deserialize = "InputValue<S>: Deserialize<'de> + Serialize"))]
variables: Option<InputValue<S>>,
pub variables: Option<InputValue<S>>,
}

impl<S> GraphQLRequest<S>
where
S: ScalarValue,
{
// TODO: Remove in 0.17 `juniper` version.
/// Returns the `operation_name` associated with this request.
#[deprecated(since = "0.16", note = "Use the direct field access instead.")]
pub fn operation_name(&self) -> Option<&str> {
self.operation_name.as_deref()
}

fn variables(&self) -> Variables<S> {
/// Returns operation [`Variables`] defined withing this request.
pub fn variables(&self) -> Variables<S> {
self.variables
.as_ref()
.and_then(|iv| {
Expand All @@ -64,7 +72,7 @@ where
operation_name: Option<String>,
variables: Option<InputValue<S>>,
) -> Self {
GraphQLRequest {
Self {
query,
operation_name,
variables,
Expand All @@ -88,7 +96,7 @@ where
{
GraphQLResponse(crate::execute_sync(
&self.query,
self.operation_name(),
self.operation_name.as_deref(),
root_node,
&self.variables(),
context,
Expand All @@ -114,7 +122,7 @@ where
SubscriptionT::TypeInfo: Sync,
S: ScalarValue + Send + Sync,
{
let op = self.operation_name();
let op = self.operation_name.as_deref();
let vars = &self.variables();
let res = crate::execute(&self.query, op, root_node, vars, context).await;
GraphQLResponse(res)
Expand Down Expand Up @@ -143,7 +151,7 @@ where
SubscriptionT::TypeInfo: Sync,
S: ScalarValue + Send + Sync,
{
let op = req.operation_name();
let op = req.operation_name.as_deref();
let vars = req.variables();

crate::resolve_into_stream(&req.query, op, root_node, &vars, context).await
Expand Down Expand Up @@ -316,8 +324,8 @@ where
/// The operation names of the request.
pub fn operation_names(&self) -> Vec<Option<&str>> {
match self {
Self::Single(req) => vec![req.operation_name()],
Self::Batch(reqs) => reqs.iter().map(|req| req.operation_name()).collect(),
Self::Single(req) => vec![req.operation_name.as_deref()],
Self::Batch(reqs) => reqs.iter().map(|r| r.operation_name.as_deref()).collect(),
}
}
}
Expand Down

0 comments on commit 8a90f86

Please sign in to comment.