@@ -16,8 +16,10 @@ use juniper::{
1616use serde_json:: error:: Error as SerdeError ;
1717use url:: form_urlencoded;
1818
19+ /// Executes synchronously the provided GraphQL [`Request`] against the provided `schema` in the
20+ /// provided `context`, returning the encoded [`Response`].
1921pub async fn graphql_sync < CtxT , QueryT , MutationT , SubscriptionT , S , B > (
20- root_node : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
22+ schema : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
2123 context : Arc < CtxT > ,
2224 req : Request < B > ,
2325) -> Response < String >
@@ -33,13 +35,15 @@ where
3335 B : Body < Error : fmt:: Display > ,
3436{
3537 match parse_req ( req) . await {
36- Ok ( req) => execute_request_sync ( root_node , context, req) . await ,
38+ Ok ( req) => execute_request_sync ( schema , context, req) . await ,
3739 Err ( resp) => resp,
3840 }
3941}
4042
43+ /// Executes the provided GraphQL [`Request`] against the provided `schema` in the provided
44+ /// `context`, returning the encoded [`Response`].
4145pub async fn graphql < CtxT , QueryT , MutationT , SubscriptionT , S , B > (
42- root_node : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
46+ schema : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
4347 context : Arc < CtxT > ,
4448 req : Request < B > ,
4549) -> Response < String >
5559 B : Body < Error : fmt:: Display > ,
5660{
5761 match parse_req ( req) . await {
58- Ok ( req) => execute_request ( root_node , context, req) . await ,
62+ Ok ( req) => execute_request ( schema , context, req) . await ,
5963 Err ( resp) => resp,
6064 }
6165}
@@ -137,6 +141,11 @@ where
137141 ) ) )
138142}
139143
144+ /// Generates a [`Response`] page containing [GraphiQL].
145+ ///
146+ /// This does not handle routing, so you can mount it on any endpoint.
147+ ///
148+ /// [GraphiQL]: https://github.com/graphql/graphiql
140149pub async fn graphiql (
141150 graphql_endpoint : & str ,
142151 subscriptions_endpoint : Option < & str > ,
@@ -148,6 +157,11 @@ pub async fn graphiql(
148157 resp
149158}
150159
160+ /// Generates a [`Response`] page containing [GraphQL Playground].
161+ ///
162+ /// This does not handle routing, so you can mount it on any endpoint.
163+ ///
164+ /// [GraphQL Playground]: https://github.com/prisma/graphql-playground
151165pub async fn playground (
152166 graphql_endpoint : & str ,
153167 subscriptions_endpoint : Option < & str > ,
@@ -168,7 +182,7 @@ where
168182}
169183
170184async fn execute_request_sync < CtxT , QueryT , MutationT , SubscriptionT , S > (
171- root_node : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
185+ schema : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
172186 context : Arc < CtxT > ,
173187 request : GraphQLBatchRequest < S > ,
174188) -> Response < String >
@@ -182,7 +196,7 @@ where
182196 CtxT : Sync ,
183197 S : ScalarValue + Send + Sync ,
184198{
185- let res = request. execute_sync ( & * root_node , & context) ;
199+ let res = request. execute_sync ( & * schema , & context) ;
186200 let body = serde_json:: to_string_pretty ( & res) . unwrap ( ) ;
187201 let code = if res. is_ok ( ) {
188202 StatusCode :: OK
@@ -199,7 +213,7 @@ where
199213}
200214
201215async fn execute_request < CtxT , QueryT , MutationT , SubscriptionT , S > (
202- root_node : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
216+ schema : Arc < RootNode < ' static , QueryT , MutationT , SubscriptionT , S > > ,
203217 context : Arc < CtxT > ,
204218 request : GraphQLBatchRequest < S > ,
205219) -> Response < String >
@@ -213,7 +227,7 @@ where
213227 CtxT : Sync ,
214228 S : ScalarValue + Send + Sync ,
215229{
216- let res = request. execute ( & * root_node , & context) . await ;
230+ let res = request. execute ( & * schema , & context) . await ;
217231 let body = serde_json:: to_string_pretty ( & res) . unwrap ( ) ;
218232 let code = if res. is_ok ( ) {
219233 StatusCode :: OK
0 commit comments