@@ -17,7 +17,7 @@ pub async fn graphql_sync<CtxT, QueryT, MutationT, SubscriptionT, S>(
17
17
root_node : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
18
18
context : Arc < CtxT > ,
19
19
req : Request < Body > ,
20
- ) -> Response < Body >
20
+ ) -> Response < String >
21
21
where
22
22
QueryT : GraphQLType < S , Context = CtxT > ,
23
23
QueryT :: TypeInfo : Sync ,
@@ -38,7 +38,7 @@ pub async fn graphql<CtxT, QueryT, MutationT, SubscriptionT, S>(
38
38
root_node : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
39
39
context : Arc < CtxT > ,
40
40
req : Request < Body > ,
41
- ) -> Response < Body >
41
+ ) -> Response < String >
42
42
where
43
43
QueryT : GraphQLTypeAsync < S , Context = CtxT > ,
44
44
QueryT :: TypeInfo : Sync ,
57
57
58
58
async fn parse_req < S : ScalarValue > (
59
59
req : Request < Body > ,
60
- ) -> Result < GraphQLBatchRequest < S > , Response < Body > > {
60
+ ) -> Result < GraphQLBatchRequest < S > , Response < String > > {
61
61
match * req. method ( ) {
62
62
Method :: GET => parse_get_req ( req) ,
63
63
Method :: POST => {
@@ -121,40 +121,35 @@ async fn parse_post_graphql_req<S: ScalarValue>(
121
121
pub async fn graphiql (
122
122
graphql_endpoint : & str ,
123
123
subscriptions_endpoint : Option < & str > ,
124
- ) -> Response < Body > {
124
+ ) -> Response < String > {
125
125
let mut resp = new_html_response ( StatusCode :: OK ) ;
126
126
// XXX: is the call to graphiql_source blocking?
127
- * resp. body_mut ( ) = Body :: from ( juniper:: http:: graphiql:: graphiql_source (
128
- graphql_endpoint,
129
- subscriptions_endpoint,
130
- ) ) ;
127
+ * resp. body_mut ( ) =
128
+ juniper:: http:: graphiql:: graphiql_source ( graphql_endpoint, subscriptions_endpoint) ;
131
129
resp
132
130
}
133
131
134
132
pub async fn playground (
135
133
graphql_endpoint : & str ,
136
134
subscriptions_endpoint : Option < & str > ,
137
- ) -> Response < Body > {
135
+ ) -> Response < String > {
138
136
let mut resp = new_html_response ( StatusCode :: OK ) ;
139
- * resp. body_mut ( ) = Body :: from ( juniper:: http:: playground:: playground_source (
140
- graphql_endpoint,
141
- subscriptions_endpoint,
142
- ) ) ;
137
+ * resp. body_mut ( ) =
138
+ juniper:: http:: playground:: playground_source ( graphql_endpoint, subscriptions_endpoint) ;
143
139
resp
144
140
}
145
141
146
- fn render_error ( err : GraphQLRequestError ) -> Response < Body > {
147
- let message = err. to_string ( ) ;
142
+ fn render_error ( err : GraphQLRequestError ) -> Response < String > {
148
143
let mut resp = new_response ( StatusCode :: BAD_REQUEST ) ;
149
- * resp. body_mut ( ) = Body :: from ( message ) ;
144
+ * resp. body_mut ( ) = err . to_string ( ) ;
150
145
resp
151
146
}
152
147
153
148
async fn execute_request_sync < CtxT , QueryT , MutationT , SubscriptionT , S > (
154
149
root_node : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
155
150
context : Arc < CtxT > ,
156
151
request : GraphQLBatchRequest < S > ,
157
- ) -> Response < Body >
152
+ ) -> Response < String >
158
153
where
159
154
QueryT : GraphQLType < S , Context = CtxT > ,
160
155
QueryT :: TypeInfo : Sync ,
@@ -166,7 +161,7 @@ where
166
161
S : ScalarValue + Send + Sync ,
167
162
{
168
163
let res = request. execute_sync ( & * root_node, & context) ;
169
- let body = Body :: from ( serde_json:: to_string_pretty ( & res) . unwrap ( ) ) ;
164
+ let body = serde_json:: to_string_pretty ( & res) . unwrap ( ) ;
170
165
let code = if res. is_ok ( ) {
171
166
StatusCode :: OK
172
167
} else {
@@ -185,7 +180,7 @@ async fn execute_request<CtxT, QueryT, MutationT, SubscriptionT, S>(
185
180
root_node : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
186
181
context : Arc < CtxT > ,
187
182
request : GraphQLBatchRequest < S > ,
188
- ) -> Response < Body >
183
+ ) -> Response < String >
189
184
where
190
185
QueryT : GraphQLTypeAsync < S , Context = CtxT > ,
191
186
QueryT :: TypeInfo : Sync ,
@@ -197,7 +192,7 @@ where
197
192
S : ScalarValue + Send + Sync ,
198
193
{
199
194
let res = request. execute ( & * root_node, & context) . await ;
200
- let body = Body :: from ( serde_json:: to_string_pretty ( & res) . unwrap ( ) ) ;
195
+ let body = serde_json:: to_string_pretty ( & res) . unwrap ( ) ;
201
196
let code = if res. is_ok ( ) {
202
197
StatusCode :: OK
203
198
} else {
@@ -260,13 +255,13 @@ fn invalid_err(parameter_name: &str) -> GraphQLRequestError {
260
255
) )
261
256
}
262
257
263
- fn new_response ( code : StatusCode ) -> Response < Body > {
264
- let mut r = Response :: new ( Body :: empty ( ) ) ;
258
+ fn new_response ( code : StatusCode ) -> Response < String > {
259
+ let mut r = Response :: new ( String :: new ( ) ) ;
265
260
* r. status_mut ( ) = code;
266
261
r
267
262
}
268
263
269
- fn new_html_response ( code : StatusCode ) -> Response < Body > {
264
+ fn new_html_response ( code : StatusCode ) -> Response < String > {
270
265
let mut resp = new_response ( code) ;
271
266
resp. headers_mut ( ) . insert (
272
267
header:: CONTENT_TYPE ,
@@ -313,7 +308,7 @@ mod tests {
313
308
use hyper:: {
314
309
server:: Server ,
315
310
service:: { make_service_fn, service_fn} ,
316
- Body , Method , Response , StatusCode ,
311
+ Method , Response , StatusCode ,
317
312
} ;
318
313
use juniper:: {
319
314
http:: tests as http_tests,
@@ -409,7 +404,7 @@ mod tests {
409
404
super :: graphql ( root_node, ctx, req) . await
410
405
}
411
406
} else {
412
- let mut resp = Response :: new ( Body :: empty ( ) ) ;
407
+ let mut resp = Response :: new ( String :: new ( ) ) ;
413
408
* resp. status_mut ( ) = StatusCode :: NOT_FOUND ;
414
409
resp
415
410
} )
0 commit comments