Skip to content

Commit 8a90f86

Browse files
committed
Expose GraphQLRequest fields (#750)
1 parent d211f4a commit 8a90f86

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

integration_tests/juniper_tests/src/api.rs

-12
This file was deleted.

integration_tests/juniper_tests/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#[cfg(test)]
2-
mod api;
3-
#[cfg(test)]
42
mod arc_fields;
53
#[cfg(test)]
64
mod codegen;

juniper/CHANGELOG.md

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

33
- 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))
4+
- Expose `GraphQLRequest` fields ([#750](https://github.com/graphql-rust/juniper/issues/750))
45

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

juniper/src/http/mod.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,31 @@ pub struct GraphQLRequest<S = DefaultScalarValue>
2929
where
3030
S: ScalarValue,
3131
{
32-
query: String,
32+
/// GraphQL query representing this request.
33+
pub query: String,
34+
35+
/// Optional name of the operation associated with this request.
3336
#[serde(rename = "operationName")]
34-
operation_name: Option<String>,
37+
pub operation_name: Option<String>,
38+
39+
/// Optional variables to execute the GraphQL operation with.
3540
#[serde(bound(deserialize = "InputValue<S>: Deserialize<'de> + Serialize"))]
36-
variables: Option<InputValue<S>>,
41+
pub variables: Option<InputValue<S>>,
3742
}
3843

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

48-
fn variables(&self) -> Variables<S> {
55+
/// Returns operation [`Variables`] defined withing this request.
56+
pub fn variables(&self) -> Variables<S> {
4957
self.variables
5058
.as_ref()
5159
.and_then(|iv| {
@@ -64,7 +72,7 @@ where
6472
operation_name: Option<String>,
6573
variables: Option<InputValue<S>>,
6674
) -> Self {
67-
GraphQLRequest {
75+
Self {
6876
query,
6977
operation_name,
7078
variables,
@@ -88,7 +96,7 @@ where
8896
{
8997
GraphQLResponse(crate::execute_sync(
9098
&self.query,
91-
self.operation_name(),
99+
self.operation_name.as_deref(),
92100
root_node,
93101
&self.variables(),
94102
context,
@@ -114,7 +122,7 @@ where
114122
SubscriptionT::TypeInfo: Sync,
115123
S: ScalarValue + Send + Sync,
116124
{
117-
let op = self.operation_name();
125+
let op = self.operation_name.as_deref();
118126
let vars = &self.variables();
119127
let res = crate::execute(&self.query, op, root_node, vars, context).await;
120128
GraphQLResponse(res)
@@ -143,7 +151,7 @@ where
143151
SubscriptionT::TypeInfo: Sync,
144152
S: ScalarValue + Send + Sync,
145153
{
146-
let op = req.operation_name();
154+
let op = req.operation_name.as_deref();
147155
let vars = req.variables();
148156

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

0 commit comments

Comments
 (0)