@@ -29,23 +29,31 @@ pub struct GraphQLRequest<S = DefaultScalarValue>
29
29
where
30
30
S : ScalarValue ,
31
31
{
32
- query : String ,
32
+ /// GraphQL query representing this request.
33
+ pub query : String ,
34
+
35
+ /// Optional name of the operation associated with this request.
33
36
#[ serde( rename = "operationName" ) ]
34
- operation_name : Option < String > ,
37
+ pub operation_name : Option < String > ,
38
+
39
+ /// Optional variables to execute the GraphQL operation with.
35
40
#[ serde( bound( deserialize = "InputValue<S>: Deserialize<'de> + Serialize" ) ) ]
36
- variables : Option < InputValue < S > > ,
41
+ pub variables : Option < InputValue < S > > ,
37
42
}
38
43
39
44
impl < S > GraphQLRequest < S >
40
45
where
41
46
S : ScalarValue ,
42
47
{
48
+ // TODO: Remove in 0.17 `juniper` version.
43
49
/// Returns the `operation_name` associated with this request.
50
+ #[ deprecated( since = "0.16" , note = "Use the direct field access instead." ) ]
44
51
pub fn operation_name ( & self ) -> Option < & str > {
45
52
self . operation_name . as_deref ( )
46
53
}
47
54
48
- fn variables ( & self ) -> Variables < S > {
55
+ /// Returns operation [`Variables`] defined withing this request.
56
+ pub fn variables ( & self ) -> Variables < S > {
49
57
self . variables
50
58
. as_ref ( )
51
59
. and_then ( |iv| {
64
72
operation_name : Option < String > ,
65
73
variables : Option < InputValue < S > > ,
66
74
) -> Self {
67
- GraphQLRequest {
75
+ Self {
68
76
query,
69
77
operation_name,
70
78
variables,
88
96
{
89
97
GraphQLResponse ( crate :: execute_sync (
90
98
& self . query ,
91
- self . operation_name ( ) ,
99
+ self . operation_name . as_deref ( ) ,
92
100
root_node,
93
101
& self . variables ( ) ,
94
102
context,
@@ -114,7 +122,7 @@ where
114
122
SubscriptionT :: TypeInfo : Sync ,
115
123
S : ScalarValue + Send + Sync ,
116
124
{
117
- let op = self . operation_name ( ) ;
125
+ let op = self . operation_name . as_deref ( ) ;
118
126
let vars = & self . variables ( ) ;
119
127
let res = crate :: execute ( & self . query , op, root_node, vars, context) . await ;
120
128
GraphQLResponse ( res)
@@ -143,7 +151,7 @@ where
143
151
SubscriptionT :: TypeInfo : Sync ,
144
152
S : ScalarValue + Send + Sync ,
145
153
{
146
- let op = req. operation_name ( ) ;
154
+ let op = req. operation_name . as_deref ( ) ;
147
155
let vars = req. variables ( ) ;
148
156
149
157
crate :: resolve_into_stream ( & req. query , op, root_node, & vars, context) . await
@@ -316,8 +324,8 @@ where
316
324
/// The operation names of the request.
317
325
pub fn operation_names ( & self ) -> Vec < Option < & str > > {
318
326
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 ( ) ,
321
329
}
322
330
}
323
331
}
0 commit comments