@@ -54,81 +54,9 @@ use rocket::{
5454use juniper:: { http, InputValue } ;
5555
5656use juniper:: {
57- serde :: Deserialize , DefaultScalarValue , FieldError , GraphQLType , RootNode , ScalarValue ,
57+ http :: GraphQLBatchRequest , DefaultScalarValue , FieldError , GraphQLType , RootNode , ScalarValue ,
5858} ;
5959
60- #[ derive( Debug , serde_derive:: Deserialize , PartialEq ) ]
61- #[ serde( untagged) ]
62- #[ serde( bound = "InputValue<S>: Deserialize<'de>" ) ]
63- enum GraphQLBatchRequest < S = DefaultScalarValue >
64- where
65- S : ScalarValue ,
66- {
67- Single ( http:: GraphQLRequest < S > ) ,
68- Batch ( Vec < http:: GraphQLRequest < S > > ) ,
69- }
70-
71- #[ derive( serde_derive:: Serialize ) ]
72- #[ serde( untagged) ]
73- enum GraphQLBatchResponse < ' a , S = DefaultScalarValue >
74- where
75- S : ScalarValue ,
76- {
77- Single ( http:: GraphQLResponse < ' a , S > ) ,
78- Batch ( Vec < http:: GraphQLResponse < ' a , S > > ) ,
79- }
80-
81- impl < S > GraphQLBatchRequest < S >
82- where
83- S : ScalarValue ,
84- {
85- pub fn execute_sync < ' a , CtxT , QueryT , MutationT , SubscriptionT > (
86- & ' a self ,
87- root_node : & ' a RootNode < QueryT , MutationT , SubscriptionT , S > ,
88- context : & CtxT ,
89- ) -> GraphQLBatchResponse < ' a , S >
90- where
91- QueryT : GraphQLType < S , Context = CtxT > ,
92- MutationT : GraphQLType < S , Context = CtxT > ,
93- SubscriptionT : GraphQLType < S , Context = CtxT > ,
94- {
95- match * self {
96- GraphQLBatchRequest :: Single ( ref request) => {
97- GraphQLBatchResponse :: Single ( request. execute_sync ( root_node, context) )
98- }
99- GraphQLBatchRequest :: Batch ( ref requests) => GraphQLBatchResponse :: Batch (
100- requests
101- . iter ( )
102- . map ( |request| request. execute_sync ( root_node, context) )
103- . collect ( ) ,
104- ) ,
105- }
106- }
107-
108- pub fn operation_names ( & self ) -> Vec < Option < & str > > {
109- match self {
110- GraphQLBatchRequest :: Single ( req) => vec ! [ req. operation_name( ) ] ,
111- GraphQLBatchRequest :: Batch ( reqs) => {
112- reqs. iter ( ) . map ( |req| req. operation_name ( ) ) . collect ( )
113- }
114- }
115- }
116- }
117-
118- impl < ' a , S > GraphQLBatchResponse < ' a , S >
119- where
120- S : ScalarValue ,
121- {
122- fn is_ok ( & self ) -> bool {
123- match * self {
124- GraphQLBatchResponse :: Single ( ref response) => response. is_ok ( ) ,
125- GraphQLBatchResponse :: Batch ( ref responses) => {
126- responses. iter ( ) . all ( |response| response. is_ok ( ) )
127- }
128- }
129- }
130- }
131-
13260/// Simple wrapper around an incoming GraphQL request
13361///
13462/// See the `http` module for more information. This type can be constructed
0 commit comments